Error when minifying Android app with R8 after upgrading Android Gradle Plugin to 8.2.2
Asked Answered
I

1

7

I recently upgraded the Android Gradle Plugin in my Android app project from version 7.4.2 to 8.2.2. However, I'm now encountering an error during the release build when the minifyReleaseWithR8 task is executed.

The error message I'm getting is as follows:

Task :app:minifyKioskDebugWithR8 FAILED AGPBI: {"kind":"error","text":"com.android.tools.r8.ResourceException: com.android.tools.r8.internal.vc: I/O exception while reading '/Users/harinikesh/StudioProjects/instore/app/build/intermediates/merged_java_res/kioskDebug/base.jar': /Users/harinikesh/StudioProjects/instore/app/build/intermediates/merged_java_res/kioskDebug/base.jar","sources":[{"file":"/Users/harinikesh/StudioProjects/instore/app/build/intermediates/merged_java_res/kioskDebug/base.jar"}],"tool":"R8"} com.android.tools.r8.ResourceException: com.android.tools.r8.internal.vc: I/O exception while reading '/Users/harinikesh/StudioProjects/instore/app/build/intermediates/merged_java_res/kioskRelease/base.jar': /Users/harinikesh/StudioProjects/instore/app/build/intermediates/merged_java_res/kioskRelease/base.jar

I got this error while generating the release build with

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

I tried making the shrinkResources and minifyEnabled to false, Build got successful.

These errors only started occurring after I updated the Android Gradle Plugin. I've tried cleaning the project and ensuring that all dependencies are up to date, but the issue persists.

Has anyone else encountered a similar issue when upgrading to Android Gradle Plugin 8.2.2? How can I resolve these errors and successfully minify my release build with R8?

Included answered 20/2 at 11:0 Comment(6)
Related issue but different - #76462910Included
I suggest that you file an issue with Android Studio, see developer.android.com/studio/report-bugs. To help the process please include the full stacktrace from running ./gradlew --stacktrace :app:minifyReleaseWithR8.Cutcherry
@HariNikeshR ever found solution?Ruhr
Removing the tasks.whenTaskAdded {} It worked fine. But with it, still shows the same error.Included
Still finding this issue and I dont use whenTaskAdded anywhere.Marindamarinduque
@Marindamarinduque were you able to fix this?Fields
M
4

Removing app bundle renaming logic in build.gradle may resolve the issue.

We were getting the exact same error. After viewing the stacktrace by using ./gradlew --stacktrace :app:minifyReleaseWithR8 as suggested by sgjesse we realized the error was happening because a file was not found during the build process.

Within our app build.gradle file we have a tasks.whenTaskAdded { closure that renames the bundle when we create a build. Within this closure a file is renamed/moved. After removing this renaming logic from our build.gradle file the error was resolved.

Note that I'm sure it's possible to correct the renaming logic. In our case we did not need it and decided to remove.

Manos answered 6/3 at 21:57 Comment(3)
Removing tasks.whenTaskAdded {} block solved the issue! I had that block to run unit tests automatically before any build. Now I need to find another solution for that.Freetown
Thanks, this fixed an issue for us as well.Elvieelvin
Thanks it worked. But anything that you suggest to rectify with the same taskIncluded

© 2022 - 2024 — McMap. All rights reserved.