androidflutterdartgradle

ERROR: Missing classes detected while running R8


ERROR: Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in ...\build\app\outputs\mapping\release\
missing_rules.txt.
ERROR: R8: Missing class com.android.org.conscrypt.SSLParametersImpl (referenced from: void org.conscrypt.KitKatPlatformOpenSSLSocketImplAdapter.<init>(org.conscrypt.AbstractConscryptSocket))
Missing class javax.annotation.Nullable (referenced from: okhttp3.CertificatePinner okhttp3.Address.certificatePinner and 116 other contexts)
Missing class org.apache.harmony.xnet.provider.jsse.SSLParametersImpl (referenced from: void org.conscrypt.PreKitKatPlatformOpenSSLSocketImplAdapter.<init>(org.conscrypt.AbstractConscryptSocket))

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:minifyReleaseWithR8'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.R8Task$R8Runnable
   > Compilation failed to complete

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 3m 8s
Running Gradle task 'assembleRelease'...                          189.3s
Gradle task assembleRelease failed with exit code 1

I have only tried flutter clean and rebuild the project

Note: Debug apk is generated but while i am create a release one this issue encounters

recently i upgraded my flutter version to 3.24


Solution

  • You have encountered missing classes exception when using the R8 shrinker in your release build. R8 is trying to optimize the code, but it can't find certain classes (e.g., com.android.org.conscrypt.SSLParametersImpl, javax.annotation.Nullable, and org.apache.harmony.xnet.provider.jsse.SSLParametersImpl) that are being referenced in your code or libraries, causing the build to fail.

    Method 1:

    Add Keep Rules in Proguard/R8 Config

    -keep class com.android.org.conscrypt.** { *; }
    -keep class javax.annotation.** { *; }
    -keep class org.apache.harmony.xnet.provider.jsse.** { *; }
    

    Method 2: (Not recommended)

    You can disable R8 minification in your gradle file by

    buildTypes {
        release {
            minifyEnabled false
            shrinkResources false
        }
    }
    

    This method is not recommended, cause it doesn't obfuscation the code.