There are a few questions around but no solution that works for me. I thought it was suppose to be easy to use.
I just get a console full of can't find referenced class
This is my proguard-project.txt
-injars bin/classes
-injars libs
-outjars bin/classes-processed.jar
-libraryjars C:/Users/ME/android-sdks/platforms/android-10/android.jar
-dontpreverify
-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-keepattributes *Annotation*
-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.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.view.View {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
public void set*(...);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * extends android.content.Context {
public void *(android.view.View);
public void *(android.view.MenuItem);
}
-keepclassmembers class * implements android.os.Parcelable {
static android.os.Parcelable$Creator CREATOR;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
and project.properties
#Proguard enabled
proguard.config=C:/Users/ME/android-sdks/tools/proguard/proguard-android.txt:proguard-project.txt
some of the classes with warnings are:
org.apache.avalon.framework.logger.Logger
org.apache.log4j.Category
org.apache.log4j.Priority
org.apache.log4j.Logger
...
javax.servlet.ServletContextListener
javax.servlet.ServletContextEvent
org.w3c.dom.html.HTMLAnchorElement
org.w3c.dom.html.HTMLObjectElement
org.w3c.dom.html.HTMLTableSectionElement
org.w3c.dom.html.HTMLFrameSetElement
...
org.w3c.dom.events.DocumentEvent
org.w3c.dom.traversal.NodeFilter
...
org.w3c.dom.ranges.Range
org.w3c.dom.ranges.RangeException
...
org.w3c.dom.html.HTMLDocument
Add to your config:
-libraryjars org.apache.jar // name of your jars.
-libraryjars org.w3c.jar
If it does not help add:
-dontwarn org.apache.** tag
or just ignore warnings (highly unrecommended since it could cause your app to crash at runtime over unsatisfied dependencies):
-ignorewarnings
This doc will help you : http://proguard.sourceforge.net/manual/troubleshooting.html
If you have an error such as:
Warning: com.package...: can't find referenced class com.secondpackage....Classname
Just add to your file proguard-android.txt:
#if it is class:
-keep class com.package.*{ *; }
#or if it is interface:
-keep interface com.package.*{ *; }
#or if it is a class that extends from any other
-keep class * extends com.example.Model
#or if you know only and of className
-keep class **Starter { *; }
#or if you want to keep only fields of classes
-keepclassmembers class com.package.** {
*;
}
Also if you dont want to see all of notes in log use:
-dontnote com.package.**
This file name is written in build Gradle
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-android.txt'
}
}
Or if you want to add many files for example use the following repo
And for add all of files:
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
proguardFiles fileTree(include: ['*.pro'], dir: '../libraries').asList().toArray()
}
libraries folder should be at D:\workspace\MyProject\libraries
From what I can remember, it means you have referenced the Jar files in the wrong way.
Also, if your username (ME) contains spaces C:/Users/ME/android-sdks/tools/proguard/proguard-android.txt:proguard-project.txt Proguard will break in "funny" ways. Move android-sdk to C:\android-sdk and save yourself headache.
If you are using library projects, than you should add -libraryjars to your library proguard config
In my case Android Studio froze while doing ProGuard on release build. I killed it. And after the restart I started to see "can't find referenced class" warnings.
solution: I closed Android Studio, deleted .gradle folder from my project folder, then deleted gradle global cache (%USER_HOME%.gradle/caches). After reopening the project, caches was rebuild and everything started to work again.
Related
I am not very familiar with proguard, I want to obfuscate a JavaFX application, I already did it right but now after adding some changes to the project things screwed up.
Here is my .pro configuration file :
-injars ../INJAR.jar
-outjars ../OUTJAR.jar
-libraryjars 'rt.jar'
-libraryjars 'jce.jar'
-libraryjars 'jfxrt.jar'
-dontshrink
-dontoptimize
-flattenpackagehierarchy ''
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,*Annotation*,Synthetic,EnclosingMethod
-adaptresourcefilecontents **.fxml,**.properties,META-INF/MANIFEST.MF
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-keep class javax.** { *; }
-keep class impl.** { *; }
-dontwarn impl.**
-keep class org.** { *; }
-dontwarn org.**
-keepclasseswithmembers public class main.Main {
public static void main(java.lang.String[]);
}
-keepclassmembernames class * {
#javafx.fxml.FXML *;
}
-keepclassmembernames class main.*Controller {
public <methods>;
public <fields>;
}
-keepclassmembernames class main.NewApplicationController$Applicant {
public <methods>;
public <fields>;
}
-keepclassmembernames class main.RDVTaker {
public <methods>;
}
-obfuscationdictionary members.txt
-classobfuscationdictionary classes.txt
-printmapping mapping.txt
by executing the command :
java -jar obf_data/proguard.jar #obf_data/myconfig.pro > obf_data/info.txt
I get this erro :
Error: Unexpected error while writing class [oshi/hardware/platform/mac/MacDisks] (Overflow of unsigned short value [70168])
I bypassed the above error by removing -dontshrink option, but in this case the resulting jar is raising the following error : Error: Invalid or corrupt jarfile OUTJAR.jar
And by removing both -dontshrink and -dontoptimize another error get raised, a stacktarce is printed, but I found out that the error was described at this level of stack :
Caused by: javafx.fxml.LoadException:
file:/C:/Users/younes/IdeaProjects/vpro/out/artifacts/vpro/OUTJAR.jar.
jar!/main/main.fxml:12
I am wondering if someone got a supposition, idea or even another obfuscating tool,
Thanks in advance
All of your FXML file names should start with UpperCase, accordingly you need to update your dictionaries.
I am trying to obfuscate some classes which contain a number of inner enums which I understand are compiled to separate standalone classes with the "$" separator by javac at compile time.
However, the problem I am having is that, although the contents of the enums are obfuscated, the parent / outer class as well as the enum class names themselves as well as their package names are not being obfuscated since the classes themselves are not being obfuscated.
We have specified ProGuard to keep various other classes within our proprietary packages (which are being dealt with correctly), but these should not be affecting the above mentioned classes.
Here is our config.pro file:
-injars .\build\libs\plugin.jar
-outjars .\build\libs\plugin_obfuscated.jar
-libraryjars .\jre\lib\rt.jar
-libraryjars .\jre\lib\jce.jar
-libraryjars .\jre\lib\ext\jfxrt.jar
## Mapping
-classobfuscationdictionary .\config_classnames.pro
-packageobfuscationdictionary .\config_packagenames.pro
-printmapping .\build\libs\proguard_obfuscation_map.txt
-printseeds .\build\libs\proguard_seeds_map.txt
-printusage .\build\libs\proguard_deadusage_map.txt
## Shrinking
-dontshrink
## Optimizations
#-dontoptimize
-optimizations method/removal/parameter,method/inlining/short,
method/inlining/unique
-optimizations code/removal/advanced,code/simplification/string,
code/removal/exception,code/removal/variable,code/merging
-optimizations class/unboxing/enum
-allowaccessmodification
-mergeinterfacesaggressively
#-optimizationpasses 5
#-repackageclasses ''
-flattenpackagehierarchy 'software'
## Obfuscation
-dontusemixedcaseclassnames
-overloadaggressively
## Keep attributes
-keepattributes !InnerClasses,Signature,Deprecated,*Annotation*,Synthetic
-adaptresourcefilecontents **.fxml
# ProGuard doesn't print notes about classes with matching names
-dontnote com.google.**
-dontnote com.sun.**
-dontnote org.apache.log4j.**
-dontnote org.apache.logging.**
-dontnote com.itextpdf.**
-dontnote org.apache.commons.io.**
-dontnote org.apache.commons.codec.**
-dontnote org.apache.commons.lang3.**
-dontnote org.hibernate.**
-dontnote **
-dontwarn **
# Keep specific proprietary classes
-keep class com.mycompany.product.framework.logging.** {
}
-keep class com.mycompany.product.plugin.persistence.** {
<fields>;
<methods>;
}
-keep class com.mycompany.product.plugin.networking.** {
<fields>;
<methods>;
}
-keep class com.mycompany.product.framework.automation.events.** {
<fields>;
<methods>;
}
-keep class com.mycompany.product.plugin.events.** {
<fields>;
<methods>;
}
-keep class com.mycompany.product.plugin.remote.** {
<fields>;
<methods>;
}
-keepnames class com.mycompany.product.plugin.providers.* {
}
-keepclassmembers class com.mycompany.product.framework.events.TestCase
{
<fields>;
<methods>;
}
# Keep class members with #FXML annotations
-keepclassmembers,allowshrinking class * {
#javafx.fxml.FXML
<fields>;
#javafx.fxml.FXML
<methods>;
}
# Keep - Antlr library
-keep class antlr.** {
<fields>;
<methods>;
}
# Keep fasterxml
-keep class com.fasterxml.** {
<fields>;
<methods>;
}
# Keep - Google classes
-keep class com.google.** {
<fields>;
<methods>;
}
... remaining other classes not to be included / sanitized
... followed by standard Proguard template configuration (truncated)
# Keep classes that implement Serializable
-keepnames class * implements java.io.Serializable
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
!static !transient <fields>;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}
# Keep - Applications. Keep all application classes, along with their
'main' methods.
-keepclasseswithmembers public class * {
public static void main(java.lang.String[]);
}
# Also keep - Enumerations. Keep the special static methods that are
required in enumeration classes.
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
# Keep - Native method names. Keep all native class/method names.
-keepclasseswithmembers,includedescriptorclasses,allowshrinking class * {
native <methods>;
}
The classes we are trying to obfuscate, which include the inner / nested enum classes are under the package:
com.mycompany.packageContainingEnum1.enumOuterClass1
com.mycompany.packageContainingEnum1.enumOuterClass1$enum1ClassName
and
com.mycompany.packageContainingEnum2.enumouterClass2
com.mycompany.packageContainingEnum2.enumOuterClass2$enum2ClassName
As you can see, the packages which are giving the problems are below the "product" package and therefore should not be affected by the rules above?
Any ideas why the enumouterClass2 and enumOuterClass2$enum2ClassName (enum) names are being preserved? This seems strange as by default, most people seem to have trouble preventing obfuscation of inner classes.
Thanks very much for your help.
Is there a way to skip proguard from obfuscating the Volley and Gson including the class using them ?
My build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.myawesomeapp"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:design:23.1.0'
compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
compile 'com.google.android.gms:play-services-appindexing:8.1.0'
}
Here the Proguard config:
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /home/starsilver/Android/Sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
-keepattributes Signature
# For using GSON #Expose annotation
-keepattributes *Annotation*
# Gson specific classes
-keep class sun.misc.Unsafe { *; }
#-keep class com.google.gson.stream.** { *; }
# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.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
-keep class com.android.volley.** { *; }
-keep class org.apache.commons.logging.**
-keepattributes *Annotation*
-dontwarn org.apache.**
-dontwarn com.itextpdf**
Errors returned for Volley:
Warning: com.android.volley.toolbox.Volley: can't find referenced class android.net.http.AndroidHttpClient
Warning: com.android.volley.toolbox.Volley: can't find referenced class android.net.http.AndroidHttpClient
NB:
Application work well without proguard.
Signed APK generated with proguard but class using Volley + Gson still not working
You have to modify your proguard.
For gson use this Gson github config:
-keepattributes Signature
# For using GSON #Expose annotation
-keepattributes *Annotation*
# Gson specific classes
-keep class sun.misc.Unsafe { *; }
#-keep class com.google.gson.stream.** { *; }
# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.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
For volley use this:
-keep class com.android.volley.** { *; }
-keep class org.apache.commons.logging.**
-keepattributes *Annotation*
-dontwarn org.apache.**
Volley seems not working after ProGuard obfuscate
Perhaps, you have no problems with Volley, you have problems with GSON, like in my case. Then, use this rules for GSON. Source: https://github.com/google/gson/blob/master/examples/android-proguard-example/proguard.cfg
# 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 * extends 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>;
}
##---------------End: proguard configuration for Gson ----------```
Hi I am struggling to create release version for my project. I have been try lot of things on Progaurd through SO / Google help but I am still not able to create the release version.
Can somebody help me with this? I always get this issue:
Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.
> java.io.IOException: Please correct the above warnings first.
Here is the full detailed error: http://justpaste.it/perror sorry I had to put as a link because it is huge.
Here are dependencies:
//compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.rengwuxian.materialedittext:library:2.1.4'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.4'
compile 'org.apache.httpcomponents:httpcore:4.4.1'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.loopj.android:android-async-http:1.4.8'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile project(':pageIndicator')
compile 'com.github.neopixl:PixlUI:v1.0.6'
compile 'com.github.bumptech.glide:glide:3.6.1'
My progaurd file:
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
-dontwarn com.google.code.**
-dontwarn org.apache.**
-dontwarn jp.wasabeef.recyclerview.**
-dontwarn com.nostra13.universalimageloader.**
-dontwarn org.acra.**
#wasabeef recyclerview
-keep class jp.wasabeef.recyclerview.** { *; }
-keepattributes Signature
#HTTP Legacy
-keep class org.apache.** { *; }
-keepattributes Signature
#Universal Image Loader
-keep class com.nostra13.universalimageloader.** { *; }
-keepattributes Signature
#Acra
-keep class org.acra.** { *; }
-keepattributes Signature
#Support libraries
-keep class com.android.** { *; }
-keepattributes Signature
# Keep the annotations
-keepattributes *Annotation*
-allowaccessmodification
-keepattributes *Annotation*
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
-repackageclasses ''
-dontnote com.android.vending.licensing.ILicensingService
# Explicitly preserve all serialization members. The Serializable interface
# is only a marker interface, so it wouldn't save them.
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}
# Preserve all native method names and the names of their classes.
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
# Preserve static fields of inner classes of R classes that might be accessed
# through introspection.
-keepclassmembers class **.R$* {
public static <fields>;
}
# Preserve the special static methods that are required in all enumeration classes.
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep public class * {
public protected *;
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keep class com.splunk.** { *; }
-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.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
-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);
}
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keep class com.splunk.** { *; }
-dontwarn rx.**
-dontwarn okio.**
-dontwarn com.squareup.okhttp.**
-keep class com.squareup.okhttp.** { *; }
-keep interface com.squareup.okhttp.** { *; }
-keep class org.apache.http.** { *; }
-dontwarn org.apache.http.**
-dontwarn android.net.**
-dontwarn retrofit.**
-dontwarn retrofit.appengine.UrlFetchClient
-keep class retrofit.** { *; }
-keepclasseswithmembers class * {
#retrofit.http.* <methods>;
}
-keepattributes Signature
-keepattributes *Annotation*
-keep class sun.misc.Unsafe { *; }
#your package path where your gson models are stored
-keep class com.ylg.others.** { *; }
In your ProGuard file add:
-ignorewarnings
like :
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in D:\Softwares\Developing\Android\sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
-ignorewarnings
You wouldn't have to specify any package like com.viewpagerindicator.** , this will suppress all warnings and the Gradle Console will just say like :
......
Warning: there were 4 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 2 unresolved references to library class members.
You probably need to update the library versions.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedlibraryclassmember)
Note: you're ignoring all warnings!
Ignoring unused library classes...
Original number of library classes: 4237
Final number of library classes: 1317
Printing kept classes, fields, and methods...
Shrinking...
......
In your ProGuard file add:
-dontwarn com.viewpagerindicator.**
If you open up the link you provided and search for 'Warning' about two thirds down you can see the message:
Warning:com.viewpagerindicator.LinePageIndicator: can't find referenced method 'float ceil(float)' in library class android.util.FloatMath
If there are any warnings ProGuard will stop and ask you to fix them first or if your code works you can choose to ignore them with dontwarn.
Update 05/01/2017
If the warning says in program class it is likely that your compiled class files are inconsistent, try removing them all and and rebuilding your project.
If the warning says in library class your compiled class files are inconsistent with the libraries. Try recompiling the class files or upgrading the libraries to consistent versions.
You can read more here.
What has helped me was to update all dependencies to last version.
In my case, the proguard file was totally ignored because the project consisted of several modules. According to this answer, the solution was to set the following in the gradle of the module causing the problem:
defaultConfig {
consumerProguardFiles 'proguard-rules.txt'
}
This seems to include the proguard of the module in the application's proguard. Now my dontwarn statements are taken in consideration.
I try to compress an android app that consumes ical4j.jar.
When i build the apk with proguard using gradle proguardDebug i get
Warning: net.fortuna.ical4j.model.CalendarFactory: can't find referenced method 'void finalize()' in library class java.lang.Object
6 additional similar warnings for finalize()
Warning: net.fortuna.ical4j.model.CalendarFactory: can't find referenced method 'java.lang.Object clone()' in library class java.lang.Object
6 additional similar warnings for clone()
I already verified that android-7 supports finalize() and clone(): "...\Android...\sdk\platforms\android-7\android.jar" has methods finalize() and clone() in class java.lang.Object .
Do you have any idea how to fix this?
Note: this is not a duplicate of other 'proguard can't find referenced method' questions because in my specific case i think that the missing method should be there.
I am using
proguard-4.11 with
gradle-1.11
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.9.2 compiled on July 8 2013
Ivy: 2.2.0
JVM: 1.7.0_25 (Oracle Corporation 23.25-b01)
OS: Windows 7 6.1 amd64
ical4j.jar 1.0.5
this is proguard config proguard-rules.txt that probably need some fix:
# proguard-rules.txt
## ical4j also contains groovy code which is not used in android
-dontwarn groovy.**
-dontwarn org.codehaus.groovy.**
-dontwarn org.apache.commons.logging.**
-dontwarn sun.misc.Perf
-dontnote com.google.vending.**
-dontnote com.android.vending.licensing.**
This is my build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
classpath 'net.sf.proguard:proguard-gradle:4.11'
}
}
allprojects {
repositories {
mavenCentral()
}
}
apply plugin: 'android'
configurations {
compile.exclude group: 'commons-logging' // referenced in some portable lib. use androids internal instead
}
android {
compileSdkVersion 19
buildToolsVersion '19.0.3'
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
defaultConfig {
minSdkVersion 7
targetSdkVersion 19
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
// used for testing. remove if it works as expected
debug {
runProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'org.mnode.ical4j:ical4j:1.0.5'
compile 'backport-util-concurrent:backport-util-concurrent:3.1'
compile 'commons-codec:commons-codec:1.8'
compile 'commons-lang:commons-lang:2.6'
}
[Update 2014-12-20]
I have added my working configuration as answer below.
Note: with Current Android Studio 1.0 (android.buildToolsVersion >= '20') you must replace
runProguard with minifyEnabled
Example
android {
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
net.fortuna.ical4j.model.CalendarFactory extends groovy.util.AbstractFactory which extends java.lang.Object. However, the middle class is missing from your input (you're suppressing the corresponding warnings with -dontwarn). With part of the class hierarchy missing, ProGuard doesn't realize that CalendarFactory may access the protected methods clone and finalize, and it prints out these warnings.
Since your code probably doesn't use the class at all, you can suppress the warnings:
-dontwarn net.fortuna.ical4j.model.CalendarFactory
Or for covering all similar classes:
-dontwarn net.fortuna.ical4j.model.**
You shouldn't add any -keep options for this issue; the Android SDK already specifies the basic Android-related -keep options for you.
This is my proguard config-file. Try copy-paste it
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontpreverify
-verbose
# standard, except v4.app.Fragment, its required when app uses Fragments
-keep public class * extends android.app.Activity
-keep public class * extends android.support.v7.app.ActionBarActivity
-keep public class * extends android.support.v4.app.Fragment
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keepclasseswithmembers class * {
native <methods>;
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-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 * extends android.app.Activity {
public void *(android.view.View);
}
Then add your code, as following:
When using
-dontwarn groovy.**
also add
-keep class groovy.** { *; }
Do it for all external libraries.
[update 2014-05-30 reformulated this text]
Thankyou to #EricLafortune answer that helped me to understand and solve the issue.
For others who want to compress android ical4j apps here is my working soluntion:
all classes with the in library class java.lang.Object - issue are from namespace
net.fortuna.ical4j.model.**
so i added these lines to proguard-rules.txt
###################
# Get rid of #can't find referenced method in library class java.lang.Object# warnings for clone() and finalize()
# for details see http://stackoverflow.com/questions/23883028/how-to-fix-proguard-warning-cant-find-referenced-method-for-existing-methods
-dontwarn net.fortuna.ical4j.model.**
###############
# I use proguard only to remove unused stuff and to keep the app small.
# I donot want to obfuscate (rename packages, classes, methods, ...) since this is open source
-keepnames class ** { *; }
-keepnames interface ** { *; }
-keepnames enum ** { *; }
statistics:
without obfuscation: 932 classes; apk 911kb.
with obfuscation: 365 classes;apk 505kb