Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android R8 Unable to find method

I have two problems. I am unable to build a release apk either way. When I disable R8 (preferring proguard), the build just goes on forever (sometimes crashing, citing 'out of memory: java heap space'), and when I enable R8, I get the following error:

Unable to find method 'com.android.tools.r8.CompatProguardCommandBuilder.setProguardSeedsConsumer(Lcom/android/tools/r8/StringConsumer;)Lcom/android/tools/r8/R8Command$Builder;'.

My project level 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
}

And my project module 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

Both the jvmargs and dexOptions heap size were put there as an attempt to fix the 'java heap space' problem, which they did not.

like image 620
S Fitz Avatar asked Sep 04 '19 09:09

S Fitz


1 Answers

Removing the line classpath 'com.android.tools:r8:1.5.68' should solve the problem, as that will make the Android Gradle Plugin use the version of R8 which it has built-in.

The issue is that you are using an R8 distribution version 1.5.68 (classpath 'com.android.tools:r8:1.5.68') together with the Android Gradle Plugin version 3.6.0-alpha09 (classpath 'com.android.tools.build:gradle:3.6.0-alpha09'). The API that is missing was introduced in version 1.6.x of R8 (this CL).

like image 114
sgjesse Avatar answered Sep 27 '22 22:09

sgjesse