升级Android Studio到3.0后,任务执行失败。

3
当我升级我的Android Studio 3.0时,出现了错误。
unable to merge with dex.

然后我在build.gradle中添加了mutiDexEnabled true,并加入了com.android.support:multidex:1.0.1。但是现在出现了以下错误:

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]))

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'    
}

你尝试过清理项目吗? - Aswin P Ashok
6个回答

1
尝试删除应用程序的构建文件夹,然后进行“清理-重建-运行”项目。如果不起作用,则执行“无效缓存/重启”。祝编码愉快!

0

在添加dependencies时,不需要添加Play服务的jar文件。

请从您的Build.Gradle中移除此部分。

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

比起 清除-重建-运行 你的项目


我已经删除了jar文件,但是它对我没有起作用。我仍然得到相同的错误。 - jasmin
@jasmin请移除这个 implementation files('libs/gcm.jar') 文件。 - AskNilesh

0

尝试以下步骤:

步骤1:删除所有 build 文件夹和 .gradle 文件夹,

步骤2:在你的 gradle.properties 中添加以下代码,

 android.enableAapt2=false

步骤三:然后同步您的安卓项目。


我看不到 gradle.properties 文件。 - jasmin
如果没有,您可以通过在项目上右键单击来创建资源包, 右键单击项目->新建->资源包。然后创建一个名为gradle的文件。您的gradle.properties文件将显示在build.gradle文件的下方。然后在那里编写此代码。 - Aman Gupta - ΔMΔN

0

你不应该使用以 + 结尾的库。你应该指定一个版本。 implementation 'com.google.android.gms:play-services:+' 应该改为

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

然后 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:11.4.2'
    compile 'com.android.support:multidex:1.0.1'    
}

0

如果您没有扩展应用程序类,则仍需要在清单中添加。

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

如果您正在扩展应用程序类,则请按照此链接中的详细信息进行操作:

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

不要使用Jars,直接使用存储库。
不要使用compile,使用implementation。
同时,您需要升级到Android Studio 3.0版本。请确保在根gradle.build中添加了新的存储库:
repositories {
    maven {
        url 'https://maven.google.com'
    }
}

您也可以使用更新的Gradle Wrapper

repositories {
        maven {
            google()
        }
    }

如果您在仓库中使用了数据绑定,请确保已添加。
android {
    ....
    dataBinding {
        enabled = true
    }
}

这是最好的方法。

在你的根级别 gradle.build 中使用以下代码

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
}

在你的gradle-wrapper.properties文件中,将包装器版本更改如下:

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

同时在你的应用级别的 build.gradle 文件中,请确保使用以下 26 版本

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'
        }
    }
}

0

尝试使用buildToolsVersion "26.0.0",然后重新启动Android Studio。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接