首页 > 解决方案 > 添加 Apache POI 作为外部库后应用程序立即崩溃

问题描述

我正在编写一个使用 Apache poi 作为外部库的应用程序,以便我能够使用应用程序上生成的数据生成 excel 文件。但是,在将 apache jar 添加到我的 lib 文件夹并在我的应用程序 build.gradle 上实现它们之后,我收到了各种 DexArchiveBuilderExceptions。

我试图使我的缓存无效并重新启动,并将我的项目设置为源代码兼容性 Java_1_8;但是,我仍然收到相同的错误。

android {
    compileSdkVersion 28
    buildToolsVersion "29.0.0"

    defaultConfig {
        applicationId "com.example.statstopwatch"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}


dependencies {
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.jjoe64:graphview:4.2.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation files('libs/poi-4.1.0.jar')
    implementation files('libs/poi-examples-4.1.0.jar')
    implementation files('libs/poi-excelant-4.1.0.jar')
    implementation files('libs/poi-ooxml-4.1.0.jar')
    implementation files('libs/poi-ooxml-schemas-4.1.0.jar')
    implementation files('libs/poi-scratchpad-4.1.0.jar')
}


我通过将这些外部库粘贴到 libs 文件夹并将它们添加为库来添加这些外部库,这可能是错误的原因吗?

标签: javaandroidapache-poi

解决方案


您需要提高minSdkVersion到 26,因为这些库使用 Java 8 中的东西,这些东西仅在 Android 8.0 及更高版本上可用。

或者,找到这些库的较旧版本或专为 Android 设计的版本,这可能允许您保留当前的minSdkVersion​​.


推荐阅读