Android R8无法找到方法

Android R8无法找到方法,android,android-gradle-plugin,android-r8,Android,Android Gradle Plugin,Android R8,我有两个问题。我无法以任何方式构建发布apk。当我禁用R8(首选proguard)时,构建将永远继续(有时会崩溃,引用“内存不足:java堆空间”),当我启用R8时,会出现以下错误: Unable to find method 'com.android.tools.r8.CompatProguardCommandBuilder.setProguardSeedsConsumer(Lcom/android/tools/r8/StringConsumer;)Lcom/android/tools/r8/

我有两个问题。我无法以任何方式构建发布apk。当我禁用R8(首选proguard)时,构建将永远继续(有时会崩溃,引用“内存不足:java堆空间”),当我启用R8时,会出现以下错误:

Unable to find method 'com.android.tools.r8.CompatProguardCommandBuilder.setProguardSeedsConsumer(Lcom/android/tools/r8/StringConsumer;)Lcom/android/tools/r8/R8Command$Builder;'.
我的项目级build.gradle:

buildscript {
    repositories {
        google()
        mavenLocal()
        jcenter()
        maven { url "https://maven.google.com" }
        maven { url 'http://storage.googleapis.com/r8-releases/raw' }
    }
    dependencies {
        classpath 'com.android.tools:r8:1.5.68'
        classpath 'com.android.tools.build:gradle:3.6.0-alpha09'
        classpath 'com.google.gms:google-services:4.3.1'
        classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:4.7.3'
    }
}

allprojects {
    tasks.withType(JavaCompile) {
        options.compilerArgs << "-Xlint:deprecation" << "-Xlint:unchecked"
    }
    repositories {
        google()
        mavenLocal()
        jcenter()
        maven { url "https://maven.google.com" }
    }
    apply plugin: "com.jfrog.artifactory"
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
apply plugin: 'com.android.application'

android {
    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/DEPENDENCIES'
    }

    compileSdkVersion 29
    buildToolsVersion '29.0.2'
    defaultConfig {
        applicationId "XXX"
        minSdkVersion 19
        targetSdkVersion 29
        vectorDrawables.useSupportLibrary = true
        signingConfig signingConfigs.release
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles 'proguard.cfg'
        }
    }
    productFlavors {}
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    lintOptions {
        ignoreWarnings true       // false by default
        quiet true                // false by default
        abortOnError false
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }
}

dependencies {
    api project(':Tableview')

    implementation 'com.diogobernardino:williamchart:2.5.0'
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation 'com.squareup.okhttp3:okhttp:4.1.0'
    implementation 'com.squareup.okio:okio:2.4.0'
    implementation 'com.google.android.material:material:1.1.0-alpha09'
    implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
    implementation 'androidx.recyclerview:recyclerview:1.1.0-beta03'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.emoji:emoji:1.0.0'
    implementation 'androidx.exifinterface:exifinterface:1.0.0'
    implementation 'androidx.media:media:1.1.0-rc01'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.google.android.gms:play-services-location:17.0.0'
    implementation 'com.google.android.gms:play-services-maps:17.0.0'
    implementation 'com.google.android.gms:play-services-gcm:17.0.0'
    implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'com.fasterxml.jackson.core:jackson-core:2.10.0.pr1'
    implementation 'com.fasterxml.jackson.core:jackson-annotations:2.10.0.pr1'
    implementation 'com.fasterxml.jackson.core:jackson-databind:2.10.0.pr1'
    implementation 'commons-io:commons-io:2.6'
    implementation 'org.apache.commons:commons-lang3:3.9'
    implementation 'org.apache.commons:commons-text:1.6'
    implementation 'petrov.kristiyan:colorpicker-library:1.1.10'
    implementation 'com.google.android.libraries.places:places:2.0.0'
}
apply plugin: 'com.google.gms.google-services'
gradle.properties:

android.enableJetifier=true
artifactory_user=admin
android.useAndroidX=true
android.enableBuildCache=true
org.gradle.jvmargs=-Xmx1g

jvmargs和dexOptions堆大小都是为了解决“java堆空间”问题而放在那里的,但他们没有解决。

删除
classpath'com.android.tools:r8:1.5.68'
应该可以解决这个问题,因为这将使android Gradle插件使用内置的r8版本


问题是您正在使用R8发行版1.5.68(
classpath'com.android.tools:R8:1.5.68'
)以及android Gradle插件版本3.6.0-alpha09(
classpath'com.android.tools.build:Gradle:3.6.0-alpha09'
)。缺失的API是在R8()的1.6.x版中引入的。

就是这样!非常感谢你!升级到AndroidStudio 3.6.1/Gradle 5.6.4后,这里也一样。这个解决方案对我也有效。谢谢