好的我知道关于这个话题有很多问题和答案。我读了这么多,结果通常是一样的,你有相互矛盾的冲突。有些人甚至建议运行gradlew依赖项来获取树。奇怪的是,此命令显示所有依赖项都运行相同的版本号。非常感谢任何帮助,我感到茫然。下面找到我的命令输出,来自AndroidStudio和app.gradle文件的错误。我还应该提到,只有在尝试调试设备时才会出现此错误,而不是在gradle构建和同步时。
错误
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/annotation/AnimRes;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
at com.android.dx.command.dexer.Main.run(Main.java:277)
at com.android.dx.command.dexer.Main.main(Main.java:245)
at com.android.dx.command.Main.main(Main.java:106)
app.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.company.company"
minSdkVersion 17
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
}
命令输出
:app:dependencies
------------------------------------------------------------
Project :app
------------------------------------------------------------
_debugAndroidTestApk - ## Internal use, do not manually configure ##
No dependencies
_debugAndroidTestCompile - ## Internal use, do not manually configure ##
No dependencies
_debugApk - ## Internal use, do not manually configure ##
+--- com.android.support:appcompat-v7:23.0.1
| \--- com.android.support:support-v4:23.0.1
| \--- com.android.support:support-annotations:23.0.1
\--- com.android.support:design:23.0.1
+--- com.android.support:support-v4:23.0.1 (*)
\--- com.android.support:appcompat-v7:23.0.1 (*)
_debugCompile - ## Internal use, do not manually configure ##
+--- com.android.support:appcompat-v7:23.0.1
| \--- com.android.support:support-v4:23.0.1
| \--- com.android.support:support-annotations:23.0.1
\--- com.android.support:design:23.0.1
+--- com.android.support:support-v4:23.0.1 (*)
\--- com.android.support:appcompat-v7:23.0.1 (*)
_debugUnitTestApk - ## Internal use, do not manually configure ##
No dependencies
_debugUnitTestCompile - ## Internal use, do not manually configure ##
No dependencies
_releaseApk - ## Internal use, do not manually configure ##
+--- com.android.support:appcompat-v7:23.0.1
| \--- com.android.support:support-v4:23.0.1
| \--- com.android.support:support-annotations:23.0.1
\--- com.android.support:design:23.0.1
+--- com.android.support:support-v4:23.0.1 (*)
\--- com.android.support:appcompat-v7:23.0.1 (*)
_releaseCompile - ## Internal use, do not manually configure ##
+--- com.android.support:appcompat-v7:23.0.1
| \--- com.android.support:support-v4:23.0.1
| \--- com.android.support:support-annotations:23.0.1
\--- com.android.support:design:23.0.1
+--- com.android.support:support-v4:23.0.1 (*)
\--- com.android.support:appcompat-v7:23.0.1 (*)
_releaseUnitTestApk - ## Internal use, do not manually configure ##
No dependencies
_releaseUnitTestCompile - ## Internal use, do not manually configure ##
No dependencies
androidJacocoAgent - The Jacoco agent to use to get coverage data.
Download https://jcenter.bintray.com/org/jacoco/org.jacoco.agent/0.7.4.201502262128/org.jacoco.agent-0.7.4.201502262128.pom
\--- org.jacoco:org.jacoco.agent:0.7.4.201502262128
androidJacocoAnt - The Jacoco ant tasks to use to get execute Gradle tasks.
Download https://jcenter.bintray.com/org/jacoco/org.jacoco.ant/0.7.4.201502262128/org.jacoco.ant-0.7.4.201502262128.pom
Download https://jcenter.bintray.com/org/jacoco/org.jacoco.report/0.7.4.201502262128/org.jacoco.report-0.7.4.201502262128.pom
\--- org.jacoco:org.jacoco.ant:0.7.4.201502262128
+--- org.jacoco:org.jacoco.core:0.7.4.201502262128
| \--- org.ow2.asm:asm-debug-all:5.0.1
+--- org.jacoco:org.jacoco.report:0.7.4.201502262128
| +--- org.jacoco:org.jacoco.core:0.7.4.201502262128 (*)
| \--- org.ow2.asm:asm-debug-all:5.0.1
\--- org.jacoco:org.jacoco.agent:0.7.4.201502262128
androidTestApk - Classpath packaged with the compiled 'androidTest' classes.
No dependencies
androidTestCompile - Classpath for compiling the androidTest sources.
No dependencies
androidTestProvided - Classpath for only compiling the androidTest sources.
No dependencies
androidTestWearApp - Link to a wear app to embed for object 'androidTest'.
No dependencies
apk - Classpath packaged with the compiled 'main' classes.
No dependencies
archives - Configuration for archive artifacts.
No dependencies
compile - Classpath for compiling the main sources.
+--- com.android.support:appcompat-v7:23.0.1
| \--- com.android.support:support-v4:23.0.1
| \--- com.android.support:support-annotations:23.0.1
\--- com.android.support:design:23.0.1
+--- com.android.support:support-v4:23.0.1 (*)
\--- com.android.support:appcompat-v7:23.0.1 (*)
debugApk - Classpath packaged with the compiled 'debug' classes.
No dependencies
debugCompile - Classpath for compiling the debug sources.
No dependencies
debugProvided - Classpath for only compiling the debug sources.
No dependencies
debugWearApp - Link to a wear app to embed for object 'debug'.
No dependencies
default - Configuration for default artifacts.
No dependencies
default-mapping - Configuration for default mapping artifacts.
No dependencies
default-metadata - Metadata for the produced APKs.
No dependencies
provided - Classpath for only compiling the main sources.
No dependencies
releaseApk - Classpath packaged with the compiled 'release' classes.
No dependencies
releaseCompile - Classpath for compiling the release sources.
No dependencies
releaseProvided - Classpath for only compiling the release sources.
No dependencies
releaseWearApp - Link to a wear app to embed for object 'release'.
No dependencies
testApk - Classpath packaged with the compiled 'test' classes.
No dependencies
testCompile - Classpath for compiling the test sources.
No dependencies
testDebugApk - Classpath packaged with the compiled 'testDebug' classes.
No dependencies
testDebugCompile - Classpath for compiling the testDebug sources.
No dependencies
testDebugProvided - Classpath for only compiling the testDebug sources.
No dependencies
testDebugWearApp - Link to a wear app to embed for object 'testDebug'.
No dependencies
testProvided - Classpath for only compiling the test sources.
No dependencies
testReleaseApk - Classpath packaged with the compiled 'testRelease' classes.
No dependencies
testReleaseCompile - Classpath for compiling the testRelease sources.
No dependencies
testReleaseProvided - Classpath for only compiling the testRelease sources.
No dependencies
testReleaseWearApp - Link to a wear app to embed for object 'testRelease'.
No dependencies
testWearApp - Link to a wear app to embed for object 'test'.
No dependencies
wearApp - Link to a wear app to embed for object 'main'.
No dependencies
答案 0 :(得分:1)
design
库包含appcompat-v7
lib,您可以明确指定它
dependencies {
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
}
如果只是从support
lib的类路径中排除design
libs组,那么你应该很好。你可以做这样的事情
dependencies {
compile 'com.android.support:appcompat-v7:23.0.1'
compile('com.android.support:design:23.0.1') {
exclude group: 'com.android.support'
}
}
您可以在依赖关系图中看到这一点:
compile - Classpath for compiling the main sources.
+--- com.android.support:appcompat-v7:23.0.1
| \--- com.android.support:support-v4:23.0.1
| \--- com.android.support:support-annotations:23.0.1
\--- com.android.support:design:23.0.1
+--- com.android.support:support-v4:23.0.1 (*) <-- already in project class path
\--- com.android.support:appcompat-v7:23.0.1 (*) <-- already in project class path
你提到这只发生在调试期间。我猜这是因为你的proguard正在删除release
版本的违规类,而不是debug
。您可能还想尝试更新build.gradle
以在debug
和release
版本上运行proguard
android {
// other stuff...
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
// other stuff...
}