Execution failed for task after updating android studio to 3.0

自闭症网瘾萝莉.ら 提交于 2019-12-12 13:26:52

问题


When I updated my Android Studio 3.0, I get an error

unable to merge with dex.

Then I added mutiDexEnabled true and also added com.android.support:multidex:1.0.1 in build.gradle.

Then I'm getting the error below:

Error:Execution failed for task ':app:transformClassesWithMultidexlistForDebug'. java.io.IOException: Can't write [C:\Users\user\AndroidStudioProjects\KnightFox-IN BUDGET\app\build\intermediates\multi-dex\debug\componentClasses.jar] (Can't read [C:\Users\user.gradle\caches\transforms-1\files-1.1\play-services-ads-lite-11.4.2.aar\9a54afd7907fee993ecc421b66ed4228\jars\classes.jar(;;;;;;**.class)] (Duplicate zip entry [classes.jar:com/google/ads/mediation/MediationServerParameters$Parameter.class]))

build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion '26.0.2'

    defaultConfig {
        applicationId "com.copperseeds.android.kunjachamman.applicationin.budget"
        minSdkVersion 14
        targetSdkVersion 26
        multiDexEnabled true
    }


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

}



dependencies {
    implementation files('libs/ksoap2-android-assembly-2.6.0-jar-with-dependencies.jar')
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    implementation 'com.android.support:appcompat-v7:26.0.0'
    implementation 'com.android.support:support-annotations:26.0.0'
    implementation 'com.android.support:support-v4:26.0.0'
    implementation 'com.github.navasmdc:MaterialDesign:1.5@aar'
    testImplementation 'junit:junit:4.12'
    implementation project(':ORMDroid')
    implementation project(':FacebookSDK')
    implementation project(':standOut')
    implementation files('libs/gcm.jar')
    implementation files('libs/google-play-services.jar')
    implementation 'com.google.android.gms:play-services:+'
    compile 'com.android.support:multidex:1.0.1'    
}

回答1:


Try delete build folder of app than Clean-Rebuild-Run your Project. if not work than do Invalidate Caches/Restart.

Happy coding!!




回答2:


Once try these steps,

Step 1: Delete all the build and the .gradle folder,

Step 2: Add the below code in your gradle.properties,

 android.enableAapt2=false

Step 3: Then Sync your android project.




回答3:


Try buildToolsVersion "26.0.0" and then just restart Android Studio.




回答4:


You don't need to add jar files for Play services when you adding dependencies

remove this from your Build.Gradle

implementation files('libs/google-play-services.jar')

than Clear-Rebuild-Run your Project




回答5:


You should not work with librairies that end with + . You should specify a version. implementation 'com.google.android.gms:play-services:+' should be

implementation 'com.google.android.gms:play-services:11.4.2'

then build.gradle will be :

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion '26.0.2'

    defaultConfig {
        applicationId "com.copperseeds.android.kunjachamman.applicationin.budget"
        minSdkVersion 14
        targetSdkVersion 26
        multiDexEnabled true
    }


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

}



dependencies {
    implementation files('libs/ksoap2-android-assembly-2.6.0-jar-with-dependencies.jar')
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    implementation 'com.android.support:appcompat-v7:26.0.0'
    implementation 'com.android.support:support-annotations:26.0.0'
    implementation 'com.android.support:support-v4:26.0.0'
    implementation 'com.github.navasmdc:MaterialDesign:1.5@aar'
    testImplementation 'junit:junit:4.12'
    implementation project(':ORMDroid')
    implementation project(':FacebookSDK')
    implementation project(':standOut')
    implementation files('libs/gcm.jar')
    implementation files('libs/google-play-services.jar')
    implementation 'com.google.android.gms:play-services:11.4.2'
    compile 'com.android.support:multidex:1.0.1'    
}



回答6:


You need to still add in manifest if you are not extending application class

  <application
            android:name="android.support.multidex.MultiDexApplication" >
        ...
    </application>

If you are extending application class then follow details in this link:

https://developer.android.com/studio/build/multidex.html

Do not use jars, just use the repos directly

do not use compile use implimentation

Also you need to update to Android Studio version 3.0. Also make sure you added the new repo in root gradle.build:

repositories {
    maven {
        url 'https://maven.google.com'
    }
}

You may also use with newer gradle wrapper

repositories {
        maven {
            google()
        }
    }

If you have used data binding in repo then make sure you have added

android {
    ....
    dataBinding {
        enabled = true
    }
}

This is the best way to do it.

In your root level gradle.build use below

buildscript {
    repositories {
        mavenCentral()
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

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

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

and in your gradle-wrapper.properties file change the wrapper version as below

distributionUrl=https\://services.gradle.org/distributions/gradle-4.2.1-all.zip

Also in your app level build.gradle make sure you are using 26 version as below

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"
    defaultConfig {
        applicationId "com.xxxx"
        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'
        }
    }
}


来源:https://stackoverflow.com/questions/47069903/execution-failed-for-task-after-updating-android-studio-to-3-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!