小编xp-*_*vit的帖子

管理Android Gradle依赖项的最佳方式

我正在使用'com.android.tools.build:gradle:0.6.+'来构建我的android应用程序.

众所周知,Android dex不能包含相同库的不同版本.但是,当你想要使用Maven依赖时,如何处理情况需要一些你已经使用的库,但只是不同的版本.例.在build.gradle文件中有以下内容:

dependencies {
    compile 'com.android.support:appcompat-v7:+'
    compile 'com.github.chrisbanes.bitmapcache:library:2.3'
}
Run Code Online (Sandbox Code Playgroud)

产生错误:

UNEXPECTED TOP-LEVEL EXCEPTION:
    java.lang.IllegalArgumentException: already added: Landroid/support/v4/app/FragmentManager$OnBackStackChangedListener;
    at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
    at com.android.dx.dex.file.DexFile.add(DexFile.java:163)...
Run Code Online (Sandbox Code Playgroud)

出现此错误的原因如下:http://search.maven.org/remotecontent? filepath = com/github/clinbanes/bitmapcache/library3.3 / library2.3.​​pom需要com.google.android:support-v4

com.android.support:appcompat-v7:+已经包含com.google.android:support-v4,这导致双重包含相同的类文件.

我现在正在寻找以下答案:使用Ant将所有依赖项下载到'libs'文件夹并使用编译文件('...')等.

更改包含顺序olso没有帮助.

我正在寻找强大而方便的解决方案.如何使用maven依赖关系,仍然没有上述异常?想法?成熟的android开发者如何管理这个?

java android gradle android-gradle-plugin

5
推荐指数
1
解决办法
4216
查看次数

标签 统计

android ×1

android-gradle-plugin ×1

gradle ×1

java ×1