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

还有我的项目模块 build.gradle:
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 版 (this CL) 中引入的。

关于Android R8 找不到方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57785507/

相关文章:

android - 资源收缩器不能用于多 apk 应用程序

android - 使用代码压缩器 R8 使用 Android Studio 3.4 构建时出现内存不足问题

android - Pjsua 2 android创建具有相同sip号码但不同ip地址的帐户

android - javaMaxHeapSize 与安卓 :largeHeap

android - 将新的 Android 项目添加到 fork 的 repo

java - 错误 :Execution failed for task ':app:transformClassesWithDexForDebug'

android-studio - 从 Eclipse 到 Android Studio : Why is proguard. cfg 在不构建版本时使用?

android - Sentry 的 Gradle 任务未编译

java - appium如何从图库中选择照片

java - 谷歌地图,基于纬度/经度值绘制标记