天天看點

解決Android Studio加載第三方jar包,出現包重複加載的問題

今天在工作中碰到了一個加載fresco這個架構,碰到了suport包重複引用的問題,一是本身應用上需要應用,但是fresco中又包含有該報,導緻在果然掉了在編譯的時候出現錯誤:

Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
	F:\zsl\sdk\build-tools\21.1.2\dx.bat --dex --output F:\zsl\Android\pro\RecipesDaquan\app\build\intermediates\dex\debug --input-list=F:\zsl\Android\pro\RecipesDaquan\app\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/AccessibilityServiceInfoCompatIcs;
		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:303)
		at com.android.dx.command.dexer.Main.run(Main.java:246)
		at com.android.dx.command.dexer.Main.main(Main.java:215)
		at com.android.dx.command.Main.main(Main.java:106)
           
解決的方法就是
           
compile 'com.android.support:appcompat-v7:21.0.0'
    compile ('in.srain.cube:cube-sdk:1.0.42.1'){
        exclude module: 'support-v4'
    }
    compile files('libs/android-async-http-1.4.6.jar')
}