在Android中使用Apache POI时的兼容性问题

我在使用Apache POI时遇到以下问题

Error:Execution failed for task ':app:transformClassesWithDexForDebug'. > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_31\bin\java.exe'' finished with non-zero exit value 2 

我在我的gradle依赖项中添加了下面的仓库。

 dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.1.1' compile 'com.android.support:design:23.1.1' compile 'org.apache.poi:poi:3.14-beta1' compile 'org.apache.poi:poi-ooxml:3.14-beta1' } 

我也testing了从poi版本3.9 。 但每次我都遇到同样的问题。

如果我评论

 compile 'org.apache.poi:poi-ooxml:3.14-beta1' 

应用程序无任何例外地运行 任何帮助解决这个问题将不胜感激。

添加库时,您的应用程序有超过65k个方法。 您需要启用multi-dex,然后修改您的gradle构build文件,如下所示:

 android { compileSdkVersion 21 buildToolsVersion "21.1.0" defaultConfig { ... minSdkVersion 14 targetSdkVersion 21 ... // Enabling multidex support. multiDexEnabled true } ... } dependencies { compile 'com.android.support:multidex:1.0.0' } 

在你的清单中添加MultiDexApplication类:

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.multidex.myapplication"> <application ... android:name="android.support.multidex.MultiDexApplication"> ... </application> </manifest> 

请参阅http://developer.android.com/tools/building/multidex.html