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

2

7

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?

Nixon answered 2/6 at 8:9 Comment(3)
Any success with this? I am facing the same issue as wellVariate
so it's not just me? is it some kind of bug?Nixon
The issue seems to be in ucrop library itself: github.com/Yalantis/uCrop/issues/914Jollanta
N
2

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.

Nixon answered 6/6 at 21:33 Comment(2)
I'm curious why do you know enum is the root cause of R8 failure? :thinkSwamper
Just added this line and problem got fixed. Not sure how but i searched Stack a lot and used a lot of commands and code snips and this one worked.Nixon
J
0

That is an issue with uCrop library. Instead of @Ashile solution which keeps all enum classes, you can use this more specific rule

-keep class com.yalantis.ucrop.util.RectUtils { *; }

You can find more info here: https://github.com/Yalantis/uCrop/issues/914

Jollanta answered 7/8 at 2:6 Comment(4)
I didn't use this library and I had this error. But i can confirm some bug exist in new version. after the update i had the error and not before that.Nixon
In the screenshot you demonstrated in the question, there was jetified-ucrop-2.2.6-runtime.jar so it seems you are using it or a library you are using is using it under the hood. Correct me if I am wrong.Jollanta
I used this library github.com/Dhaval2404/ImagePicker and when I opened yours, they are very similar in action. maybe they inherit from each other?Nixon
Yes, this library uses uCrop under the hood. See implementation 'com.github.yalantis:ucrop:2.2.6' at line 52 on github.com/Dhaval2404/ImagePicker/blob/master/…Jollanta

© 2022 - 2024 — McMap. All rights reserved.