Proguard is having issues with the Lombok library when using Gradle in Android Studio to complile the library. I found some config info to fix butterknife, the other annotation library we use.
-keepattributes *Annotation*
-dontwarn butterknife.internal.**
-keep class **$$ViewInjector { *; }
-keepnames class * { #butterknife.InjectView *;}
Does anyone know the flags to add to make Lombok happy.
Proguard config file
# This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html
# Optimizations: If you don't want to optimize, use the
# proguard-android.txt configuration file instead of this one, which
# turns off the optimization flags. Adding optimization introduces
# certain risks, since for example not all optimizations performed by
# ProGuard works on all versions of Dalvik. The following flags turn
# off various optimizations known to have issues, but the list may not
# be complete or up to date. (The "arithmetic" optimization can be
# used if you are only targeting Android 2.0 or later.) Make sure you
# test thoroughly if you go this route.
#-optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/*,!code/allocation/variable
-dontobfuscate
#-optimizationpasses 5
-allowaccessmodification
-dontpreverify
# The remainder of this file is identical to the non-optimized version
# of the Proguard configuration file (except that the other file has
# flags to turn off optimization).
#-dontusemixedcaseclassnames
#-dontskipnonpubliclibraryclasses
-verbose
-keepattributes *Annotation*
-dontwarn butterknife.internal.**
-keep class **$$ViewInjector { *; }
-keepnames class * { #butterknife.InjectView *;}
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService
# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames class * {
native <methods>;
}
# keep setters in Views so that animations can still work.
# see http://proguard.sourceforge.net/manual/examples.html#beans
-keepclassmembers public class * extends android.view.View {
void set*(***);
*** get*();
}
# We want to keep methods in Activity that could be used in the XML attribute onClick
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
# The support library contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version. We know about them, and they are safe.
-dontwarn android.support.**
A few of the errors I'm seeing...
Warning:lombok.core.Agent$NetbeansPatcherInfo$1: can't find superclass or interface java.lang.instrument.ClassFileTransformer
Warning:lombok.core.AnnotationProcessor: can't find superclass or interface javax.annotation.processing.AbstractProcessor
Warning:lombok.delombok.DocCommentIntegrator$CommentAttacher_8$1: can't find superclass or interface com.sun.tools.javac.parser.Tokens$Comment
Warning:lombok.delombok.PrettyCommentsPrinter: can't find superclass or interface com.sun.tools.javac.tree.JCTree$Visitor
Warning:lombok.delombok.PrettyCommentsPrinter$1UsedVisitor: can't find superclass or interface com.sun.tools.javac.tree.TreeScanner
Warning:lombok.delombok.ant.DelombokTask: can't find superclass or interface org.apache.tools.ant.Task
Warning:lombok.eclipse.EclipseAstProblemView$LombokProblem: can't find superclass or interface org.eclipse.jdt.internal.compiler.problem.DefaultProblem
Warning:lombok.eclipse.agent.ExtensionMethodCompletionProposal: can't find superclass or interface org.eclipse.jdt.internal.codeassist.InternalCompletionProposal
Warning:lombok.eclipse.handlers.SetGeneratedByVisitor: can't find superclass or interface org.eclipse.jdt.internal.compiler.ASTVisitor
Warning:lombok.installer.InstallerGUI$12: can't find superclass or interface java.awt.event.ActionListener
Warning:lombok.installer.InstallerGUI$13: can't find superclass or interface java.awt.event.ActionListener
Warning:lombok.installer.InstallerGUI$2: can't find superclass or interface java.awt.event.ActionListener
Warning:lombok.installer.InstallerGUI$3: can't find superclass or interface java.awt.event.ActionListener
Warning:lombok.installer.InstallerGUI$4: can't find superclass or interface java.awt.event.ActionListener
Warning:lombok.installer.InstallerGUI$6: can't find superclass or interface java.awt.event.ActionListener
Warning:lombok.installer.InstallerGUI$6$2: can't find superclass or interface javax.swing.filechooser.FileFilter
Warning:lombok.installer.InstallerGUI$7: can't find superclass or interface java.awt.event.ActionListener
Warning:lombok.installer.InstallerGUI$8: can't find superclass or interface java.awt.event.ActionListener
Warning:lombok.installer.InstallerGUI$9: can't find superclass or interface java.awt.event.ActionListener
...
Warning: there were 10560 unresolved references to classes or interfaces.
You may need to add missing library jars or update their versions.
If your code works fine without the missing classes, you can suppress
the warnings with '-dontwarn' options.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
Warning: there were 128 instances of library classes depending on program classes.
You must avoid such dependencies, since the program classes will
be processed, while the library classes will remain unchanged.
(http://proguard.sourceforge.net/manual/troubleshooting.html#dependency)
Warning: there were 103 unresolved references to program class members.
Your input classes appear to be inconsistent.
You may need to recompile the code.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedprogramclassmember)
:just10:proguardGooglePhoneDevDebug FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':just10:proguardGooglePhoneDevDebug'.
> java.io.IOException: Please correct the above warnings first.
I added some flags to suppress warnings for the included libraries in my project and that did the trick.
-dontwarn javax.**
-dontwarn lombok.**
-dontwarn org.apache.**
-dontwarn com.squareup.**
-dontwarn com.sun.**
-dontwarn **retrofit**
If you're using a compile directive in your gradle build file, change it to provided
In Eclipse, there's a similar solution where you can break the jar into a lombok-api.jar that you include in your libs. I tried looking for the instructions, but can't find the page that explained how you'd do that (This was over a year ago, so it may have changed).
Thanks to Roel (below), here's the commandline to use:
java -jar lombok.jar publicApi
Related
I implemented a library on my gradle that uses Moshi as a dependency. When I tried to compile locally and also creating an android build through jenkins, it shows an error of
Use of generics not allowed for java type at '<1>_<2>_<3>JsonAdapter' in line 43 of file '\.gradle\caches\transforms-1\files-1.1\jetified-moshi-1.9.3.jar\76f6a6d7d5642e8be11f9d49dc24d752\META-INF\proguard\moshi.pro'
I already indicated rules on my proguard.pro file as stated on the documentation of the library I used but still errors are still encountering. I also tried the solution on the issues tab of moshi on github but I still received an error build.
Here's my proguard-rules.pro file
#ChatvisorLibrary
-keep class com.chatvisor.** {*;}
-dontwarn com.chatvisor.**
-dontwarn okhttp3.**
#Dependencies
#Protocol Buffers
-keep class com.google.**
-dontwarn com.google.**
#Moshi (https://github.com/square/moshi/blob/master/moshi/src/main/resources/META-INF/proguard/moshi.pro)
# JSR 305 annotations are for embedding nullability information.
-dontwarn javax.annotation.**
-keepclasseswithmembers class * {
#com.squareup.moshi.* <methods>;
}
-keep #com.squareup.moshi.JsonQualifier interface *
# Enum field names are used by the integrated EnumJsonAdapter.
# values() is synthesized by the Kotlin compiler and is used by EnumJsonAdapter indirectly
# Annotate enums with #JsonClass(generateAdapter = false) to use them with Moshi.
-keepclassmembers #com.squareup.moshi.JsonClass class * extends java.lang.Enum {
<fields>;
**[] values();
}
-ignorewarnings
-keep class * {
public private protected *;
}
I hope someone could help me and get resolved the issue. Thank you!
Already resolved this issue by upgrading my Proguard version
https://www.guardsquare.com/en/blog/proguard-61-released
I have been researching this for the past few hours without any luck. Class names are not obfuscated no matter what. These are just regular classes, not Activities, Services, or something else which is also in Android Manifest (I know those don't get obfuscated). What am I missing here?
Android Gradle Plugin version: 4.0.0
Gradle version: 6.1.1
Android Studio version: 4.0
With these versions, R8 should be enabled by default. Here is my buildType config:
buildTypes {
release {
//useProguard false // even tried this without luck
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
Here is my proguard-rules.pro
-ignorewarnings
# --- Glide ---
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.module.AppGlideModule
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
**[] $VALUES;
public *;
}
# --- Billing library ---
-keep class com.android.vending.billing.**
# --- Retrofit2 ---
# Retrofit does reflection on generic parameters. InnerClasses is required to use Signature and
# EnclosingMethod is required to use InnerClasses.
-keepattributes Signature, InnerClasses, EnclosingMethod
# Retrofit does reflection on method and parameter annotations.
-keepattributes RuntimeVisibleAnnotations, RuntimeVisibleParameterAnnotations
# Retain service method parameters when optimizing.
-keepclassmembers,allowshrinking,allowobfuscation interface * {
#retrofit2.http.* <methods>;
}
# Ignore annotation used for build tooling.
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
# Animal Sniffer compileOnly dependency to ensure APIs are compatible with older versions of Java.
-dontwarn org.codehaus.mojo.animal_sniffer.*
# Ignore JSR 305 annotations for embedding nullability information.
-dontwarn javax.annotation.**
# With R8 full mode, it sees no subtypes of Retrofit interfaces since they are created with a Proxy
# and replaces all potential values with null. Explicitly keeping the interfaces prevents this.
-if interface * { #retrofit2.http.* <methods>; }
-keep,allowobfuscation interface <1>
# --- TwitterKit ---
#Picasso Proguard Config https://github.com/square/picasso
-dontwarn com.squareup.okhttp.**
# --- GSON ---
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature
# For using GSON #Expose annotation
-keepattributes *Annotation*
# Gson specific classes
-dontwarn sun.misc.**
#-keep class com.google.gson.stream.** { *; }
# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { <fields>; }
# Prevent proguard from stripping interface information from TypeAdapter, TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in #JsonAdapter)
-keep class * implements com.google.gson.TypeAdapter
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer
# Prevent R8 from leaving Data object members always null
-keepclassmembers,allowobfuscation class * {
#com.google.gson.annotations.SerializedName <fields>;
}
# --- SciChart ---
# ignore warnings and save classes required for syntax highlighting
-dontwarn java.awt.**
-dontwarn javax.swing.**
-dontwarn syntaxhighlight.**
-keep public class java.awt.** { *; }
-keep public class javax.swing.** { *; }
-keep public class syntaxhighlight.** { *; }
-keep public class prettify.** { *; }
# need to keep these classes and their methods because they are used by resampling code
-keep public class com.scichart.core.model.DoubleValues { *; }
-keep public class com.scichart.core.model.FloatValues { *; }
-keep public class com.scichart.core.model.IntegerValues { *; }
-keep public class com.scichart.data.model.Point2DSeries { *; }
# repack obfuscated classes into single package so it would be hard to find their originall package
-repackageclasses ''
-allowaccessmodification
Similar questions which I checked but didn't offer any solutions to this:
Android studio 3.4.2 R8 obfuscator does not obfuscate class names, but only java code inside
Class no longer obfuscated after upgrading to Android Gradle plugin 3.4.0
Android/java: Transition / Migration from ProGuard to R8?
As per WorkManager's proguard file, it is expected that all classes that extend ListenableWorker (and its subclasses, such as Worker) are kept. This is because the name of the class is the unique key in WorkManager's internal database.
I am trying to setup proguard on my app and I'm encountering the following error:
java.lang.NoSuchMethodError: No static method getParameterized(Ljava/lang/reflect/Type;[Ljava/lang/reflect/Type;)Lcom/google/gson/reflect/TypeToken; in class Lcom/google/gson/reflect/TypeToken; or its super classes (declaration of 'com.google.gson.reflect.TypeToken' appears in /data/app/com.rw.crm.leads-1/base.apk)
at com.rw.crm.leads.model.response.GsonAdaptersResponse$ListResponseTypeAdapter.<init>(GsonAdaptersResponse.java:185)
at com.rw.crm.leads.model.response.GsonAdaptersResponse.create(GsonAdaptersResponse.java:36)
at com.google.gson.Gson.getAdapter(Gson.java:423)
I am unable to come up with a proguard configuration that resolves this. This is what I have in the gson proguard file the moment:
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature
# For using GSON #Expose annotation
-keepattributes *Annotation*
# Gson specific classes
-dontwarn sun.misc.**
#-keep class com.google.gson.stream.** { *; }
# Application classes that will be serialized/deserialized over Gson
-keep class com.rw.crm.leads.model.** { *; }
# Prevent proguard from stripping interface information from TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in #JsonAdapter)
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer
# To make the app compile
-dontwarn com.google.gson.reflect.TypeToken
# Why doesn't this work?
-keep class com.google.gson.reflect.** { *; }
Edit: here are the relevant dependencies from build.gradle
compile "com.squareup.retrofit2:retrofit:2.3.0"
compile "com.squareup.retrofit2:converter-gson:2.3.0"
annotationProcessor "org.immutables:value:2.5.6"
provided "org.immutables:gson:2.5.6:annotations"
By including the latest gson release in my gradle, I was able to resolve this error:
compile 'com.google.code.gson:gson:2.8.2'
This will be the fix until whichever library is using the older version (immutables or retrofit2) updates their gson.
I'm trying to configure proguard and have faced with some problems which are sorted by priority:
I have received warnings of duplicates zip and cannot fix it.
I use external libraries in "libs" directory and 2 library projects(one library project has one external lib - added to project only once) which are added to project only once. I tried to move my external jars to another directory, i.e. "lib" - just rename due to some users have been managed to solve it so but it doesn't help me. Another way was trying to implement custom_rules to basic build.xml due to it helps some users to avoid these warning. But everything from it doesn't help me, how can I fix it? Log:
ProGuard: Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [jackson-annotations-2.1.4.jar:META-INF/MANIFEST.MF])
ProGuard: Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [android-support-v4.jar:META-INF/MANIFEST.MF])
ProGuard: Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [google-analytics-v2.jar:META-INF/MANIFEST.MF])
ProGuard: Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [jackson-core-2.1.4.jar:META-INF/MANIFEST.MF])
ProGuard: Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [httpclientandroidlib-1.1.2.jar:META-INF/MANIFEST.MF])
ProGuard: Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [deviceprint-lib-1.0.0.jar:META-INF/MANIFEST.MF])
Last thing is some notes during signed apk building:
ProGuard: Note: com.google.analytics.tracking.android.AdHitIdGenerator: can't find dynamically referenced class com.google.ads.AdRequest
ProGuard: Note: the configuration refers to the unknown class 'com.google.vending.licensing.ILicensingService'
ProGuard: Note: the configuration refers to the unknown class 'com.android.vending.licensing.ILicensingService'
Full proguard file:
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
# Otherwise return Warning: com.fasterxml.jackson.databind.ext.DOMSerializer: can't find referenced class org.w3c.dom.bootstrap.DOMImplementationRegistry
-dontwarn com.fasterxml.jackson.databind.**
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
# Preserve all fundamental application classes.
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.view.View
-keep public class * extends android.preference.Preference
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
# Preserve ActionBarSherlock and Android support libraries` classes and interfaces
-keep class android.support.** { *; }
-keep interface android.support.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep interface com.actionbarsherlock.** { *; }
# Preserve all Jackson library classes
-keep class com.fasterxml.jackson.** { *; }
# Original
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
#To remove debug logs:
-assumenosideeffects class android.util.Log {
public static *** d(...);
public static *** v(...);
}
The 6 warnings and 3 notes that you currently list are harmless.
You should make sure that you are using a recent version of the Android SDK, which creates an empty proguard-project.txt for your project. The standard Ant build and Eclipse build take care of the important configuration internally (I presume you're using Ant from IDEA). You can still add application-specific options to proguard-project.txt, like the -keep options for Jackson and ActionBarSherlock. Do not add options like -injars/-libraryjars/-outjars, since the build process specifies them for you.
There are similar problems discussed here in Stackoverflow:
Android Proguard Duplicate Definition
Duplicate resources when using ProGuard and an Android application
Android - Proguard duplicate zip entry error
In Your case, I think the first one could help You...
If this does not help, we should look from where this issue comes. I even have some apps at playstore with third party libs and I had no problems with proguard. Here are my proguard.cfg settings from one of my app with a third party lib and google lvl licensing:
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-dontwarn **CompatHoneycomb
-keep class android.support.v4.** { *; }
-dontwarn org.apache.**
-verbose
-dontoptimize
-dontshrink
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-keepattributes *Annotation*
-dontwarn com.google.ads.**
well, You don´t need all them, it depends what you have implemented or which third party libs You use. So, I couldn´t see your app structure and got no code, this would exceed the scope. I suggest that You just test one by one.
I'm very short on time here, so I truly hope someone here has a clue how to fix these:
[proguard] Warning: android.support.v4.view.ViewConfigurationCompatFroyo: can't find referenced method 'int getScaledPagingTouchSlop()' in class android.view.ViewConfiguration
[proguard] Note: org.codehaus.jackson.map.deser.BasicDeserializerFactory: can't find dynamically referenced class java.util.ConcurrentNavigableMap
[proguard] Note: org.codehaus.jackson.map.deser.BasicDeserializerFactory: can't find dynamically referenced class java.util.ConcurrentSkipListMap
[proguard] Note: there were 2 unresolved dynamic references to classes or interfaces.
[proguard] You should check if you need to specify additional program jars.
[proguard] Warning: there were 1 unresolved references to program class members.
[proguard] Your input classes appear to be inconsistent.
[proguard] You may need to recompile them and try again.
[proguard] Alternatively, you may have to specify the options
[proguard] '-dontskipnonpubliclibraryclasses' and/or
[proguard] '-dontskipnonpubliclibraryclassmembers'.
I already tried adding multiple things:
-dontwarn **CompatHoneycomb
-dontwarn **CompatCreatorHoneycombMR2
-keep class android.support.v4.** { *; }
and also (for the jackson errors):
-libraryjars /Libraries/Joda/joda-time-1.6.2.jar
-libraryjars /Libraries/stax2-api-3.0.0.jar
-libraryjars /Libraries/jsr311-api-0.8.jar
-libraryjars /Libraries/httpmime-4.0.1.jar
Anyone have a clue what i'm missing in my proguard.cfg for these references? Or potentially some tips on how to investigate / resolve it more generally?
I brought it down from 472 warnings to just these, mostly by adding the dontwarn statements:
-dontwarn java.awt.,javax.security.,java.beans.,javax.xml.,java.util.,org.w3c.dom.
EDIT: Migrated to Answer
-dontwarn **CompatHoneycomb
-dontwarn **CompatCreatorHoneycombMR2
-dontwarn android.support.v4.view.**
-keep class android.support.v4.** { *; }
-dontwarn java.awt.**,javax.security.**,java.beans.**,javax.xml.**,java.util.**,org.w3c.dom.**
Edited my post above to display the answer.
Found it.
These seemed to help.
-dontwarn **CompatHoneycomb
-dontwarn **CompatCreatorHoneycombMR2
-dontwarn android.support.v4.view.**
-keep class android.support.v4.** { *; }
-dontwarn java.awt.**,javax.security.**,java.beans.**,javax.xml.**,java.util.**,org.w3c.dom.**
Add the following to your proguard configuration file.
-keep class org.codehaus.jackson.** {
*;
}
You do not need to obscure 3rd party libraries.