只有在我尝试发布或调试我的应用程序的apk时才会出现错误。我可以直接从Android Studio在我的设备上运行或调试它。从this问题,我了解到这可能是由于重复的依赖性。所以我试着通过运行来检查是否有任何重复的依赖:
./gradlew -q :app:dependencies
我得到了以下依赖树:
_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 (*)
如何从这棵树中推断出我项目中的重复依赖项?它们是以星号结尾的吗?
编辑:我的Gradle文件在下面给出
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'
编辑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 /支撑/ V7 / util的/ ThreadUtil $ MainThreadCallback;
编辑3:由于support / v7 / util / ThreadUtil.java属于RecyclerView模块,我尝试使用以下内容排除设计库下的RecyclerView模块:
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'
}
仍然无效。
答案 0 :(得分:1)
根据您的评论,显然该问题是分发recyclerview-v7
的JAR的第三方SDK,您在libs/
中遇到了与您的recyclerview-v7
依赖项冲突的问题。
将普通JAR用于依赖项存在缺点。
一个是您倾向于忘记它们,特别是如果您也正在使用工件存储库中的依赖项。例如,我甚至没有考虑到my comment中的libs/
中有JAR。
另一个原因是Gradle无法为它们执行任何类型的依赖项解析。 Gradle依赖于工件元数据(POM文件)来确定需要哪些依赖项。 Gradle认为"你正在做正确的事情"关于JAR文件,在这种情况下,您的广告网络的一个JAR并不是正确的事情"。
此外,JAR是JAR,而不是AAR。在这种情况下,广告网络中的工程师是非常奇怪的人。 recyclerview-v7
在其{1}}需要的AAR中拥有资源(例如,自定义属性)。基本上,通过分发包含RecyclerView
代码的JAR,他们正在使用他们的SDK进行操作:没有人可以使用他们的RecyclerView
因为它不完整(并且可能已过期),并且没有人可以使用官方{ {1}}由于课堂冲突。
至少,我建议您向广告网络投诉,敦促他们切换到使用工件和一组适当的依赖关系。