解决Android Studio加载第三方jar包,出现包重复加载的问题:

通过Maven中央库添加第三方jar包的时候,出现了重复加载jar包的问题,解决办法很简单去掉一个不让它去加载就OK了

一、错误

Error: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:<strong> <span style="color:#3333ff;">Multiple dex files define Landroid/</span><span style="color:#ff0000;">support/v4</span><span style="color:#3333ff;">/accessibilityservice/AccessibilityServiceInfoCompatIcs;</span></strong>
		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)

从上述错误中我们可以看到support_v4的包重复加载编译了,我们看一下gradle-app文件


dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.0'
    <span style="color:#ff0000;">compile 'in.srain.cube:cube-sdk:1.0.42.1'</span>
    compile files('libs/android-async-http-1.4.6.jar')
}
其中引入了v7的包后会自动去加载编译一个v4:21.0.0包,而在in.srain.cube:cube-sdk:1.0.42.1库中也有一个v4的包,所以我们需要去掉一个


看一下,libraries是否是我们所讲的那样,重复加载v4包


二、解决办法

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.0'
    <span style="color:#ff0000;">compile ('in.srain.cube:cube-sdk:1.0.42.1'){
        exclude module: 'support-v4'
    }</span>
    compile files('libs/android-async-http-1.4.6.jar')
}
去掉in.srain.cube:cube-sdk:1.0.42.1中的包不加载即可。



阅读更多
换一批

没有更多推荐了,返回首页