问题描述
只有当我尝试释放或调试我的应用的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错误:
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 in libs/
, which conflicted with your recyclerview-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 that RecyclerView
needs (e.g., custom attributes). Basically, by distributing a JAR containing RecyclerView
code, they are dooming anyone using their SDK: nobody can use their RecyclerView
because it is incomplete (and probably out of date), and nobody can use the official RecyclerView
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错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!