在Android Studio 3.0 Beta 2上,执行任务app:transformClassesWithDesugarForDebug失败。

23

我将我的项目从Android Studio 2.3.3迁移到了Android Studio 3.0 Beta 2,现在我的项目无法运行。

在控制台中,我收到以下消息:

Error:Execution failed for task ':app:transformClassesWithDesugarForDebug'.

Got it, I'll try my best to be concise in my answers. Let me know if you need any help!有没有其他东西我需要来使它运行?
我的 gradle 文件如下:
buildscript {
    repositories {
        mavenCentral();
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.22.1'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
        classpath "com.newrelic.agent.android:agent-gradle-plugin:5.9.0"
    }
}

apply plugin: 'com.android.application'
//apply plugin: 'kotlin-android'
apply plugin: 'io.fabric'
apply plugin: 'realm-android'
apply plugin: 'newrelic'

repositories {
    mavenCentral()
    maven { url 'https://maven.fabric.io/public' }
    maven { url "http://dl.bintray.com/glomadrian/maven" }
    maven {
        url "http://nexus.radioafricaplatforms.com/repository/radio-africa-group"
        credentials {
            username "${project.getProperties().ragNexusUsername}"
            password "${project.getProperties().ragNexusPassword}"
        }
    }
}

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.3"

    defaultConfig {
        applicationId "com.radioafrica.music"
        minSdkVersion 19
        targetSdkVersion 25
        renderscriptTargetApi 20
        renderscriptSupportModeEnabled true
        versionCode 74
        versionName "0.9.9"
        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true

        multiDexKeepProguard file("proguard.multidex.config")
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

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

//    retrolambda {
//        jvmArgs '-noverify'
//    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile('io.fabric.sdk.android:fabric:1.3.16@aar') {
        transitive = true;
    }
    compile('com.crashlytics.sdk.android:crashlytics:2.6.7@aar') {
        transitive = true;
    }
    compile 'com.newrelic.agent.android:android-agent:5.9.0'
    compile 'com.android.support:multidex:1.0.2'
    compile 'com.android.support:cardview-v7:25.3.1'
    compile 'com.android.support:recyclerview-v7:25.3.1'
    compile 'com.android.support:palette-v7:25.3.1'
    compile 'com.android.support:design:25.3.1'
    compile 'com.google.android.gms:play-services-location:11.0.4'
    compile 'com.google.code.gson:gson:2.8.1'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'de.hdodenhof:circleimageview:1.3.0'
    compile 'jp.wasabeef:glide-transformations:2.0.1'
    compile 'com.google.android.exoplayer:exoplayer:r2.3.1'
    compile 'uk.co.chrisjenx:calligraphy:2.1.0'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'org.apache.commons:commons-lang3:3.4'
    compile 'com.google.firebase:firebase-core:11.2.0'
    compile 'io.realm:android-adapters:2.1.0'
    compile 'org.parceler:parceler-api:1.1.6'
    compile 'com.jakewharton:butterknife:8.4.0'
    compile 'com.radioafrica.sdk:rag-sdk:0.0.59-SNAPSHOT'
    compile 'com.andrognito.kerningview:kerningview:1.0.0'
    compile 'com.flurry.android:analytics:6.4.2'
    compile 'com.amazonaws:aws-android-sdk-core:2.3.9'
    compile 'com.amazonaws:aws-android-sdk-pinpoint:2.3.9'
    compile 'com.amazonaws:aws-android-sdk-sns:2.3.9'
    compile 'com.google.android.gms:play-services-gcm:11.0.4'
    compile 'com.wdullaer:materialdatetimepicker:3.1.3'
    testCompile 'junit:junit:4.12'
    annotationProcessor 'org.parceler:parceler:1.1.5'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
    compile "com.mixpanel.android:mixpanel-android:5.0.2"
    compile 'com.mani:ThinDownloadManager:1.3.0'
    compile 'com.google.android:flexbox:0.3.0-alpha3'
    compile 'com.airbnb:deeplinkdispatch:3.1.0'
    annotationProcessor 'com.airbnb:deeplinkdispatch-processor:3.1.0'
//    compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.4-2"
}

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

展示你的 build.gradle 文件。 - IntelliJ Amiya
@IntelliJAmiya,请查看更新后的 build.gradle 问题。 - Alex Kombo
2
使用compileSdkVersion 26 buildToolsVersion "26.0.1" - IntelliJ Amiya
我已经更新了我的问题,需要解决方案。 - Dhanu K
刚开始遇到这个问题。 - JPM
我已经通过这篇文章解决了我的问题:https://dev59.com/e67la4cB1Zd3GeqPkNyF - Shivang
7个回答

32

我在一个Ionic Cordova项目中遇到了这个问题

解决方案是清理项目:

cordova clean android

希望这会有所帮助。


1
非常感谢。这个解决方案也适用于ionic构建。 - Andrew Sithole
我尝试了这里的所有解决方案,但都没有起作用 :(。我还使用IONIC。 - Khang Tran

21

错误:任务执行失败:':app:transformClassesWithDesugarForDebug'

com.android.build.api.transform.TransformException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: Error while executing java process with main class com.google.devtools.build.android.desugar.Desugar with arguments

打开你的build.gradle文件并使用以下内容。

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"

然后 Clean-Rebuild-Run


2
自从Android Studio 3.0发布以来,最低所需的 buildToolsVersion26.0.2,但是,在类似的情况下执行 cleanbuild 仍然对我有所帮助,现在一切都正常了。我认为使Android Studio缓存无效会有所帮助,但实际上并没有。 - kit
2
你好,这对我不起作用。 我正在使用Android Studio 3.0.1,请提供任何其他解决方案。 - Jaydip Kalkani
1
重点是将 compileSdkVersionbuildToolVersion 更新到最新版本,然后执行 CleanRebuild - HendraWD
我什么都没改,只是添加了一些新的类和代码,然后就出现了这个错误。我进行了清理重建,但结果仍然相同。问题是我大约1小时前刚构建好,那时候它还是正常的。 - JPM

8

修改您的项目/build.gradle文件

compileOptions {
    //sourceCompatibility JavaVersion.VERSION_1_8
    //targetCompatibility JavaVersion.VERSION_1_8
}

重新构建......好了,我修改了这个文件。重新构建......成功编译apk!希望它能帮到你。


是的,当我注释掉它们时,它可以工作,但问题是我需要使用Java 8。 - Zeyad Assem
同样的问题,从build.gradle中删除Java 1.8后错误消失了。但是有人知道如何启用Java 1.8而不出现问题吗? - avelyne

3
我只是通过删除“build/intermediates”目录来解决了它。

1

在我的情况下,我将源代码兼容性和目标兼容性从1.8改为1.7,然后一切开始正常运行。


0
在我的情况下,所有的compileSdkVersionbuildToolsVersiontargetSdkVersion必须是相同的版本,特别是compileSdkVersion。因为如果你不定义compileSdkVersion,它会自动导入最新版本,所以要小心。

0

我在Flutter项目中遇到了同样的问题。我目前使用的是Android Studio 3.5.2,我按照以下步骤解决了这个问题:

  1. 在项目的build.gradle文件中,我升级到了classpath 'com.android.tools.build:gradle:3.5.4'
  2. 在gradle-wrapper.properties文件中,我升级到了distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip

您可以从这里检查Android Gradle插件版本。


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