Search code examples
android-studiogradleandroid-gradle-pluginbuild.gradleandroid-sdk-tools

Upgrade Gradle version to 8.6 and Gradle plugin version to 8.4.1 make my android studio unable to build release .apk file


after recent update, my android studio make an error:

java.lang.NullPointerException: Cannot invoke "com.android.tools.r8.internal.Gk0.B()" because the return value of "com.android.tools.r8.internal.Jw.b()" is null

and this error avoids build release .apk file.

here is my build.gradle(app):

android {
    namespace '...'
    compileSdk 34

    defaultConfig {
        applicationId '...'
        minSdk 23
        targetSdk 34
        versionCode 11
        versionName '2.1.1'
        vectorDrawables.useSupportLibrary = true
        multiDexEnabled true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

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

    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_18
        targetCompatibility JavaVersion.VERSION_18
    }
    buildFeatures {
        buildConfig true
    }
}

dependencies {
    //some dependencies
}

here's my build.gradle(Project)

plugins {
    id 'com.android.application' version '8.4.1' apply false
    id 'com.android.library' version '8.4.1' apply false
}

I should add I have android.enableR8=true which is depreciated in my gradle.properties file, however change it to true, false or even removing it doesn't change anything.

any idea how to resolve this problem?


Solution

  • After a long research and testing for a day, I found a solution. Adding this to proguard-rules.pro fixed the problem for now:

    -keepclassmembers enum * { *; }
    

    Is it safe to use such a command? If you guys have a better idea, I would appreciated it.