构建失败 - “无法合并Dex”

时间:2017-11-22 10:01:45

标签: android react-native react-native-android

以下是应用级别中build.gradle的片段:

android {
    compileSdkVersion 23
    buildToolsVersion "26.0.2"

    defaultConfig {
        applicationId "com.miniProject"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }

        vectorDrawables.useSupportLibrary = true
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false
            include "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    applicationVariants.all { variant ->
        variant.outputs.each { output ->    
            def versionCodes = ["armeabi-v7a":1, "x86":2]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }
}

及其依赖项:

dependencies {
    compile project(':react-native-android-location-services-dialog-box')
    compile project(':react-native-image-crop-picker')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:+"  // From node_modules
}

我已经在项目级build.gradle上添加了google()。我之前在SDK工具中安装了google play服务并添加了

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

到依赖项。我卸载了google play服务并删除了依赖项中的播放服务,将其还原到其工作副本,但现在它提示错误“无法合并dex'”。我该怎么办?

1 个答案:

答案 0 :(得分:1)

the problem happening due to Over 64K Methods (https://developer.android.com/studio/build/multidex.html)   

dependencies {
        compile project(':react-native-android-location-services-dialog-box')
        compile project(':react-native-image-crop-picker')
        compile fileTree(dir: "libs", include: ["*.jar"])
        compile "com.android.support:appcompat-v7:23.0.1"
        compile 'com.android.support:multidex:1.0.0'   ///add this line
        compile "com.facebook.react:react-native:+"  // From node_modules
    }

    =======
     defaultConfig {
            applicationId "com.miniProject"
            minSdkVersion 16
            targetSdkVersion 23
            multiDexEnabled true  ///add this line
            versionCode 1
            versionName "1.0"
            ndk {
                abiFilters "armeabi-v7a", "x86"
            }

            vectorDrawables.useSupportLibrary = true
        }