2015-11-03 68 views
0

好的我知道关于这个话题有很多关于SO的问题和答案。我读了很多,结果通常是一样的,你有相互依赖的冲突。有些人甚至建议运行gradlew依赖来获得一棵树。奇怪的是,这个命令显示所有的依赖都运行相同的版本号。任何帮助非常感谢,我很茫然。下面找到我的命令输出,来自AndroidStudio和app.gradle文件的错误。我还应该提到,只有在尝试调试到设备时才会出现此错误,而不是在gradle构建和同步时发生。定义了多个dex文件

错误

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 

回答

1

design库包含appcompat-v7 lib和你指定它明确

dependencies { 
    compile 'com.android.support:appcompat-v7:23.0.1' 
    compile 'com.android.support:design:23.0.1' 
} 

你应该是不错的,如果你只是从design 11b的类路径排除support库群。你可以做这样的事情

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运行ProGuard,并将在两个debugrelease建立

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... 
} 
+0

感谢您的回答!我实现了这两个代码更改,但我仍然留下了相同的问题。有没有机会使用我正在使用的gradle版本? (1.4.0-beta6) – Kyle

+1

后续行动:结合您的两条建议并升级到1.5.0-beta1可以解决问题。 – Kyle

+0

使用compile'c​​om.android.support:appcompat-v7:23.0.1'和 compile'c​​om.android.support:design:23.0.1'不会产生问题。 –

相关问题