最近在调整代码的时候,出现如下问题:

1 2 3 4 5 6 7 8 9 10 11 12 13 Cause : com . android . dex . DexException : Multiple dex files define Landroid / support / annotation / AnimRes ;      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 : 579 )          at com . android . dx . merge . DexMerger . getSortedTypes ( DexMerger . java : 535 )          at com . android . dx . merge . DexMerger . mergeClassDefs ( DexMerger . java : 517 )          at com . android . dx . merge . DexMerger . mergeDexes ( DexMerger . java : 164 )          at com . android . dx . merge . DexMerger . merge ( DexMerger . java : 188 )          at com . android . dx . command . dexer . Main . mergeLibraryDexBuffers ( Main . java : 504 )          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 )

网上查询了一下,找到如下的解决方法:

我们常常用 gradle.build文件导入依赖库,但是有时候库依赖会发生版本冲突或多个模块依赖同一个库的情况,这就引出两个问题,如下:

  • 版本冲突时, Gradle会下载多个版本的依赖库吗?
  • 当多个模块依赖同一个库时,每个模块都会去下载该依赖库吗?
    为解决这疑问,接下来我们在 Android Studio用 Gradle举个例子:
    gradle.build依赖部分的配置:

1 2 3 4 5 6 7 8 dependencies {      compile 'com.android.support:appcompat-v7:22.2.1'      compile ( 'com.android.support:design:22.2.1' )      compile 'com.shamanland:fonticon:0.1.8'      androidTestCompile 'com.android.support:support-annotations:22.2.1'      androidTestCompile 'com.android.support.test:runner:0.3'      androidTestCompile ( 'com.android.support.test.espresso:espresso-core:2.2' ) }

在文件目录下或 Android Studio的 Terminal下敲 gradlew -q app:dependencies 命令,便有以下输出:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 _debugAndroidTestApk - # # Internal use , do not manually configure # # + -- - com . android . support : support - annotations : 22.2.1 + -- - com . android . support . test : runner : 0.3 |      + -- - com . android . support . test : exposed - instrumentation - api - publish : 0.3 |      + -- - junit : junit : 4.12 |      |      \ -- - org . hamcrest : hamcrest - core : 1.3 |      \ -- - com . android . support : support - annotations : 22.2.0 -> 22.2.1 \ -- - com . android . support . test . espresso : espresso - core : 2.2      + -- - com . android . support . test . espresso : espresso - idling - resource : 2.2      + -- - com . squareup : javawriter : 2.1.1      + -- - javax . inject : javax . inject : 1      + -- - org . hamcrest : hamcrest - library : 1.3      |      \ -- - org . hamcrest : hamcrest - core : 1.3      + -- - com . android . support . test : rules : 0.3      |      \ -- - com . android . support . test : runner : 0.3 ( * )      + -- - org . hamcrest : hamcrest - integration : 1.3      |      \ -- - org . hamcrest : hamcrest - library : 1.3 ( * )      + -- - com . google . code . findbugs : jsr305 : 2.0.1      + -- - javax . annotation : javax . annotation - api : 1.2      \ -- - com . android . support . test : runner : 0.3 ( * )   _debugAndroidTestCompile - # # Internal use , do not manually configure # # + -- - com . android . support : support - annotations : 22.2.1 + -- - com . android . support . test : runner : 0.3 |      + -- - com . android . support . test : exposed - instrumentation - api - publish : 0.3 |      + -- - junit : junit : 4.12 |      |      \ -- - org . hamcrest : hamcrest - core : 1.3 |      \ -- - com . android . support : support - annotations : 22.2.0 -> 22.2.1 \ -- - com . android . support . test . espresso : espresso - core : 2.2      + -- - com . android . support . test . espresso : espresso - idling - resource : 2.2      + -- - com . squareup : javawriter : 2.1.1      + -- - javax . inject : javax . inject : 1      + -- - org . hamcrest : hamcrest - library : 1.3      |      \ -- - org . hamcrest : hamcrest - core : 1.3      + -- - com . android . support . test : rules : 0.3      |      \ -- - com . android . support . test : runner : 0.3 ( * )      + -- - org . hamcrest : hamcrest - integration : 1.3      |      \ -- - org . hamcrest : hamcrest - library : 1.3 ( * )      + -- - com . google . code . findbugs : jsr305 : 2.0.1      + -- - javax . annotation : javax . annotation - api : 1.2      \ -- - com . android . support . test : runner : 0.3 ( * )   _debugApk - # # Internal use , do not manually configure # # + -- - com . android . support : multidex : 1.0.1 + -- - com . android . support : appcompat - v7 : 22.2.1 |      \ -- - com . android . support : support - v4 : 22.2.1 |          \ -- - com . android . support : support - annotations : 22.2.1 + -- - com . android . support : design : 22.2.1 |      + -- - com . android . support : appcompat - v7 : 22.2.1 ( * ) |      \ -- - com . android . support : support - v4 : 22.2.1 ( * ) \ -- - com . shamanland : fonticon : 0.1.8   _debugCompile - # # Internal use , do not manually configure # # + -- - com . android . support : multidex : 1.0.1 + -- - com . android . support : appcompat - v7 : 22.2.1 |      \ -- - com . android . support : support - v4 : 22.2.1 |          \ -- - com . android . support : support - annotations : 22.2.1 + -- - com . android . support : design : 22.2.1 |      + -- - com . android . support : appcompat - v7 : 22.2.1 ( * ) |      \ -- - com . android . support : support - v4 : 22.2.1 ( * ) \ -- - com . shamanland : fonticon : 0.1.8   _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 : multidex : 1.0.1 + -- - com . android . support : appcompat - v7 : 22.2.1 |      \ -- - com . android . support : support - v4 : 22.2.1 |          \ -- - com . android . support : support - annotations : 22.2.1 + -- - com . android . support : design : 22.2.1 |      + -- - com . android . support : appcompat - v7 : 22.2.1 ( * ) |      \ -- - com . android . support : support - v4 : 22.2.1 ( * ) \ -- - com . shamanland : fonticon : 0.1.8   _releaseCompile - # # Internal use , do not manually configure # # + -- - com . android . support : multidex : 1.0.1 + -- - com . android . support : appcompat - v7 : 22.2.1 |      \ -- - com . android . support : support - v4 : 22.2.1 |          \ -- - com . android . support : support - annotations : 22.2.1 + -- - com . android . support : design : 22.2.1 |      + -- - com . android . support : appcompat - v7 : 22.2.1 ( * ) |      \ -- - com . android . support : support - v4 : 22.2.1 ( * ) \ -- - com . shamanland : fonticon : 0.1.8   _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 . \ -- - org . jacoco : org . jacoco . agent : 0.7.4.201502262128   androidJacocoAnt - The Jacoco ant tasks to use to get execute Gradle tasks . \ -- - 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 . + -- - com . android . support : support - annotations : 22.2.1 + -- - com . android . support . test : runner : 0.3 |      + -- - com . android . support . test : exposed - instrumentation - api - publish : 0.3 |      + -- - junit : junit : 4.12 |      |      \ -- - org . hamcrest : hamcrest - core : 1.3 |      \ -- - com . android . support : support - annotations : 22.2.0 -> 22.2.1 \ -- - com . android . support . test . espresso : espresso - core : 2.2      + -- - com . android . support . test . espresso : espresso - idling - resource : 2.2      + -- - com . squareup : javawriter : 2.1.1      + -- - javax . inject : javax . inject : 1      + -- - org . hamcrest : hamcrest - library : 1.3      |      \ -- - org . hamcrest : hamcrest - core : 1.3      + -- - com . android . support . test : rules : 0.3      |      \ -- - com . android . support . test : runner : 0.3 ( * )      + -- - org . hamcrest : hamcrest - integration : 1.3      |      \ -- - org . hamcrest : hamcrest - library : 1.3 ( * )      + -- - com . google . code . findbugs : jsr305 : 2.0.1      + -- - javax . annotation : javax . annotation - api : 1.2      \ -- - com . android . support . test : runner : 0.3 ( * )   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 : 22.2.1 |      \ -- - com . android . support : support - v4 : 22.2.1 |          \ -- - com . android . support : support - annotations : 22.2.1 + -- - com . android . support : design : 22.2.1 |      + -- - com . android . support : appcompat - v7 : 22.2.1 ( * ) |      \ -- - com . android . support : support - v4 : 22.2.1 ( * ) \

更多相关文章

  1. android EditText设置不可写
  2. Android(安卓)Wifi模块分析(三)
  3. Android(安卓)Activity的启动
  4. APP开发实战94-Vector静态图的使用
  5. Android架构分析之使用自定义硬件抽象层(HAL)模块
  6. Android(安卓)开发中的倒计时
  7. Gradle多渠道打包
  8. [APP] Android(安卓)开发笔记 006-使用短信验证SDK进行短信验证
  9. Android(安卓)5.x特性概览二

随机推荐

  1. AM:新型“水-醚”电解质基水系锂离子电池
  2. Solar RRL:2D/2D基Z型异质结在光催化应用
  3. AS:有机配体“武装”的氧化锌提高CsPbI2Br
  4. 澳大利亚昆士兰科技大学Liangzhi Kou团队
  5. Small Structures:低载量Pt纳米团簇锚定在
  6. AM:顺序A位掺杂精确控制钙钛矿结晶动力学
  7. Small:等离激元超构表面与单层二硫化钼光
  8. PHP基础知识:PHP代码书写规范及数组遍历方
  9. 购物车全选与自动计算参与结算的商品价格
  10. 04-Vue_过滤器