There's this http://github.com/theapache64/BugMailer我创建的库是为了通过电子邮件报告异常情况。它适用于 Android Java 项目,但不适用于 Android Kotlin。当我添加库的编译脚本时(compile 'com.theah64.bugmailer:bugmailer:1.1.9')
并尝试构建 APK,但出现以下错误。
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
这是我的应用程序的 build.gradle 文件
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.theapache64.calculator"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
multiDexEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
preDexLibraries = false
javaMaxHeapSize "4g"
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:27.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile 'com.theah64.bugmailer:bugmailer:1.2.0'
}
我用谷歌搜索了很多并尝试过multiDexEnabled
解决方案。但它不起作用。
您遇到的问题是由冲突的依赖项引起的,您的两个依赖项定义了相同的类。如果你尝试编译
./gradlew --stacktrace app:assembleDebug
你会看到这个错误
Caused by: com.android.dex.DexException: Multiple dex files define Lorg/intellij/lang/annotations/MagicConstant;
现在,您可以使用以下命令分析所有依赖关系树
./gradlew app:dependencies
并查看这些(此处简化):
+--- com.theah64.bugmailer:bugmailer:1.2.0
| +--- org.jetbrains:annotations-java5:15.0
and
+--- org.jetbrains.kotlin:kotlin-stdlib:1.2.30
| \--- org.jetbrains:annotations:13.0
因此,Kotlin std lib 和 bugmailer 都使用 org.jetbrains 注释,但来自 2 个不同的模块。这会导致问题,因为同一个类(在这种情况下为 MagicConstant)被定义了两次,我认为重复的条目会更多。
解决方案是排除 2 个传递依赖项之一,例如
compile('com.theah64.bugmailer:bugmailer:1.2.0') {
exclude group: 'org.jetbrains', module: 'annotations-java5'
}
您将能够编译该应用程序,但是请记住,该解决方案基于以下假设:bugmailer 可以很好地工作org.jetbrains:annotations:13.0
代替org.jetbrains:annotations-java5:15.0
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)