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

标签 java android excel 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'
}

我还从 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>

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

关于java - 在 Android 中使用 Apache POI 时的兼容性问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34495681/

相关文章:

java - RMI 中的 UnsupportedOperationException

java - Spring Boot Rest API 不会在 Tomcat 8.5.47 上部署,错误代码为 "org.apache.catalina.LifecycleException: Failed to start component"

MYSQL SELECT AVG() of rows that meet certain conditions in 中满足某些条件的行

python - 如何在 Python 中读取、编辑和另存为另一个 excel 文件?

java - 在 Eclipse 中从 sqlite 数据库加载 JAVA GUI 中的表时,如何添加表标题?

java - Android 上如何知道字符串是否在数组内?

android - 任务 'install' 在根项目 'TestApp' 中不明确。候选为: 'installDebug' , 'installDebugAndroidTest'

android - 从另一个 AsyncTask 的 onPostExecute 启动的 asyncTask 在 API 10 中无法正确执行

java - Android类加载器: loadClass fails if the class implements an interface

excel - 获取分隔符和 -1 之前的数字(上个月)