ProGuard warnings for kotlinx.coroutines - android

Recently went through and updated most libraries in our app, which of course has led to ProGuard fun. We've gotten it down to just 3 warnings, which I can't for the life of me figure out what to do about.
Here's the warnings:
Warning: kotlinx.coroutines.AbstractContinuation: can't find referenced method 'kotlin.coroutines.CoroutineContext getContext()' in program class kotlinx.coroutines.AbstractContinuation
Warning: kotlinx.coroutines.DelayKt: can't find referenced method 'kotlin.coroutines.CoroutineContext getContext()' in program class kotlinx.coroutines.CancellableContinuation
Warning: kotlinx.coroutines.channels.TickerChannelsKt: can't find referenced method 'kotlin.coroutines.CoroutineContext plus(kotlin.coroutines.CoroutineContext)' in program class kotlinx.coroutines.CoroutineDispatcher
We're using the recommended set of kotlinx.coroutines ProGuard rules:
-keepnames class kotlinx.coroutines.internal.MainDispatcherFactory {}
-keepnames class kotlinx.coroutines.CoroutineExceptionHandler {}
-keepnames class kotlinx.coroutines.android.AndroidExceptionPreHandler{}
-keepnames class kotlinx.coroutines.android.AndroidDispatcherFactory {}
-keepclassmembernames class kotlinx.** {
volatile <fields>;
}
I've tried various combinations of aggressively keeping or ignoring those classes, but I'll be the first person to tell you that I'm not remotely a ProGuard expert and don't really know what I'm doing.
In general, any over aggressive usage of -dontwarn or -ignorewarnings seems to result in this error message:
Unexpected error while performing partial evaluation:
Class = [kotlinx/coroutines/CommonPool]
Method = [<clinit>()V]
Exception = [java.lang.IllegalArgumentException] (Can't find common super class of [java/lang/Integer] (with 3 known super classes) and [kotlinx/coroutines/CommonPool] (with 3 known super classes))
Unexpected error while preverifying:
Class = [kotlinx/coroutines/CommonPool]
Method = [<clinit>()V]
Exception = [java.lang.IllegalArgumentException] (Can't find common super class of [java/lang/Integer] (with 3 known super classes) and [kotlinx/coroutines/CommonPool] (with 3 known super classes))
And any more subtle/targeted methods (i.e. keeping the specific classes that get called back, trying to keep methods, etc) result in no change in the 3 warnings I pasted above.

Related

Proguard error when using FirebaseRemoteConfig and Play Services SDK

When I generate my APK with the following proguard rules
-keep public class com.google.android.gms.* { public *; }
-dontwarn com.google.android.gms.**
-keep public class com.google.firebase.* {public *;}
-dontwarn com.google.firebase.**
I get this error
Unexpected error while performing partial evaluation: Class =
[com/google/firebase/remoteconfig/FirebaseRemoteConfig] Method
= [getInstance()Lcom/google/firebase/remoteconfig/FirebaseRemoteConfig;]
Exception = [java.lang.IllegalArgumentException] (Can't find common
super class of [com/google/android/gms/internal/zzama] (with 2 known
super classes) and [com/google/android/gms/internal/zzamb$zzc] (with 1
known super classes))
Warning: Exception while processing task java.io.IOException:
java.lang.IllegalArgumentException: Can't find common super class of
[com/google/android/gms/internal/zzama] (with 2 known super classes)
and [com/google/android/gms/internal/zzamb$zzc] (with 1 known super
classes)
I found this URL http://proguard.sourceforge.net/manual/troubleshooting.html#superclass which says me to add the missing class. I am not sure which is the missing class here. Any inputs would be really appreciated.
I found the issue. it was because I had not updated the version of firebase once i updated google pay services in my gradle. Make sure that the version of your play service sdk and firebase sdk is same

Proguard: ignoring package does not prevent warnings

Why does having proguard ignore a package not prevent the warnings related to that package?
Background:
I am attempting to apply proguard to a large project. Predictably, I have lots of warning like this:
Warning:net.fortuna.ical4j.model.CalendarFactory: can't find superclass or interface groovy.util.AbstractFactory
Warning:net.fortuna.ical4j.model.CalendarFactory: can't find superclass or interface groovy.lang.GroovyObject
Warning:net.fortuna.ical4j.model.ContentBuilder: can't find superclass or interface groovy.util.FactoryBuilderSupport
Warning:net.fortuna.ical4j.model.ParameterListFactory: can't find superclass or interface groovy.util.AbstractFactory
Warning:net.fortuna.ical4j.model.ParameterListFactory: can't find superclass or interface groovy.lang.GroovyObject
Warning:net.fortuna.ical4j.model.component.AbstractComponentFactory: can't find superclass or interface groovy.util.AbstractFactory
Warning:net.fortuna.ical4j.model.component.AbstractComponentFactory: can't find superclass or interface groovy.lang.GroovyObject
Warning:net.fortuna.ical4j.model.component.XComponentFactory: can't find superclass or interface groovy.util.AbstractFactory
Warning:net.fortuna.ical4j.model.component.XComponentFactory: can't find superclass or interface groovy.lang.GroovyObject
Warning:net.fortuna.ical4j.model.parameter.AbstractParameterFactory: can't find superclass or interface groovy.util.AbstractFactory
Warning:net.fortuna.ical4j.model.parameter.AbstractParameterFactory: can't find superclass or interface groovy.lang.GroovyObject
Warning:net.fortuna.ical4j.model.property.AbstractPropertyFactory: can't find superclass or interface groovy.util.AbstractFactory
I thought I could approach this by excluding these packages from proguard until my app runs with proguard enabled. Then, working package-by-package, I could figure out whether I should ignoring the warnings or exclude only the necessary pieces.
I used this example of how to exclude a package, adding
-keep class net.fortuna.ical4j.model.** { public protected private *; }
to my proguard rules file. However, I get the same warnings as before. I did find this which suggests using -keep in combination with -dontwarn, but I don't understand why having proguard ignore the package doesn't prevent the warnings all together.
Keeping a class will not automatically hide warnings related to this class as they might indicate problems with the configuration or missing inputs.
To hide warnings for a specific package use
-dontwarn com.example.**
This will only hide Warnings, but not Notes, which can be hidden like this:
-dontnote com.example.**
Looking at your specific warning messages, it looks like that you are missing a groovy library that is used and referenced by the ical4j model classes.

Proguard build failed(Eclipse)

This question already have been asked many times, but I am not able to resolve it. I am trying to export my app using eclipse for final release, but I am getting the below error.
I already added
-keep class com.afollestad.materialdialogs.*{ *; }
-dontwarn com.afollestad.materialdialogs.**
-dontshrink
Error resolved, but after running my app crashed.
please help me
this is the error:
Proguard returned with error code 1. See console
Warning: com.afollestad.materialdialogs.util.DialogUtils: can't find referenced method 'android.content.res.ColorStateList getColorStateList(int)' in class android.content.Context
Warning: com.afollestad.materialdialogs.util.DialogUtils: can't find referenced method 'int getColor(int)' in class android.content.Context
You should check if you need to specify additional program jars.
Warning: there were 2 unresolved references to program class members.
Your input classes appear to be inconsistent.
You may need to recompile them and try again.
Alternatively, you may have to specify the option
dontskipnonpubliclibraryclassmembers'.
java.io.IOException: Please correct the above warnings first.
at proguard.Initializer.execute(Initializer.java:321)
at proguard.ProGuard.initialize(ProGuard.java:211)
at proguard.ProGuard.execute(ProGuard.java:86)

Can't enable Proguard on Android project containing jsch lib

I am trying to use Proguard to obfuscate my Android app which makes use of the library jsch-1.50.jar for uploading files to an SFTP server.
When I do an export from Eclipse, I get warnings "can't reference class" and nothing is produced. I have tried all manner of options to tell Proguard to ignore the jsch classes, but it's not making any difference and therefore I wonder if I am misunderstanding how this works. I am not too worried about the optimisation, but I would like the code obfuscated.
I have setup the proguard-properties as follows:
-keep class com.jcraft.jsch.jce.*
-keep class * extends com.jcraft.jsch.KeyExchange
-keep class com.jcraft.jsch.**
-keep class com.jcraft.jzlib.ZStream
-keep class com.jcraft.jsch.Compression
-keep class org.ietf.jgss.*
-libraryjars /libs/jsch-0.1.50.jar
The project-properties file contains an entry for "proguard.config=proguard-project.txt".
The output from the export with duplicates removed:-
Warning: com.jcraft.jsch.jcraft.Compression: can't find referenced class com.jcraft.jzlib.ZStream
Warning: com.jcraft.jsch.jgss.GSSContextKrb5: can't find referenced class org.ietf.jgss.Oid
Warning: com.jcraft.jsch.jgss.GSSContextKrb5: can't find referenced class org.ietf.jgss.GSSManager
Warning: com.jcraft.jsch.jgss.GSSContextKrb5: can't find referenced class org.ietf.jgss.GSSException
Warning: com.jcraft.jsch.jgss.GSSContextKrb5: can't find referenced class org.ietf.jgss.GSSContext
Warning: com.jcraft.jsch.jgss.GSSContextKrb5: can't find referenced class org.ietf.jgss.MessageProp
Warning: there were 44 unresolved references to classes or interfaces.
You may need to specify additional library jars (using '-libraryjars').
Error: Please correct the above warnings first.
Would very much appreciate any pointers.
Thanks
Mike
After a bit more investigation, I found the following...
I had forgotten to include jzlib-1.1.1.jar in the project with the corresponding
-libraryjars /libs/jzlib-1.1.1.jar
entry in the proguard-properties.txt.
Also to ignore the warning regards references to "class org.ietf.jgss", I tried the suggested method of excluding the referencing class
-libraryjars /libs/jsch-0.1.50.jar(!com.jcraft.jsch.jgss/GSSContextKrb5.class)
but that didn't help. In the end, I went with :-
-dontwarn org.ietf.jgss.**

Ant + Proguard provide android-support-v4.jar errors

While building project using ANT 1.8.2 and proguarg 4.8.1
[proguard] Unexpected error while evaluating instruction:
[proguard] Class = [android/support/v4/view/AccessibilityDelegateCompat$AccessibilityDelegateJellyBeanImpl]
[proguard] Method = [newAccessiblityDelegateBridge(Landroid/support/v4/view/AccessibilityDelegateCompat;)Ljava/lang/Object;]
[proguard] Instruction = [18] areturn
[proguard] Exception = [java.lang.IllegalArgumentException] (Can't find any super classes of [android/support/v4/view/AccessibilityDelegateCompatIcs$1] (not even immediate super class [android/view/View$AccessibilityDelegate]))
[proguard] Unexpected error while performing partial evaluation:
[proguard] Class = [android/support/v4/view/AccessibilityDelegateCompat$AccessibilityDelegateJellyBeanImpl]
[proguard] Method = [newAccessiblityDelegateBridge(Landroid/support/v4/view/AccessibilityDelegateCompat;)Ljava/lang/Object;]
[proguard] Exception = [java.lang.IllegalArgumentException] (Can't find any super classes of [android/support/v4/view/AccessibilityDelegateCompatIcs$1] (not even immediate super class [android/view/View$AccessibilityDelegate]))
BUILD FAILED
E:\adt-bundle-windows\sdk\tools\ant\build.xml:864: java.lang.IllegalArgumentException: Can't find any super classes of [android/support/v4/view/AccessibilityDelegateCompatIcs$1] (not even immediate super class [android/view/View$AccessibilityDelegate])
android-support-v4.jar is in class path and project dependecies...
From Eclipse all but debug version is built OK.
Ant display those errors...
How do avoid this? I understand if Eclipse builds this OK, the Ant have to build too..
P.S. My project is android-10 target and I don't want and can't make it target-16 if somebody'll advise...
what about try to add these to your proguard.cf?
-libraryjars libs/android-support-v4.jar
-dontwarn android.support.v4.**
-keep class android.support.v4.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep public class * extends android.support.v4.**
-keep public class * extends android.app.Fragment
You should specify a target SDK in your project.properties that in this case contains 'android.view.View$AccessibilityDelegate' (SDK level 14 or higher). ProGuard's shrinking/optimization/obfuscation need at least the same base SDK that was used for compiling the application and its libraries. The support library was compiled against this more recent SDK, so ProGuard needs it as well.
You can still specify a different target/min/max SDK in your AndroidManifest.xml, for running the application. You should of course make sure that the application is indeed compatible with those specified SDKs.

Categories

Resources