29

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?

Jim Clermonts
  • 1,694
  • 8
  • 39
  • 94

8 Answers8

59

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 you path to mmissing_rules.txt

I follow the path to mmissing_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 message into proguard-rules.pro then i fix this problem.

Kamal Nayan
  • 1,635
  • 1
  • 5
  • 19
Ven Ren
  • 1,584
  • 1
  • 13
  • 24
  • 3
    This should be the answer – Tony Jun 20 '23 at 13:53
  • 2
    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.WillClose – Mick Jul 27 '23 at 01:50
  • @mick yes, I get the as seam warnings as yours, i don't why. but it's working. – Ven Ren Jul 27 '23 at 07:02
  • 1
    Is this safe though? We just suppressed the warnings here, not fixing the real problem – Risal Fajar Amiyardi Jul 28 '23 at 08:09
  • 2
    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. – Mick Jul 29 '23 at 01:59
21

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.

sgjesse
  • 3,793
  • 14
  • 17
  • Opened https://github.com/google/conscrypt/pull/1046 to address some of these. – sgjesse Nov 22 '21 at 13:43
  • I added lombok to libgdx in this way ```project(":android") { apply plugin: "com.android.application" configurations { natives } dependencies { api "org.projectlombok:lombok:$lombokVersion" } }``` – kapellan Dec 17 '22 at 21:38
6

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.

bompf
  • 1,374
  • 1
  • 18
  • 24
1

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

Nick
  • 73
  • 7
0

Write the -dontwarn rules in the proguard-rules file

-dontwarn okhttp3.internal.platform.**
-dontwarn org.conscrypt.**
-dontwarn org.bouncycastle.**
-dontwarn org.openjsse.**
Attaullah
  • 3,856
  • 3
  • 48
  • 63
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
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
Anonymous
  • 835
  • 1
  • 5
  • 21
0

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
    }
}
yacine
  • 147
  • 1
  • 6