gpt4 book ai didi

android - DexException 在 Android 中定义了多个 dex 文件

转载 作者:太空宇宙 更新时间:2023-11-03 12:27:01 26 4
gpt4 key购买 nike

在我的 android 项目中,我使用两个 JAXB 库 jaxp-ri(用于 XMLGregorianCalendarImpl 类)和 jaxb-api(用于对象到 xml 的转换)。我在 build.gradle 文件中添加了这两个库。

但是当我构建我的项目时出现以下提到的错误

Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Ljavax/xml/stream/events/Namespace;
Error:com.android.dex.DexException: Multiple dex files define Ljavax/xml/stream/events/Namespace;
Error: at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:661)
Error: at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:616)
Error: at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:598)
Error: at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
Error: at com.android.dx.merge.DexMerger.merge(DexMerger.java:198)
Error: at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:61)
Error: at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:36)
Error: at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
Error: at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
Error: at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
Error: at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
Error: at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Error:Execution failed for task ':app:transformDexArchiveWithDexMergerForDebug'.
> com.android.build.api.transform.TransformException: com.android.dex.DexException: Multiple dex files define Ljavax/xml/stream/events/Namespace;

Build.gradle文件

dependencies {

implementation fileTree(include: ['*.jar'], dir: 'libs')

implementation 'com.android.support:appcompat-v7:26.0.0-beta1'

implementation 'com.android.support.constraint:constraint-layout:1.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 group: 'com.sun.org.apache', name: 'jaxp-ri', version: '1.4'

compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.1'

}

有人可以帮忙吗?我该如何解决这个问题?

编辑

完成build.gradle文件

android {
compileSdkVersion 26
defaultConfig {
applicationId "in.cdac.xmlparsing"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.0.0-beta1'
implementation 'com.android.support.constraint:constraint-layout:1.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 group: 'com.sun.org.apache', name: 'jaxp-ri', version: '1.4'
compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.1'
}

最佳答案

只需在模块级 build.gradle 中声明 multiDexEnabled true,仅当您的 minSdkVersion 设置为 21 或更高时才有效。

如果你的minSdkVersion低于21,除了上面这一步,你还需要有multidex支持库作为依赖

dependencies {
compile 'com.android.support:multidex:1.0.1'
}

您可以在此处阅读详细信息 - https://developer.android.com/studio/build/multidex.html

关于android - DexException 在 Android 中定义了多个 dex 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48681342/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com