无法合并Dex - Android Studio 3.0.1 DexArchiveMergerException

时间:2018-02-28 11:53:06

标签: android gradle android-gradle android-studio-3.1

我开始收到以下错误

  

错误:任务':app:transformDexArchiveWithExternalLibsDexMergerForDebug'执行失败。   java.lang.RuntimeException:java.lang.RuntimeException:com.android.builder.dexing.DexArchiveMergerException:无法合并dex

我尝试重置我的备份,但同样的问题

我尝试了所有解决方案,例如

multiDexEnabled true

清理和重建项目,但它没有工作。任何帮助将不胜感激。

应用文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.2'
    defaultConfig {
        applicationId "com.example"
        minSdkVersion 18
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
        resConfigs "auto"

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
ext {
    supportLibraryVersion = '27.0.2'
    grpcVersion = '1.4.0'
}
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    testImplementation 'junit:junit:4.12'
//appcompat libraries
    compile 'com.android.support:design:27.0.2'
    compile 'com.android.support:appcompat-v7:27.0.2'
    implementation 'com.android.support:support-v4:27.1.0'

//butterknife
    compile 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

//retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.3.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
    implementation 'com.squareup.okhttp3:okhttp:3.8.0'
    implementation 'com.jakewharton.retrofit:retrofit1-okhttp3-client:1.0.2'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.scottyab:aes-crypto:0.0.4'
//circleimageview
    implementation 'de.hdodenhof:circleimageview:2.2.0'
//ZXing for barCode reader
    compile 'com.journeyapps:zxing-android-embedded:3.2.0@aar'
    compile 'com.google.zxing:core:3.2.1'
//gson
    compile 'com.google.code.gson:gson:2.8.2'
//recyclerview and cardview
    implementation 'com.android.support:cardview-v7:27.0.2'
    compile 'com.android.support:recyclerview-v7:+'
//play-services
    compile 'com.google.android.gms:play-services-maps:11.8.0'




    implementation 'com.github.bumptech.glide:glide:4.3.1'
    implementation 'com.jaeger.statusbarutil:library:1.4.0'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    compile 'com.android.support:support-annotations:27.0.2'
    compile 'com.wang.avi:library:2.1.3'

}

项目文件

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'

    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

我在这里看了很多其他问题和答案,但似乎无法找到解决问题的解决方案:(

2 个答案:

答案 0 :(得分:0)

我在尝试了stackoverflow上的所有解决方案后解决了,尝试按顺序执行以下步骤

  1. 将所有编译替换为实现
  2. 使所有supportLibraryVersion = '27 .0.2'
  3. 更改
  4.   

    'com.google.android.gms:播放服务-地图:11.8.0'

      

    'com.google.android.gms:播放服务-地图:11.4.0'

    1. 删除所有未使用的库
    2. 删除项目中的.gradle文件夹
    3. 删除构建文件夹和gradle缓存
    4. file - >使缓存/重启无效
    5. 构建>清洁项目
    6. 添加
    7.   

      dependencies {implementation'comcom.android.support :multidex:1.0.1'}

      1. 添加
      2.   

        android {       defaultConfig {           multiDexEnabled是的           }   }

        1. 异步项目
        2. 最后这是我的App文件

          apply plugin: 'com.android.application'
          
          android {
              compileSdkVersion 27
              defaultConfig {
                  applicationId "com.example"
                  minSdkVersion 18
                  targetSdkVersion 27
                  versionCode 1
                  versionName "1.0"
                  multiDexEnabled true
                  testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
              }
              buildTypes {
                  release {
                      minifyEnabled false
                      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                  }
              }
          
          }
          ext {
              supportLibraryVersion = '27.0.2'
          
          }
          dependencies {
          
              implementation fileTree(dir: 'libs', include: ['*.jar'])
              testImplementation 'junit:junit:4.12'
              androidTestImplementation 'com.android.support.test:runner:1.0.1'
              androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
          
              implementation 'com.android.support:support-v4:27.0.2'
              implementation 'com.android.support:appcompat-v7:27.0.2'
              implementation 'com.android.support:design:27.0.2'
          
          
          //constraint
              implementation 'com.android.support.constraint:constraint-layout:1.0.2'
          
          //butterknife
              implementation  'com.jakewharton:butterknife:8.8.1'
              annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
          //avi:library
              implementation  'com.wang.avi:library:2.1.3'
          
          //circleimageview
              implementation 'de.hdodenhof:circleimageview:2.2.0'
          
          //retrofit2
              implementation 'com.squareup.retrofit2:retrofit:2.3.0'
              implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
              implementation 'com.squareup.okhttp3:okhttp:3.8.0'
              implementation 'com.jakewharton.retrofit:retrofit1-okhttp3-client:1.0.2'
          
          
          //recyclerview and cardview
              implementation  'com.android.support:recyclerview-v7:27.0.2'
              implementation 'com.android.support:cardview-v7:27.0.2'
          
          
          //ZXing for barCode reader
              implementation  'com.journeyapps:zxing-android-embedded:3.2.0@aar'
              implementation  'com.google.zxing:core:3.2.1'
          
          //play-services
              implementation  'com.google.android.gms:play-services-maps:11.4.0'
          
          //gson
              implementation  'com.google.code.gson:gson:2.8.2'
          //statusbarutil
              implementation  'com.jaeger.statusbarutil:library:1.4.0'
          //glide
              implementation 'com.github.bumptech.glide:glide:4.6.1'
              annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
          //multidex
              implementation 'com.android.support:multidex:1.0.1'
          }
          

          实际上我并不了解它的真正原因以及为什么会突然发生

          所以,如果有人知道,请告诉我详细信息

          我希望这会对你有所帮助

答案 1 :(得分:0)

经过几个小时浪费时间后,这对我有用

就这样做

  

实施>>>的 annotationProcessor