该应用程序在连接的设备上工作正常,但当我尝试构建其apk时显示错误

时间:2018-01-21 17:29:17

标签: java android android-studio

当我尝试在连接的设备或模拟器上运行它时没有错误但是,当我尝试构建其apk文件时,它会产生此错误。如果你在这里发现任何错误的线索,请帮帮我。谢谢

错误是:

  

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

build.gradle是:

apply plugin: 'com.android.application'

android {
compileSdkVersion 26
defaultConfig {
    applicationId "com.example.ihtesham.demoapp"
    minSdkVersion 16
    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'
        multiDexEnabled true
    }

}

}

dependencies {

implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:26.1.0'



androidTestImplementation 'com.android.support.test:runner:1.0.1'   //1.0.1
androidTestImplementation 'com.android.support.test.espresso:espresso-
core:3.0.1'

//Adding libraries


implementation 'com.github.glomadrian:MaterialAnimatedSwitch:1.1@aar'
implementation 'com.firebaseui:firebase-ui-auth:3.1.3'
implementation 'com.firebase:geofire-android:2.1.2'
implementation 'com.github.d-max:spots-dialog:0.7@aar'
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'uk.co.chrisjenx:calligraphy:2.3.0'
implementation 'com.rengwuxian.materialedittext:library:2.1.4'
implementation 'com.android.support:design:26.1.0'   // 26.1.0
implementation 'com.android.support:cardview-v7:26.1.0'
implementation 'com.google.firebase:firebase-database:11.8.0'  //11.8.0
implementation 'com.google.firebase:firebase-auth:11.8.0'
implementation 'com.google.android.gms:play-services-maps:11.8.0'
implementation 'com.google.android.gms:play-services:11.8.0'
implementation 'com.google.android.gms:play-services-auth:11.8.0'  //11.4.2
testImplementation 'junit:junit:4.12'//11.8.0
}

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

项目的build.gradle是:

buildscript {

repositories {
    google()
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.0.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 {
    google()
    jcenter()
        maven{
            url 'https://maven.google.com'
        }
    maven{
        url 'https://dl.bintray.com/glomadrian/maven'
    }
}
}

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

1 个答案:

答案 0 :(得分:0)

remove

multiDexEnabled true

Or do it

multiDexEnabled false

from your project's build.gradle because the exception you are facing is telling something about not being able to compile the dex code.

after removing that line or doing it false try to CLEAN and then ->REBUILD and go for buildapk.

if you are going for releasing your apk then you have to do some more amends in your application's build.gradle like this

buildTypes {

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

in your program-rules pro file you have to put these lines too its good practice well to me actually

-keep class * {
public private *;
}

if that does not work! keep the multidexEnabled true and add this in your project dependencies

implementation 'com.android.support:multidex:1.0.2'