Proguard Missing classes detected while running R8 after adding package names in proguard-rules.pro
Asked Answered
P

16

74

AGPBI gives this as output:

> Task :app:minifyReleaseWithR8
AGPBI: {"kind":"warning","text":"Unexpected reference to missing service class: META-INF/services/reactor.blockhound.integration.BlockHoundIntegration.","sources":[{"file":"/app/build/intermediates/merged_java_res/release/base.jar"}],"tool":"R8"}

AGPBI: {"kind":"warning","text":"Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in /app/build/outputs/mapping/release/missing_rules.txt.\n","sources":[{}]}

AGPBI: {"kind":"warning","text":"Missing class com.aayushatharva.brotli4j.Brotli4jLoader (referenced from: void io.netty.handler.codec.compression.Brotli.<clinit>() and 2 other contexts)\n

Missing class com.aayushatharva.brotli4j.decoder.DecoderJNI$Status (referenced from: void io.netty.handler.codec.compression.BrotliDecoder$1.<clinit>() and 1 other context)\n
Missing class com.aayushatharva.brotli4j.decoder.DecoderJNI$Wrapper (referenced from: com.aayushatharva.brotli4j.decoder.DecoderJNI$Wrapper io.netty.handler.codec.compression.BrotliDecoder.decoder and 4 other contexts)\n
Missing class com.aayushatharva.brotli4j.encoder.Encoder$Mode (referenced from: void io.netty.handler.codec.compression.BrotliOptions.<clinit>())\n
Missing class com.aayushatharva.brotli4j.encoder.Encoder$Parameters (referenced from: com.aayushatharva.brotli4j.encoder.Encoder$Parameters io.netty.handler.codec.compression.BrotliEncoder.parameters and 7 other contexts)\n
Missing class com.aayushatharva.brotli4j.encoder.Encoder (referenced from: io.netty.buffer.ByteBuf io.netty.handler.codec.compression.BrotliEncoder.allocateBuffer(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, boolean))\n
Missing class com.android.org.conscrypt.SSLParametersImpl (referenced from: void org.conscrypt.KitKatPlatformOpenSSLSocketImplAdapter.<init>(org.conscrypt.AbstractConscryptSocket))\n
Missing class com.github.luben.zstd.Zstd (referenced from: io.netty.buffer.ByteBuf io.netty.handler.codec.compression.ZstdEncoder.allocateBuffer(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, boolean) and 1 other context)\n
Missing class com.google.protobuf.ExtensionRegistry (referenced from: void io.netty.handler.codec.protobuf.ProtobufDecoder.<init>(com.google.protobuf.MessageLite, com.google.protobuf.ExtensionRegistry))\n
Missing class com.google.protobuf.ExtensionRegistryLite (referenced from: com.google.protobuf.ExtensionRegistryLite io.netty.handler.codec.protobuf.ProtobufDecoder.extensionRegistry and 2 other contexts)\n

The missing files seem to be part of the bouncycastle library. Here is my proguard file:

-keep class org.spongycastle.** { *; }
-dontwarn org.spongycastle.**

# When I remove this, java.security.cert.CertificateException: X.509 not found is thrown
-keep class org.bouncycastle.** { *; }
-keep interface org.bouncycastle.**

# I got the missing classes from missing_rules.txt and added the package names that created the problem here:
-keep class org.conscrypt.** { *; }
-keep class io.netty.** { *; }

-keep class com.aayushatharva.** { *; }

-keep class ** { *; }

build.gradle (app):

implementation "org.conscrypt:conscrypt-android:$conscrypt"
implementation 'org.bouncycastle:bcprov-jdk15on:1.69'
implementation 'org.bouncycastle:bcpkix-jdk15on:1.69'

Why does it still gives the error while I add the correct missing package names?

Pademelon answered 19/11, 2021 at 15:51 Comment(0)
C
155

I upgrade gradle to 8.0 when i package my app I get the same problem.

this is the error message

Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in your path to missing_rules.txt

I follow the path to missing_rules.txt like this

app -> build -> outputs -> mapping -> your_app_name -> missing_rules.txt

I get those message

# Please add these rules to your existing keep rules in order to 
  suppress warnings.
# This is generated automatically by the Android Gradle plugin.
-dontwarn android.os.ServiceManager*
-dontwarn com.bun.miitmdid.core.MdidSdkHelper*
-dontwarn com.bun.miitmdid.interfaces.IIdentifierListener*
-dontwarn com.bun.miitmdid.interfaces.IdSupplier*
-dontwarn com.google.firebase.iid.FirebaseInstanceId*
-dontwarn com.google.firebase.iid.InstanceIdResult*
-dontwarn com.huawei.hms.ads.identifier.AdvertisingIdClient$Info*
-dontwarn com.huawei.hms.ads.identifier.AdvertisingIdClient*
-dontwarn com.tencent.android.tpush.otherpush.OtherPushClient*

I copy those messages into proguard-rules.pro then i fix this problem.

Creator answered 8/5, 2023 at 14:3 Comment(13)
I added these as directed above, they were underlined in red with "unresolved class name", regardless the problem went away :) -dontwarn javax.annotation.Nullable -dontwarn javax.annotation.ParametersAreNonnullByDefault -dontwarn javax.annotation.WillClosePhytology
@mick yes, I get the as seam warnings as yours, i don't why. but it's working.Creator
Is this safe though? We just suppressed the warnings here, not fixing the real problemFirkin
Is it safe? It seems to me that there are a lot of hidden problems in the Android Studio software. They pop up from time to time, each responder has a different solution unrelated to the other solutions, they usually involve invalidate caches or whatever arbitrary things we come up with, like the infamous red R problem, that I get once a year, ... Anyway, if the problem goes away we can get on with our day - until the next one bites.Phytology
this works 2023Trinidad
@Phytology I know this will get a few warnings, if you add * to the end. the warnings will go. -dontwarn android.os.ServiceManager* -dontwarn com.bun.miitmdid.core.MdidSdkHelper* -dontwarn com.bun.miitmdid.interfaces.IIdentifierListener* -dontwarn com.bun.miitmdid.interfaces.IdSupplier*Creator
this is not safe 2023. missing_rules.txt had some classes related to our payment SDK, when we applied payment realted features were not working. So simply applying rules from missing_rules.txt to proguard-rules.pro will not solve actual problem.Cila
Even if this fixes the issue, could someone explain why this issue is happening now? Suppressing warnings does not seem to be all that safe or correct.Chi
I made a minor change to the code by using com.google.android.material.R.color.material_on_primary_emphasis_high_type, then I could not build the app due to this "Unexpected reference" error. The missing_rules.txt file suggests adding "-dontwarn com.google.android.material.R$color". It works.Doncaster
Docs: developer.android.com/build/releases/past-releases/…Henni
If you are wondering like me where is proguard-rules.pro file then it should be in android/app folder. If there is no such file then you should create oneOneill
This allows the project to compile but if I install the APK on a device and run the app I get a NoClassDefFoundError error.Stigmatism
as github discussion stated that some classes are safe to ignore.Felting
L
25

The missing classes warning tells that the mentioned classes are not present in the input (your source and dependencies) or in the referenced library (Android runtime library android.jar provided form the Platfrom SDK in this case). When R8 traces the program it will try to handle all the classes, methods and fields that it finds in the part of the program it considers live. Keeping all classes in a package will not change that. There are two options in this case:

  1. Find the missing dependency and add it to the project
  2. Ignore the warning using a -dontwarn as the class is expected to be missing.

For the warning on the class com.android.org.conscrypt.SSLParametersImpl adding a

-dontwarn com.android.org.conscrypt.SSLParametersImpl`

is the right thing to do, as looking at the source shows that the class extends a class which will be in the KitKat runtime, but not in the app (and also not in android.jar).

For the remaining warnings a similar decision has to be made.

Leander answered 22/11, 2021 at 7:57 Comment(2)
Opened github.com/google/conscrypt/pull/1046 to address some of these.Leander
I added lombok to libgdx in this way project(":android") { apply plugin: "com.android.application" configurations { natives } dependencies { api "org.projectlombok:lombok:$lombokVersion" } }Onshore
S
16

Not directly OP's issue, but if you find R8 failing your builds about missing rules and you're using an older version of OkHttp, you can upgrade OkHttp to 4.11.0 for the necessary Proguard rules instead of adding them to your project.

Systemize answered 6/6, 2023 at 9:30 Comment(3)
The OP doesn´t use OkHttpArchitect
That's true, although I assume many people will find this question looking for issues stemming from OkHttp usages. I'll clarify my answer.Systemize
it works for my case!Allen
L
6

Just add -ignorewarnings to proguard-rules.pro as described in the Android 8 release notes.

Languid answered 18/9, 2023 at 16:35 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Pie
H
5

Write the -dontwarn rules in the missing_rules.txt file into the proguard-rules file.

Hague answered 20/4, 2023 at 22:54 Comment(0)
E
2

After long time trouble, fix it by below steps.

Try to create build at machine level and find missing_rules.txt

build >> output >> mapping >> aapstoreliverelease (depend on what environment you selected) >> missing_rules.txt

Copy missiing rules and paste it into progaurd file and try to run.

It'll work.

In my case missing rules are below.

# Please add these rules to your existing keep rules in order to suppress warnings.
# This is generated automatically by the Android Gradle plugin.
-dontwarn org.apache.commons.lang.builder.ToStringBuilder
-dontwarn org.slf4j.impl.StaticLoggerBinder

Note :

  1. Each one have different case so please try to find missing_rules.txt file of your project and do copy paste into progaurd.
  2. Don't try to waste time to use others rules mentioned here because it can work and can't.

hope it will work for you.

Emetic answered 15/1 at 15:50 Comment(2)
Thanks for focusing out that: Each one have different case...Hautesalpes
@Hautesalpes hope it will help. ThanksEmetic
U
2
  • Create a file in app folder proguard-rules.pro

in this file write some code below-

 ## Flutter wrapper
 -keep class io.flutter.app.** { *; }
 -keep class io.flutter.plugin.** { *; }
 -keep class io.flutter.util.** { *; }
 -keep class io.flutter.view.** { *; }
 -keep class io.flutter.** { *; }
 -keep class io.flutter.plugins.** { *; }
 -keep class com.google.firebase.** { *; }
 -dontwarn io.flutter.embedding.**
 -ignorewarnings
Unshakable answered 23/4 at 5:47 Comment(0)
R
1

Write the -dontwarn rules in the proguard-rules file

-dontwarn okhttp3.internal.platform.**
-dontwarn org.conscrypt.**
-dontwarn org.bouncycastle.**
-dontwarn org.openjsse.**
Rubricate answered 1/5, 2023 at 17:32 Comment(1)
The OP doesn´t use OkHttpArchitect
S
1

Just add the following lines of code in the proguard-rules.pro and again build the signed apk or app bundle. It worked for me at last. find the missing classes accordingly and add '-dontwarn' followed by the class name.

-dontwarn com.android.org.conscrypt.SSLParametersImpl
-dontwarn org.apache.harmony.xnet.provider.jsse.SSLParametersImpl
Sedillo answered 27/1 at 15:37 Comment(0)
L
1

If it the missing classes are present in your own Android library, then you can add the following to the libraries proguard.pro file:

-keep class packagename.classname

or simply

-keep class packagename.*

This will ensure that the minification of the library doesn't drop these classes that are used in the root project.

Lupercalia answered 9/5 at 12:49 Comment(0)
L
0

These rules worked for me

-dontwarn com.google.protobuf.java_com_google_android_gmscore_sdk_target_granule__proguard_group_gtm_N1281923064GeneratedExtensionRegistryLite**

-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation
Lind answered 25/5, 2023 at 10:5 Comment(0)
M
0
  1. Go to proguard-rules file (this file is available in Gradle Scripts)
  2. add this rules in proguard-rules file
-dontwarn android.media.Spatializer$OnSpatializerStateChangedListener

-dontwarn android.media.Spatializer
Madonia answered 10/6, 2023 at 12:26 Comment(0)
R
0

Copy the missing rules from the file android\app\build\outputs\mapping\release\missing_rules.txt and paste it in the android\app\proguard-rules.pro

Rebuff answered 11/12, 2023 at 12:27 Comment(0)
C
0

instead of suppressing it , you should find the missing class. for example if getting error related to annotations, please add following dependency to your app level build.gradle

//https://mvnrepository.com/artifact/com.google.errorprone/error_prone_annotations
implementation 'com.google.errorprone:error_prone_annotations:2.23.0'

this will add the missing class to your project and will remove error.

Convey answered 13/12, 2023 at 16:54 Comment(0)
V
-3

You can disable minifyEnabled when debug the app since you are debugging the app on your phone but for the release version let minifyEnabled true ;

    buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.ProfileForsign
    }
    debug {
        signingConfig signingConfigs.ProfileForsign
        debuggable true
        minifyEnabled false
    }
}
Verisimilar answered 2/7, 2023 at 19:30 Comment(0)
M
-9

Change minifyEnabled true to minifyEnabled false in build.gradle (app)

Maitilde answered 17/1 at 23:40 Comment(1)
it's not a good idea fo you want to upload a release version.Intravasation

© 2022 - 2024 — McMap. All rights reserved.