我在使用 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'
}
我还从 poi 版本 3.9
进行了测试。但每次我都会遇到同样的问题。
如果我发表评论
compile 'org.apache.poi:poi-ooxml:3.14-beta1'
应用程序运行没有任何异常。
最佳答案
添加库时,您的应用程序有超过 65k 个方法。然后,您需要启用 multi-dex,为此修改您的 gradle 构建文件,如下所示:
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'
}
并在 list 中添加 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>
关于java - 在 Android 中使用 Apache POI 时的兼容性问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34495681/