多个dex文件定义Landroid / support / v7 / util / ThreadUtil $ MainThreadCallback错误 [英] Multiple dex files define Landroid/support/v7/util/ThreadUtil$MainThreadCallback Error
问题描述
只有当我尝试释放或调试我的应用的apk时才会出现错误。我可以直接从Android Studio在我的设备上运行或调试它。从这个问题,我明白这可能是由于重复的依赖关系。所以我试着通过运行来检查是否有重复的依赖关系:
./gradlew -q:app:dependencies
我得到了以下依赖关系树:
_releaseApk - ##内部使用,请勿手动配置##
+ --- com.android.support:appcompat-v7:25.3.1
| + --- com.android.support:support-annotations:25.3.1
| + --- com.android.support:support-v4:25.3.1
| | + --- com.android.support:support-compat:25.3.1
| | | \ --- com.android.support:support-annotations:25.3.1
| | + --- com.android.support:support-media-compat:25.3.1
| | | + --- com.android.support:support-annotations:25.3.1
| | | \ --- com.android.support:support-compat:25.3.1(*)
| | + --- com.android.support:support-core-utils:25.3.1
| | | + --- com.android.support:support-annotations:25.3.1
| | | \ --- com.android.support:support-compat:25.3.1(*)
| | + --- com.android.support:support-core-ui:25.3.1
| | | + --- com.android.support:support-annotations:25.3.1
| | | \ --- com.android.support:support-compat:25.3.1(*)
| | \ --- com.android.support:support-fragment:25.3.1
| | + --- com.android.support:support-compat:25.3.1(*)
| | + --- com.android.support:support-media-compat:25.3.1(*)
| | + --- com.android.support:support-core-ui:25.3.1(*)
| | \ --- com.android.support:support-core-utils:25.3.1(*)
| + --- com.android.support:support-vector-drawable:25.3.1
| | + --- com.android.support:support-annotations:25.3.1
| | \ --- com.android.support:support-compat:25.3.1(*)
| \ --- com.android.support:animated-vector-drawable:25.3.1
| \ --- com.android.support:support-vector-drawable:25.3.1(*)
+ --- com.android.support:cardview-v7:25.3.1
| \ --- com.android.support:support-annotations:25.3.1
+ --- com.android.support:recyclerview-v7:25.3.1
| + --- com.android.support:support-annotations:25.3.1
| + --- com.android.support:support-compat:25.3.1(*)
| \ --- com.android.support:support-core-ui:25.3.1(*)
+ --- com.android.support:design:25.3.1
| + --- com.android.support:support-v4:25.3.1(*)
| + --- com.android.support:appcompat-v7:25.3.1(*)
| + --- com.android.support:recyclerview-v7:25.3.1(*)
| \ --- com.android.support:transition:25.3.1
| + --- com.android.support:support-annotations:25.3.1
| \ --- com.android.support:support-v4:25.3.1(*)
+ --- pl.droidsonroids.gif:android-gif-drawable:1.2.7
+ - - com.google.android.gms:play-services-ads:10.2.6
| + --- com.google.android.gms:play-services-ads-lite:10.2.6
| | \ --- com.google.android.gms:play-services-basement:10.2.6
| | \ --- com.android.support:support-v4:25.2.0 - > 25.3.1(*)
| + --- com.google.android.gms:play-services-base:10.2.6
| | + --- com.google.android.gms:play-services-basement:10.2.6(*)
| | \ --- com.google.android.gms:play-services-tasks:10.2.6
| | \ --- com.google.android.gms:play-services-basement:10.2.6(*)
| + --- com.google.android.gms:play-services-clearcut:10.2.6
| | + --- com.google.android.gms:play-services-base:10.2.6(*)
| | \ --- com.google.android.gms:play-services-basement:10.2.6(*)
| + --- com.google.android.gms:play-services-basement:10.2.6(*)
| \ --- com.google.android.gms:play-services-gass:10.2.6
| \ --- com.google.android.gms:play-services-basement:10.2.6(*)
+ --- com.google.android.gms:play-services-location:10.2.6
| + --- com.google.android.gms:play-services-base:10.2.6(*)
| + --- com.google.android.gms:play-services-basement:10.2.6(*)
| \ --- com.google.android.gms:play-services-tasks:10.2.6(*)
\ --- com.google.firebase:firebase-core:10.2.6
\ --- com.google.firebase:firebase-analytics:10.2.6
+ --- com.google.firebase:firebase-analytics-impl:10.2.6
| + --- com.google.android.gms:play-services-basement:10.2.6(*)
| + --- com.google.firebase:firebase-iid:10.2.6
| | + --- com.google.android.gms:play-services-basement:10.2.6(*)
| | \ --- com.google.firebase:firebase-common:10.2.6
| | + --- com.google.android.gms:play-services-basement:10.2.6(*)
| | \ --- com.google.android.gms:play-services-tasks:10.2.6(*)
| + --- com.google.firebase:firebase-common:10.2.6(*)
| \ --- com.google.android.gms:play-services-tasks:10.2.6(*)
+ --- com.google.android.gms:play-services-basement:10.2.6 (*)
\ --- com.google.firebase:firebase-common:10.2.6(*)
如何从这棵树中推断出我的项目中的重复依赖项?它们是以星号结尾的吗?
编辑:我的Gradle文件在下面给出
apply plugin:'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion25.0.3
defaultConfig {
applicationIdcom.mycompany.myapp
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName1.0
testInstrumentationRunnerandroid.support.test.runner。 AndroidJUnitRunner
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
}
}
依赖关系{
编译fileTree(dir:'libs',include:['* .jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',{
exclude group:'com.androi d.support',模块:'support-annotations'
})
编译'com.android.support:appcompat-v7:25.3.1'
compile'com.android.support: cardview-v7:25.3.1'
compile'com.android.support:recyclerview-v7:25.3.1'
compile'com.android.support:design:25.3.1'
编译'pl.droidsonroids.gif:android-gif-drawable:1.2.7'
compile'com.google.android.gms:play-services-ads:10.2.6'
compile'com。 google.android.gms:play-services-location:10.2.6'
compile'com.google.firebase:firebase-core:10.2.6'
testCompile'junit:junit:4.12'
}
应用插件:'com.google.gms.google-services'
编辑2:完整gradle错误:
错误:任务
'执行失败:应用程序:transformClassesWithDexForDebug'。
com.android.build.api.transform.TransformException:com.android .ide.common.process.ProcessException:
java.util.concurrent.ExecutionException:com.android.dex.DexException:
多个dex文件定义
Landroid / support / v7 / util / ThreadUtil编辑3:由于support / v7 / util / ThreadUtil.java属于RecyclerView模块,我试图用设计库排除下面的RecyclerView模块:
依赖项{
compile fileTree(dir :'libs',include:['* .jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',{
exclude group:' com.android.support',module:'support-annotations'
})
compile'com.android.support:appcompat-v7:25.3.1'
compile'com.android。支持:cardview-v7:25.3.1'
compile'com.android.support:recyclerview-v7:25.3.1'
compile('com.android.support:design:25.3.1') {
排除模块:'recyclerview-v7'
}
编译'pl.droidsonroids.gif:android-gif-drawable:1.2.7'
compile'com.google.android.gms:play -services-ads:10.2.6'
compile'com.google.android.gms:play-services-location:10.2.6'
compile'com.google.firebase:firebase-core:10.2 .6'
testCompile'junit:junit:4.12'
}
Still根据您的评论,显然问题是第三方SDK分发了一个JAR <$ code> recyclerview-v7 ,你在
libs /
中有冲突,它与recyclerview-v7冲突code>依赖关系。
使用纯JAR进行依赖关系存在缺点。你往往会忘记它们,特别是如果你 正在使用工件存储库中的依赖关系。例如,我甚至没有考虑过你可能在
libs /
中有我的评论。
另一个是Gradle不能为他们执行任何类型的依赖关系解析。 Gradle依靠工件元数据(POM文件)来确定需要哪些依赖关系。 Gradle认为,对于JAR文件你做的是正确的事情,在这种情况下,你的广告网络的一个JAR不是正确的。
<另外,JAR是JAR,而不是AAR。在这种情况下,广告网络的工程师是非常陌生的人。recyclerview-v7
在其AAR中具有RecyclerView
需要的资源(例如自定义属性)。基本上,通过发布一个包含RecyclerView
代码的JAR,他们正在使用他们的SDK开展工作:因为没有人可以使用它们的RecyclerView
,因为它是不完整的(可能过时),并且由于类冲突,任何人都不能使用官方RecyclerView
。
至少,我建议您向广告网络投诉,敦促他们切换到使用工件和一组适当的依赖项。
Error occurs only when I'm trying to take release or debug apk of my app. I can run or debug it on my device straight from Android Studio. From this question, I understood that this might be due to duplicate dependencies. So I tried to check whether there are any duplicate dependencies by running:
./gradlew -q :app:dependencies
I got the following dependency tree:
_releaseApk - ## Internal use, do not manually configure ## +--- com.android.support:appcompat-v7:25.3.1 | +--- com.android.support:support-annotations:25.3.1 | +--- com.android.support:support-v4:25.3.1 | | +--- com.android.support:support-compat:25.3.1 | | | \--- com.android.support:support-annotations:25.3.1 | | +--- com.android.support:support-media-compat:25.3.1 | | | +--- com.android.support:support-annotations:25.3.1 | | | \--- com.android.support:support-compat:25.3.1 (*) | | +--- com.android.support:support-core-utils:25.3.1 | | | +--- com.android.support:support-annotations:25.3.1 | | | \--- com.android.support:support-compat:25.3.1 (*) | | +--- com.android.support:support-core-ui:25.3.1 | | | +--- com.android.support:support-annotations:25.3.1 | | | \--- com.android.support:support-compat:25.3.1 (*) | | \--- com.android.support:support-fragment:25.3.1 | | +--- com.android.support:support-compat:25.3.1 (*) | | +--- com.android.support:support-media-compat:25.3.1 (*) | | +--- com.android.support:support-core-ui:25.3.1 (*) | | \--- com.android.support:support-core-utils:25.3.1 (*) | +--- com.android.support:support-vector-drawable:25.3.1 | | +--- com.android.support:support-annotations:25.3.1 | | \--- com.android.support:support-compat:25.3.1 (*) | \--- com.android.support:animated-vector-drawable:25.3.1 | \--- com.android.support:support-vector-drawable:25.3.1 (*) +--- com.android.support:cardview-v7:25.3.1 | \--- com.android.support:support-annotations:25.3.1 +--- com.android.support:recyclerview-v7:25.3.1 | +--- com.android.support:support-annotations:25.3.1 | +--- com.android.support:support-compat:25.3.1 (*) | \--- com.android.support:support-core-ui:25.3.1 (*) +--- com.android.support:design:25.3.1 | +--- com.android.support:support-v4:25.3.1 (*) | +--- com.android.support:appcompat-v7:25.3.1 (*) | +--- com.android.support:recyclerview-v7:25.3.1 (*) | \--- com.android.support:transition:25.3.1 | +--- com.android.support:support-annotations:25.3.1 | \--- com.android.support:support-v4:25.3.1 (*) +--- pl.droidsonroids.gif:android-gif-drawable:1.2.7 +--- com.google.android.gms:play-services-ads:10.2.6 | +--- com.google.android.gms:play-services-ads-lite:10.2.6 | | \--- com.google.android.gms:play-services-basement:10.2.6 | | \--- com.android.support:support-v4:25.2.0 -> 25.3.1 (*) | +--- com.google.android.gms:play-services-base:10.2.6 | | +--- com.google.android.gms:play-services-basement:10.2.6 (*) | | \--- com.google.android.gms:play-services-tasks:10.2.6 | | \--- com.google.android.gms:play-services-basement:10.2.6 (*) | +--- com.google.android.gms:play-services-clearcut:10.2.6 | | +--- com.google.android.gms:play-services-base:10.2.6 (*) | | \--- com.google.android.gms:play-services-basement:10.2.6 (*) | +--- com.google.android.gms:play-services-basement:10.2.6 (*) | \--- com.google.android.gms:play-services-gass:10.2.6 | \--- com.google.android.gms:play-services-basement:10.2.6 (*) +--- com.google.android.gms:play-services-location:10.2.6 | +--- com.google.android.gms:play-services-base:10.2.6 (*) | +--- com.google.android.gms:play-services-basement:10.2.6 (*) | \--- com.google.android.gms:play-services-tasks:10.2.6 (*) \--- com.google.firebase:firebase-core:10.2.6 \--- com.google.firebase:firebase-analytics:10.2.6 +--- com.google.firebase:firebase-analytics-impl:10.2.6 | +--- com.google.android.gms:play-services-basement:10.2.6 (*) | +--- com.google.firebase:firebase-iid:10.2.6 | | +--- com.google.android.gms:play-services-basement:10.2.6 (*) | | \--- com.google.firebase:firebase-common:10.2.6 | | +--- com.google.android.gms:play-services-basement:10.2.6 (*) | | \--- com.google.android.gms:play-services-tasks:10.2.6 (*) | +--- com.google.firebase:firebase-common:10.2.6 (*) | \--- com.google.android.gms:play-services-tasks:10.2.6 (*) +--- com.google.android.gms:play-services-basement:10.2.6 (*) \--- com.google.firebase:firebase-common:10.2.6 (*)
How to deduce which are the duplicate dependencies in my project from this tree? Are they the ones that end in asterisk?
Edit: My Gradle File is given below
apply plugin: 'com.android.application' android { compileSdkVersion 25 buildToolsVersion "25.0.3" defaultConfig { applicationId "com.mycompany.myapp" minSdkVersion 19 targetSdkVersion 25 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:25.3.1' compile 'com.android.support:cardview-v7:25.3.1' compile 'com.android.support:recyclerview-v7:25.3.1' compile 'com.android.support:design:25.3.1' compile 'pl.droidsonroids.gif:android-gif-drawable:1.2.7' compile 'com.google.android.gms:play-services-ads:10.2.6' compile 'com.google.android.gms:play-services-location:10.2.6' compile 'com.google.firebase:firebase-core:10.2.6' testCompile 'junit:junit:4.12' } apply plugin: 'com.google.gms.google-services'
Edit 2: Full gradle error:
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Landroid/support/v7/util/ThreadUtil$MainThreadCallback;
Edit 3: Since support/v7/util/ThreadUtil.java belongs to RecyclerView module, I tried to exclude the RecyclerView module under design library with the following:
dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:25.3.1' compile 'com.android.support:cardview-v7:25.3.1' compile 'com.android.support:recyclerview-v7:25.3.1' compile ('com.android.support:design:25.3.1') { exclude module: 'recyclerview-v7' } compile 'pl.droidsonroids.gif:android-gif-drawable:1.2.7' compile 'com.google.android.gms:play-services-ads:10.2.6' compile 'com.google.android.gms:play-services-location:10.2.6' compile 'com.google.firebase:firebase-core:10.2.6' testCompile 'junit:junit:4.12' }
Still doesn't work.
解决方案Per your comment, apparently the issue was a third-party SDK that distributed a JAR of
recyclerview-v7
, that you had inlibs/
, which conflicted with yourrecyclerview-v7
dependency.There are downsides to using plain JARs for dependencies.
One is that you tend to forget about them, particularly if you also are using dependencies from artifact repositories. For example, I didn't even consider that you might have JARs in
libs/
in my comment.Another is that Gradle cannot perform any sort of dependency resolution for them. Gradle relies on artifact metadata (POM files) for determining what dependencies are required. Gradle assumes that "you're doing the right thing" with respect to JAR files, and in this case, your ad network's one JAR isn't "the right thing".
Also, JARs are JARs, not AARs. In this case, the engineers at your ad network are very strange people.
recyclerview-v7
has resources in its AAR thatRecyclerView
needs (e.g., custom attributes). Basically, by distributing a JAR containingRecyclerView
code, they are dooming anyone using their SDK: nobody can use theirRecyclerView
because it is incomplete (and probably out of date), and nobody can use the officialRecyclerView
due to class conflicts.At minimum, I recommend that you complain to the ad network, urging them to switch to using artifacts and a proper set of dependencies.
这篇关于多个dex文件定义Landroid / support / v7 / util / ThreadUtil $ MainThreadCallback错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!