当前位置:  开发笔记 > Android > 正文

多个dex文件在android studio中定义了Landroid/support/v4 /

如何解决《多个dex文件在androidstudio中定义了Landroid/support/v4/》经验,为你挑选了0个好方法。

我可以integrate (add & work) with many libraries.

但至于ActionBarSherlock图书馆,我有很多问题.

第一期是热门问题Multiple dex files define,

我知道duplicated android-support-v4.jar它的原因,但我现在无法解决这个问题:

Error:Execution failed for task ':fitness:dexDebug'.

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:594)
    at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)
    at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533)
    at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)
    at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
    at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
    at com.android.dx.command.dexer.Main.run(Main.java:230)
    at com.android.dx.command.dexer.Main.main(Main.java:199)
    at com.android.dx.command.Main.main(Main.java:103)

我在同样的错误中遵循了答案.它用于:

dependencies {
    compile('...') {
      exclude module: 'support-v4'
    }

    compile 'com.android.support:support-v4:18.0.+'
}

但我收到第二期:unsupported Gradle DSL method found: 'exclude()'!错误.因此,我改变build.gradlemain module这样的:

//configurations {
//    all*.exclude group: 'com.android.support', module: 'support-v4'
//}

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':google-play-services')
    compile files('/google-play-services/libs/google-play-services.jar')
    compile (project(':actionbarsherlock')) {
        exclude(module: 'support-v4')
    }
    compile 'com.android.support:support-v4:18.0.+'
}

Solved 第二期,但仍然得到第一期 Multiple dex files define错误.

我读了很多主题,但现在无法解决第一期,

请帮我,

谢谢,

p/s:我可以顺利地与Gradle同步,但是在运行时,它会遇到错误.

我使用Android studio 0.5.5

编辑

build.gradleActionBarSherlock,它只有一个android-support-v4.jar:

dependencies {
        compile fileTree(dir: 'libs', include: '*.jar')
}

setting.gradle 像这样 :

include ':fitness', ':google-play-services',':actionbarsherlock'

@Garbriele:我更新了新的问题,显示build.gradle of projectbuild.gradle of main module build.gradleproject:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.+'
    }
}

build.gradlemain module修改后:

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar' // Get following error in this line
} 

我在下面得到了这个错误:

在此输入图像描述

好的,感谢@Garbriele的评论,我已经通过使用这个解决了这个问题:

repositories {
            mavenCentral()
        }
dependencies {
        compile fileTree(dir: 'libs', include: '*.jar')
        compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar' // Get following error in this line
    } 

编辑2当我这样说:

repositories {
            mavenCentral()
        }
dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile 'com.google.android.gms:play-services:+'
}

仍然会收到First Issue Multiple dex files define错误.

我现在想要的是如何成功添加com.google.android.gms:play-servicesMaven,

请帮我,

谢谢,

UPDATE

完成以下步骤后:

将库通过Maven放入build.gradle主模块中:compile 'com.google.android.gms:play-services:+'

Restart Android Studio

Sync project with gradle

再也不会出现此错误.

推荐阅读
U友50081205_653
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有