Error when minifying Android app with R8 after upgrading Android Gradle Plugin to 8.0.2
Asked Answered
S

3

10

I recently upgraded the Android Gradle Plugin in my Android app project from version 7.4.2 to 8.0.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:minifyReleaseWithR8
AGPBI: {"kind":"error","text":"Library class android.test.AndroidTestRunner extends program class junit.runner.BaseTestRunner","sources":[{}],"tool":"R8"}
Library class android.test.AndroidTestRunner extends program class junit.runner.BaseTestRunner

AGPBI: {"kind":"error","text":"Library class android.test.InstrumentationTestCase extends program class junit.framework.TestCase","sources":[{}],"tool":"R8"}
Library class android.test.InstrumentationTestCase extends program class junit.framework.TestCase

Task :app:minifyReleaseWithR8 FAILED

The error seems to be related to missing service classes and conflicts between library classes and program classes.

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.0.2? How can I resolve these errors and successfully minify my release build with R8?

Any help or suggestions would be greatly appreciated. Thank you!

Spinoza answered 13/6, 2023 at 7:5 Comment(1)
Same here. That's why I hate to updateChristadelphian
S
3

We fixed the problem by adding

-dontwarn com.squareup.okhttp.CipherSuite
-dontwarn com.squareup.okhttp.ConnectionSpec
-dontwarn com.squareup.okhttp.TlsVersion

to the app/proguard-rules.pro.

It seems like some minification warnings were treated as errors.

Spinoza answered 20/7, 2023 at 6:28 Comment(6)
Can you help me? Please))) I got next message: AGPBI: {"kind":"error","text":"Library class android.net.http.AndroidHttpClient implements program class org.apache.http.client.HttpClient","sources":[{}],"tool":"R8"}Gahnite
Did you try this? #20144744Spinoza
How did you find that these were the sources of the issue?Mendiola
how did you debug which class is causing the issue @SpinozaWhang
Unfortunately I can not remember how exactly we found out that these were the problem. I think we somehow searched which of our dependencies use AndroidTestRunner, BaseTestRunner, InstrumentationTestCase or TestCase. And somewhere we read that warnings are sometimes interpreted as errors. Because of that the -dontwarn suppresses the warning and thus the error.Spinoza
Did you try in runtime to check if the classes weren't really missing?Christadelphian
P
0

I fixed this issue by adding

-dontwarn org.bouncycastle.jsse.BCSSLSocket
-dontwarn org.bouncycastle.jsse.provider.BouncyCastleJsseProvider
-dontwarn org.conscrypt.Conscrypt$Version
-dontwarn org.conscrypt.Conscrypt
-dontwarn org.conscrypt.ConscryptHostnameVerifier
-dontwarn org.joda.convert.FromString
-dontwarn org.joda.convert.ToString
-dontwarn org.openjsse.javax.net.ssl.SSLParameters
-dontwarn org.openjsse.javax.net.ssl.SSLSocket
-dontwarn org.openjsse.net.ssl.OpenJSSE

You can find these in the build/output/mapping/release/missing_rules.txt file. Just copy and paste all the classes with in the missing_rules.txt in progaurd-rules.pro file.

Porta answered 16/8 at 13:2 Comment(0)
C
0

I tried a lot but was unable to find any solution then I tried

flutter build apk --release --verbose

then I found this verbose result

Verbose results

Then I go to this file and copy a rule auto-added in that file

missing_rules.txt

# Please add these rules to your existing keep rules in order to suppress warnings.
# This is generated automatically by the Android Gradle plugin.
-dontwarn com.google.devtools.build.android.desugar.runtime.ThrowableExtension

copy the rule

-dontwarn com.google.devtools.build.android.desugar.runtime.ThrowableExtension

and added in app/proguard-rules.pro

-dontwarn com.google.devtools.build.android.desugar.runtime.ThrowableExtension

It worked for me I hope it will be helpful.

Clinquant answered 20/8 at 20:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.