11

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
IAmGroot
  • 13,760
  • 18
  • 84
  • 154
  • Possible duplicate of [ProGuard: can't find referenced class com.google.android.gms.R](https://stackoverflow.com/questions/18646899/proguard-cant-find-referenced-class-com-google-android-gms-r) – Yuliia Ashomok Oct 02 '18 at 15:05

5 Answers5

10

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

Yahor10
  • 2,123
  • 1
  • 13
  • 13
  • 3
    Ive been reading that already. It says not to use ignorewarnings unless you know what your doing. Aka, you know what its reffering to and that it is fine. But implies things may well break doing so. So id rather link them properly than ignore warnings – IAmGroot Sep 25 '12 at 12:59
  • If you dont want use -ignore tag then just copy your classes with warnings to your src(source) folder and it should works – Yahor10 Sep 25 '12 at 13:02
  • 1
    +1 for helping, but these are not my classes. Im just going to give up on Pro-guard. Too much hastle. – IAmGroot Sep 25 '12 at 13:08
  • you can find these classes on apache site – Yahor10 Sep 25 '12 at 13:10
  • 1
    I'm having lots of issues too. Spent a whole 2 days on ProGuard, overly complicated. – Oliver Dixon May 04 '15 at 19:27
  • Does **-ignorewarning** have any adverse effect on the Proguard result? – IgorGanapolsky Nov 03 '16 at 13:54
6

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

NickUnuchek
  • 11,794
  • 12
  • 98
  • 138
1

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.

Nathan
  • 8,093
  • 8
  • 50
  • 76
richardwiden
  • 1,584
  • 2
  • 12
  • 22
0

If you are using library projects, than you should add -libraryjars to your library proguard config

k4dima
  • 6,070
  • 5
  • 41
  • 39
0

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.

AppiDevo
  • 3,195
  • 3
  • 33
  • 51