无法合并 dex [英] Unable to merge dex

查看:45
本文介绍了无法合并 dex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 Android Studio 测试版.我通过编译旧模块创建了一个新项目,但是当我尝试启动该应用程序时,它没有启动并显示以下消息:

错误:任务':app:transformDexArchiveWithExternalLibsDexMergerForDebug'的执行失败.

<块引用>

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

但是我不知道如何解决这个错误.我用谷歌搜索了几个小时,但没有成功.

我的项目gradle:

//顶级构建文件,您可以在其中添加所有子项目/模块通用的配置选项.构建脚本{存储库{jcenter()谷歌()}依赖{类路径 'com.android.tools.build:gradle:3.0.0-beta6'类路径io.realm:realm-gradle-plugin:3.7.1"类路径 'com.google.gms:google-services:3.1.0'//注意:不要将您的应用程序依赖项放在这里;他们属于//在单独的模块 build.gradle 文件中}}所有项目{存储库{jcenter()谷歌()}}任务清理(类型:删除){删除 rootProject.buildDir}

我的应用程序gradle:

 应用插件:'com.android.application'安卓 {compileSdkVersion 26构建工具版本26.0.1"默认配置{applicationId "parad0x.sk.onlyforyou"minSdk 版本 21目标SDK版本26版本代码 1版本名称1.0"testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"multiDexEnabled true}构建类型{释放 {minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'}调试{}}编译选项{目标兼容性 1.7源兼容性 1.7}包装选项{排除元信息/许可证"排除元信息/通知"}lintOptions {checkReleaseBuilds false}产品风味{}}依赖{编译文件树(包括:['*.jar'],目录:'libs')androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {排除组:'com.android.support',模块:'support-annotations'})//不检查GradleCompatible编译'com.android.support:appcompat-v7:26.0.0-alpha1'编译项目(路径:':loginregisterview')}

还有我的模块gradle:

 应用插件:'com.android.library'应用插件:'realm-android'安卓 {compileSdkVersion 26构建工具版本26.0.1"默认配置{minSdk 版本 19目标SDK版本26版本代码 1版本名称1.0"testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"}构建类型{释放 {minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'}}}依赖{编译文件树(目录:'libs',包括:['*.jar'])androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {排除组:'com.android.support',模块:'support-annotations'})编译'com.android.support:appcompat-v7:26.0.2'编译'com.android.support:support-v4:26.1.0'编译'com.github.bumptech.glide:glide:4.0.0'testCompile 'junit:junit:4.12'编译项目(路径:':parser')}

我的第二个模块:

 应用插件:'com.android.library'应用插件:'realm-android'安卓 {compileSdkVersion 26构建工具版本26.0.1"默认配置{minSdk 版本 14目标SDK版本23版本代码 1版本名称1.0"testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"}领域{同步启用 = 真}useLibrary 'org.apache.http.legacy'构建类型{释放 {minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'}}产品风味{}}依赖{编译文件树(目录:'libs',包括:['*.jar'])androidTestCompile 'junit:junit:4.12'//编译 'com.android.support:appcompat-v7:23.1.0'//编译 'com.fasterxml.jackson.core:jackson-core:2.9.0'//编译 'com.fasterxml.jackson.core:jackson-annotations:2.9.0'//编译 'com.fasterxml.jackson.core:jackson-databind:2.9.0'编译'com.google.code.gson:gson:2.6.2'}

____________发现_________

当我没有导入第二个模块(解析器)时,应用程序不会在 dex 上崩溃,但是当模块未被导入时,应用程序无法运行.:D :D

解决方案

我尝试了以上所有方法,但都没有帮助.最后,我找到了适合我的工作:

app/build.gradle:

android {默认配置{multiDexEnabled true}}

I have 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

But I don't know how to solve this error. I googled this for hours but with no success.

My project 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:

    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:

    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. :D :D

解决方案

I tried all the above and none of them helps. finally, I find this work for me:

app/build.gradle:

android {
    defaultConfig {
       multiDexEnabled true
    }
}

这篇关于无法合并 dex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆