无法合并dex

本文翻译自:Unable to merge dex

I have Android Studio Beta. 我有Android Studio Beta。 I created a new project with compile my old modules but when I tried launching the app it did not launch with the message: 我使用编译旧模块创建了一个新项目,但是当我尝试启动该应用程序时,它并没有显示以下消息:

Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.

com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex com.android.builder.dexing.DexArchiveMergerException:无法合并dex

But I don't know how to solve this error. 但是我不知道如何解决这个错误。 I googled this for hours but with no success. 我用谷歌搜索了几个小时,但没有成功。

My project gradle: 我的项目gradle:

    // Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-beta6'
        classpath "io.realm:realm-gradle-plugin:3.7.1"
        classpath 'com.google.gms:google-services:3.1.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

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

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

My app gradle: 我的应用程式gradle:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "parad0x.sk.onlyforyou"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
        }
    }
    compileOptions {
        targetCompatibility 1.7
        sourceCompatibility 1.7
    }
    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
    }
    lintOptions {
        checkReleaseBuilds false
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    //noinspection GradleCompatible
    compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
    compile project(path: ':loginregisterview')


}

And my module gradle: 和我的模块gradle:

    apply plugin: 'com.android.library'
apply plugin: 'realm-android'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.0.2'
    compile 'com.android.support:support-v4:26.1.0'
    compile 'com.github.bumptech.glide:glide:4.0.0'
    testCompile 'junit:junit:4.12'
    compile project(path: ':parser')

}

My second module: 我的第二个模块:

     apply plugin: 'com.android.library'
apply plugin: 'realm-android'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }

    realm {
        syncEnabled = true
    }
    useLibrary 'org.apache.http.legacy'

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile 'junit:junit:4.12'
    //  compile 'com.android.support:appcompat-v7:23.1.0'

    //   compile 'com.fasterxml.jackson.core:jackson-core:2.9.0'
 //   compile 'com.fasterxml.jackson.core:jackson-annotations:2.9.0'
 //   compile 'com.fasterxml.jackson.core:jackson-databind:2.9.0'
    compile 'com.google.code.gson:gson:2.6.2'
}

____________finding_________ ____________发现_________

When I did not import the second module (parser) the app did not crash on dex but when the module was not imported app did not work. 当我不导入第二个模块(解析器)时,该应用程序在dex上没有崩溃,但是当该模块未导入时,应用程序无法正常工作。 :D :D :D:D


#1楼

参考:https://stackoom.com/question/388Jx/无法合并dex


#2楼

  1. Delete the .gradle directory. 删除.gradle目录。

  2. Run your app again. 再次运行您的应用程序。

Notes 笔记

  • The .gradle directory is in your project's root folder. .gradle目录位于项目的根文件夹中。 (You may have to show hidden files first.) (您可能必须先显示隐藏的文件。)
  • I have to do this every time I update a dependency module using Android 3.0. 每次我使用Android 3.0更新依赖项模块时,都必须执行此操作。 (More recent releases of Android Studio 3 seem to have resolved the problem.) (Android Studio 3的最新版本似乎已解决了该问题。)

#3楼

Deleting .gradle as suggested by Suragch wasn't enough for me. .gradle建议删除.gradle对我来说还不够。 Additionally, I had to perform a Build > Clean Project . 此外,我还必须执行Build > Clean Project

Note that, in order to see .gradle , you need to switch to the "Project" view in the navigator on the top left: 请注意,为了查看.gradle ,您需要在左上方的导航器中切换到“项目”视图:

切换至专案检视


#4楼

I had the same problem when I update from com.google.android.gms:play-services:11.2.2 to com.google.android.gms:play-services:11.4.0 . com.google.android.gms:play-services:11.2.2com.google.android.gms:play-services:11.4.0时,我遇到了同样的问题。 This solved it for me: 这为我解决了:

  1. clean 清洁
  2. rebuild 重建

#5楼

I agree with Chris-Jr. 我同意小克里斯。 If you are using Firebase to embed your AdMob ads (or even if you are not) the play-services-analytics includes the play-services-ads even though you don't add that as a dependency. 如果您使用Firebase嵌入AdMob广告(即使不是,也可以),则即使您没有将play-services广告添加为依赖项,play-services-analytics也包含play-services-ads。 Google have obviously made a mistake in their 11.4.0 roll-out as the analytics is including version 10.0.1 of ads, not 11.4.0 (the mouse over hint in the gradle shows this). Google显然在其11.4.0的推出过程中犯了一个错误,因为分析包括的是10.0.1版的广告,而不是11.4.0版(gradle中的鼠标悬停提示显示了这一点)。

I manually added compile 'com.google.android.gms:play-services-ads:11.4.0' at the top which worked, but only after I disabled Instant Run: http://stackoverflow.com/a/35169716/530047 我在顶部手动添加了编译'com.google.android.gms:play-services-ads:11.4.0' ,但是只有在禁用即时运行后,该命令才起作用: http ://stackoverflow.com/a/35169716/530047

So its either regress to 10.0.1 or add the ads and disable Instant Run. 因此,它要么退回到10.0.1,要么添加广告并禁用“即时运行”。 That's what I found if it helps any. 这就是我发现的有帮助的地方。


#6楼

If this error appeared for you after including kotlin support, and none of the other solutions work, try changing the kotlin dependency of app module's build.gradle to: 如果在包含Kotlin支持后为您出现了此错误,并且没有其他解决方案起作用,请尝试将应用程序模块的build.gradle的kotlin依赖项build.gradle为:

implementation ("org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version") {
    exclude group: 'org.jetbrains', module: 'annotations'
}

This works for me on Android Studio 3.0 Beta 6. See this answer for further explanation. 这对我在Android Studio 3.0 Beta 6上有效。请参阅答案以获取进一步的说明。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值