java - 添加 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')
}
解决方案
您需要提高minSdkVersion
到 26,因为这些库使用 Java 8 中的东西,这些东西仅在 Android 8.0 及更高版本上可用。
或者,找到这些库的较旧版本或专为 Android 设计的版本,这可能允许您保留当前的minSdkVersion
.
推荐阅读
- maven - 如何在提交/拉取请求后更新 maven 包
- haskell - 使用“否则”时如何获得“非详尽模式”异常
- mongodb - 使用 Java 驱动程序 3.8 的 ColdFusion 和 MongoDB 4
- python - 在 GMSH 物理线获取 FaceVariable
- jmeter - 当服务器总是返回 200 时,JMeter 中的真正错误是什么?
- mysql - 连接三个表的 SQL 查询
- node.js - 如何创建在所有支持的平台上运行相同的 Node.js 程序
- mysql - MySQL 中带有 DateTime 和动态列的数据透视表
- c# - C# - 通过面板中的 z-index 重新排序控件
- vue.js - Vue:方法不是内联模板组件标记中的函数