Proguard: ignoring package does not prevent warnings - android

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.

Related

ProGuard warnings for kotlinx.coroutines

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.

D8: Type `sun.misc.Unsafe` was not found

After enabling D8 in my android project, I've started seeing these warnings:
/Users/yashasvi/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/27.0.1-android/b7e1c37f66ef193796ccd7ea6e80c2b05426182d/guava-27.0.1-android.jar: D8: Type `sun.misc.Unsafe` was not found, it is required for default or static interface methods desugaring of `void com.google.common.util.concurrent.AbstractFuture$UnsafeAtomicHelper.<clinit>()`
/Users/yashasvi/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/27.0.1-android/b7e1c37f66ef193796ccd7ea6e80c2b05426182d/guava-27.0.1-android.jar: D8: Type `sun.misc.Unsafe` was not found, it is required for default or static interface methods desugaring of `sun.misc.Unsafe com.google.common.cache.Striped64.getUnsafe()`
/Users/yashasvi/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/27.0.1-android/b7e1c37f66ef193796ccd7ea6e80c2b05426182d/guava-27.0.1-android.jar: D8: Type `sun.misc.Unsafe` was not found, it is required for default or static interface methods desugaring of `sun.misc.Unsafe com.google.common.hash.LittleEndianByteArray$UnsafeByteArray.getUnsafe()`
/Users/yashasvi/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/27.0.1-android/b7e1c37f66ef193796ccd7ea6e80c2b05426182d/guava-27.0.1-android.jar: D8: Type `sun.misc.Unsafe` was not found, it is required for default or static interface methods desugaring of `void com.google.common.util.concurrent.AbstractFuture$UnsafeAtomicHelper.<clinit>()`
/Users/yashasvi/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/27.0.1-android/b7e1c37f66ef193796ccd7ea6e80c2b05426182d/guava-27.0.1-android.jar: D8: Type `sun.misc.Unsafe` was not found, it is required for default or static interface methods desugaring of `sun.misc.Unsafe com.google.common.cache.Striped64.getUnsafe()`
/Users/yashasvi/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/27.0.1-android/b7e1c37f66ef193796ccd7ea6e80c2b05426182d/guava-27.0.1-android.jar: D8: Type `sun.misc.Unsafe` was not found, it is required for default or static interface methods desugaring of `sun.misc.Unsafe com.google.common.hash.LittleEndianByteArray$UnsafeByteArray.getUnsafe()`
.
Project builds successfully but at runtime, I see these error logs and due to this, app functionality is affected.
java.lang.AbstractMethodError: abstract method "java.lang.Object com.google.common.base.e.a(java.lang.Object)"
at com.google.common.e.a.i$c.a(SourceFile:1464)
at com.google.common.e.a.i$c.a(SourceFile:1453)
at com.google.common.e.a.i$a.run(SourceFile:1408)
at com.google.common.e.a.l$a.execute(SourceFile:456)
at com.google.common.e.a.i$f.a(SourceFile:153)
at com.google.common.e.a.i.a(SourceFile:1234)
I haven't been able to find anything useful on this after searching for a while. Please help.
And yes, I don't face this error at runtime if D8 is disabled and everything else remains same.
you need to keep sun.misc.Unsafe:
-keep class sun.misc.Unsafe { *; }
-dontnote sun.misc.Unsafe
alternatively, a rule with includedescriptorclasses should keep it dynamically:
-keep,includedescriptorclasses class com.google.common.**
in general:
adding switch -verbose is quite helpful for writing ProGuard configuration rules.
adding switch -dontoptimize can be used to disable all optimization, for a test.
just found this:
R8 now understands proguard specs in META-INF/proguard.
but unless this had been added, one has to add custom rules - instead of using consumer rules.
In your project-proguard file. Please add this:
-keepnames class com.google.common.**
-keep class com.google.common.**
-dontwarn com.google.common.**
It seems to be a sort of bug. But sometimes when you using D8 it tend to renames class names or delete them altogether.

Proguard unresolved references to classes

When building apk using Proguard, I see theses Warnings:
com.google.android.gms.internal.zzaq: can't find referenced class com.google.android.gms.internal.zzzk
com.google.android.gms.internal.zzaq: can't find referenced class com.google.android.gms.internal.zzzk$zza
com.google.android.gms.internal.zzaq: can't find referenced class com.google.android.gms.internal.zzzk
com.google.android.gms.internal.zzaq: can't find referenced class com.google.android.gms.internal.zzzk$zza
com.google.android.gms.internal.zzaq: can't find referenced class com.google.android.gms.internal.zzzk$zza
com.google.android.gms.internal.zzaq: can't find referenced class com.google.android.gms.internal.zzzk$zza
com.google.android.gms.internal.zzaq: can't find referenced class com.google.android.gms.internal.zzzk
com.google.android.gms.internal.zzaq$1: can't find referenced class com.google.android.gms.internal.zzzk
com.google.android.gms.internal.zzaq$1: can't find referenced class com.google.android.gms.internal.zzzk
com.google.android.gms.internal.zzbd: can't find referenced class com.google.android.gms.internal.zzaqg
com.google.android.gms.internal.zzbd: can't find referenced class com.google.android.gms.internal.zzzk
com.google.android.gms.internal.zzbd: can't find referenced class com.google.android.gms.internal.zzzk
com.google.android.gms.internal.zzbd: can't find referenced class com.google.android.gms.internal.zzaqg
com.google.android.gms.internal.zzej: can't find referenced field 'int[] AdsAttrs' in program class com.google.android.gms.R$styleable
com.google.android.gms.internal.zzej: can't find referenced field 'int AdsAttrs_adSize' in program class com.google.android.gms.R$styleable
com.google.android.gms.internal.zzej: can't find referenced field 'int AdsAttrs_adSizes' in program class com.google.android.gms.R$styleable
com.google.android.gms.internal.zzej: can't find referenced field 'int AdsAttrs_adUnitId' in program class com.google.android.gms.R$styleable
I'm using Google Play Services 10.2.0, modules ads, ads-lite, analytics, analytics-impl, base, basement, drive, games, tasks.
What modules or libraries need to be included to fix those warnings?
Based from this thread, if you use ProGuard, you need to keep some GMS (Google Play Services) classes and they are annotated with #com.google.android.gms.common.annotation.KeepName.
You need to ignore like you are compiling but you also need to keep the class so it can find it during runtime.
Add these two lines to your proguard configuration file:
-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**
You may also check these related SO posts:
Proguard and error
com.google.android.gms.internal.zzhu: can't find referenced class android.security.NetworkSecurityPolicy
How to use -dontwarn in ProGuard?

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.**

Categories

Resources