生成签名的APK错误com.android.dex.DexException:多个dex文件定义

时间:2018-02-22 08:23:01

标签: java android gradle apk

生成签名apk时出现此错误,但构建项目没问题

错误:将字节码转换为dex时出错: 原因:com.android.dex.DexException:多个dex文件定义Landroid / support / v4 / accessibilityservice / AccessibilityServiceInfoCompat;

的gradle:

apply plugin: 'com.android.application'

repositories {
    maven {
        url 'https://raw.github.com/71241NW123CK/maven-repo/master'
    }
}

android {
    compileSdkVersion 23
    buildToolsVersion '25.0.0'

    defaultConfig {
        applicationId "com.baclock"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 18
        versionName "2018.02.09"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        incremental false
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'party.treesquaredcode.android:flip-animation:0.0.2'
    compile 'com.mcxiaoke.volley:library:1.0.6'
    compile 'com.google.android.gms:play-services-gcm:8.1.0'
    compile 'com.google.android.gms:play-services:8.1.0'
    compile 'com.evernote:android-job:1.2.4'
}

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

2 个答案:

答案 0 :(得分:0)

在默认配置中添加multiDexEnabled true,然后尝试。

defaultConfig {
        applicationId "com.baclock"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 18
        versionName "2018.02.09"
        multiDexEnabled true
    }

答案 1 :(得分:0)

在defaultConfig块中添加 multiDexEnabled = true

defaultConfig {
        applicationId "com.baclock"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 18
        versionName "2018.02.09"
        multiDexEnabled true
    }