【问题标题】:Unable to merge dex error in android studio 3.0无法在 android studio 3.0 中合并 dex 错误
【发布时间】:2017-12-07 10:07:48
【问题描述】:

我正在寻找可以帮助我解决这个问题的答案。我试图在过去 2 天解决这个问题。但是,我仍然没有得到可以解决我的问题的答案。我已经尝试了很多这里给出的解决方案。但没有一个解决方案对我有用。 请帮我解决这个问题。任何帮助将不胜感激。

实际问题是:

Error:Execution failed for task
':app:transformDexArchiveWithExternalLibsDexMergerForGlobalServerDebug'.
 java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

每次我在 android studio 3.0 上运行现有项目时都会发生这种情况

我为此尝试了很多解决方案,例如:

1-在gradle中添加mutidexenabledtrue

2- 改变依赖的版本

3- 用实现改变编译关键字

4- 清理和重建项目

5- 删除 Gradle 文件(这太难了,因为当你再次 重新启动项目,不会自动重新生成 Gradle 文件)等。

我正在寻找上述解决方案以外的解决方案。请帮帮我。请...

gradle文件代码如下:

apply plugin: 'com.android.application'
buildscript {
    repositories {
        mavenCentral()
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'io.fabric'

repositories {
    mavenCentral()
    maven { url 'https://maven.fabric.io/public' }

    flatDir {
        dirs 'libs'
    }
}
repositories {
    maven { url 'http://clojars.org/repo' }
}

android {
    signingConfigs {
        config {
            keyAlias 'example'
            keyPassword 'example'
            storeFile file('/Users/standarduser/Documents/Android_Projects/example.jks')
            storePassword '@@@@@@@@'
        }
    }
    compileSdkVersion 25
    buildToolsVersion '26.0.2'
    defaultConfig {
        applicationId 'com.example.example'
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 9  // both Latest
        versionName "2.0.7"
        multiDexEnabled true
        useLibrary 'org.apache.http.legacy'
        vectorDrawables.useSupportLibrary = true
        signingConfig signingConfigs.config
    }
    dexOptions {
        incremental = true
        preDexLibraries = false
        javaMaxHeapSize "4g"
    }
    aaptOptions.cruncherEnabled = false
    aaptOptions.useNewCruncher = false
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

        }
    }
    android {
        packagingOptions
                {
                    exclude 'META-INF/DEPENDENCIES.txt'
                    exclude 'META-INF/LICENSE.txt'
                    exclude 'META-INF/NOTICE.txt'
                    exclude 'META-INF/NOTICE'
                    exclude 'META-INF/LICENSE'
                    exclude 'META-INF/DEPENDENCIES'
                    exclude 'META-INF/notice.txt'
                    exclude 'META-INF/license.txt'
                    exclude 'META-INF/dependencies.txt'
                    exclude 'META-INF/LGPL2.1'
                }
    }

    lintOptions{
        abortOnError false
    }
}

dependencies {
    compile files('libs/httpcore-4.4.1.jar')
    compile('com.twitter.sdk.android:twitter:2.1.1@aar') { //1.6.1@aar
        transitive = true;
    }
    compile('com.github.afollestad.material-dialogs:core:0.8.5.2@aar') {
        transitive = true
    }
    compile('io.socket:socket.io-client:0.8.2') { // 0.6.3
        // excluding org.json which is provided by Android
        exclude group: 'org.json', module: 'json'
    }
    testCompile 'junit:junit:4.12'
    compile 'com.writingminds:FFmpegAndroid:0.3.2'
    compile 'com.mcxiaoke.volley:library:1.0.19'
    compile 'io.nlopez.smartlocation:library:3.2.9'
    //   compile 'com.android.volley:volley:1.0.0'
    compile 'com.google.android.gms:play-services-appinvite:9.8.0'
    //9.0.1
    compile 'com.google.android.gms:play-services-gcm:9.8.0'
    compile 'com.google.android.gms:play-services-location:9.8.0'
    compile 'com.google.android.gms:play-services-places:9.8.0'
    compile 'com.google.android.gms:play-services-maps:9.8.0'
    compile 'com.google.android.gms:play-services-ads:9.8.0'
    compile 'com.google.android.gms:play-services-auth:9.8.0'
    compile 'com.google.android.gms:play-services-plus:9.8.0'
    //noinspection GradleCompatible
    compile 'com.android.support:appcompat-v7:25.3.0'
    compile 'com.android.support:design:25.0.1'
    compile 'de.hdodenhof:circleimageview:2.1.0'
    compile 'com.google.code.gson:gson:2.4'
    compile 'org.apache.httpcomponents:httpmime:4.3.5'
//    implementation 'org.apache.httpcomponents:httpmime:4.3.6'
//    implementation 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'com.facebook.android:facebook-android-sdk:4.23.0'
    compile 'com.pusher:pusher-java-client:1.1.2'
    compile 'com.android.support:recyclerview-v7:25.0.1'
    compile 'com.android.support:cardview-v7:25.0.1'
    compile 'com.daimajia.swipelayout:library:1.2.0@aar'
    compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.6'
    compile 'com.amazonaws:aws-android-sdk-mobileanalytics:2.2.9'
    compile 'com.commit451:PhotoView:1.2.4'
    compile 'commons-lang:commons-lang:2.3'
    compile 'com.karumi:dexter:2.3.1'
    compile 'com.jakewharton:butterknife:8.5.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
    implementation 'com.android.support:multidex:1.0.2'
    compile 'org.ocpsoft.prettytime:prettytime:3.2.7.Final'
    compile 'com.koushikdutta.async:androidasync:2.+'
    compile 'com.soundcloud.android:android-crop:1.0.1@aar'
    compile 'net.danlew:android.joda:2.9.4.1'
    compile 'com.albinmathew:photo-crop-library:1.0.3'
    compile 'com.amazonaws:aws-android-sdk-core:2.2.+'
    compile 'com.amazonaws:aws-android-sdk-s3:2.2.+'
    compile 'com.wang.avi:library:2.1.3'
    compile 'com.wowza.gocoder.sdk.android:com.wowza.gocoder.sdk:1.0b7@aar'
    compile 'com.theartofdev.edmodo:android-image-cropper:2.3.+'
    compile('com.crashlytics.sdk.android:crashlytics:2.6.4@aar') {
        transitive = true;
    }
    compile 'com.google.code.gson:gson:2.7'
    compile 'com.squareup.retrofit2:retrofit:2.1.0'
    //    compile 'com.cocosw:bottomsheet:1.+@aar'
    compile project(':libbambuser7')
    compile 'com.squareup.okhttp:okhttp:2.0.0'
}

apply plugin: 'com.google.gms.google-services'

【问题讨论】:

  • 请添加您的应用级 gradle 文件
  • 你用过com.google.android.gms:play-services:哪个版本
  • 版本 - 9.8.0
  • 请检查答案。
  • 是的,检查一下

标签: android android-multidex


【解决方案1】:

将此添加到您的 build.gradle

android {
    defaultConfig {
       multiDexEnabled true
    }
}
  • 然后首先同步 gradle
  • 从 Build 菜单 -> 按 Clean Project 按钮。
  • 任务完成后,按“构建”菜单中的“重建项目”按钮。
  • compile 现在是deprecated 所以最好使用 implementation 或 api

希望这对你有帮助。

【讨论】:

  • 我已经这样做了很多次了。这对我不起作用
  • 请分享您的 build.xml 文件,这里主要是这个错误的常见解决方案。
  • 我已分享。现在你可以看到
【解决方案2】:

试试这个

使用这个

com.google.android.gms:play-services:11.6.0

com.google.android.gms:play-services-location:11.6.0 

不是这个

com.google.android.gms:play-services:9.8.0

同步之后 -> clean -> 重建

【讨论】:

  • 仍然出现同样的问题
  • 使用所有最新版本的库。
  • @KulsDroid 谢谢
  • 其实我也遇到了同样的问题!你能简要解释一下它是如何解决这个问题的!
  • @Ratilal Chopda 我已经更新了我的所有库,但问题仍然没有解决
猜你喜欢
  • 2018-05-04
  • 1970-01-01
  • 2018-04-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-15
  • 2018-04-24
  • 1970-01-01
相关资源
最近更新 更多