做项目的时候,遇到这个异常:
Error:Execution failed for task ':samsung_edge_reader:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/Users/xiongcen/Documents/develop/android-sdk-macosx/build-tools/21.1.1/dx -JXmx3g --dex --output /Users/xiongcen/Documents/workspace/MyApplication3/samsung_edge_reader/build/intermediates/dex/debug --input-list=/Users/xiongcen/Documents/workspace/MyApplication3/samsung_edge_reader/build/intermediates/tmp/dex/debug/inputList.txt
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
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:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:302)
at com.android.dx.command.dexer.Main.run(Main.java:245)
at com.android.dx.command.dexer.Main.main(Main.java:214)
at com.android.dx.command.Main.main(Main.java:106)
这个Error Code有分很多等级,现在碰到过2和3.
1》当Error Code=2时:
先说一下当时的环境,用得是AndroidStudio开发工具。在build.gradle中,看到一段代码:
dependencies { compile "com.android.support:cardview-v7:21.+" // compile 'com.android.support:multidex:1.0.+' // compile 'com.crashlytics.android:crashlytics:1.+' compile fileTree(dir: 'libs', include: '*.jar') compile files('libs/look_v1.1.1.jar') compile files('libs/sdk-v1.0.0.jar') }
一旦保存,那么项目就关联上v7包,在中可以看到项目关联包。
可是项目实际上已经在libs文件夹下添加v4包,引起冲突,所以出现以上异常。
解决办法:只要屏蔽compile 'com.android.support:cardview-v7:21.+'这句话。重新编译即可通过。
2》当Error Code=3时:
同事说只要在build.gradle文件中加,
dexOptions{ javaMaxHeapSize "3g" }
即可通过。但没有具体实践过。