2

I am new to Proguard and I was implementing it in my application

App->Module1->ApIManager->Volley is the dependency diagram

I am using Grale. Without Proguard everything runs fine. However with Proguard I get the error above on three class uses.

I notices that all of these are under com.android.volley and are interfaces

My Proguard.cfg for APImanager and volley is

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

-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 *;
}

#---------------------------------------------------------------------------------------------
-renamesourcefileattribute SourceFile
-keepattributes  Signature,SourceFile,LineNumberTable

-keep interface com.android.volley.Response$ErrorListener { *; }
-keep interface com.android.volley.toolbox$ImageLoader { *; }
-keep interface com.android.volley.Request$Method { *; }

-keep public class * extends android.app.Application

-keep class android.support.v4.app.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep class com.android.volley.** { *; }

-keepattributes *Annotation*


-dontwarn org.apache.**
-keep class org.apache.commons.logging.**

Build Error:

:volley:transformClassesAndResourcesWithSyncLibJarsForRelease
:volley:mergeReleaseJniLibFolders UP-TO-DATE
:volley:transformNative_libsWithMergeJniLibsForRelease UP-TO-DATE
:volley:transformNative_libsWithSyncJniLibsForRelease UP-TO-DATE
:volley:bundleRelease
:apimanager:prepareComAndroidSupportAnimatedVectorDrawable2340Library UP-TO-DATE
:apimanager:prepareComAndroidSupportAppcompatV72340Library UP-TO-DATE
:apimanager:prepareComAndroidSupportSupportV42340Library UP-TO-DATE
:apimanager:prepareComAndroidSupportSupportVectorDrawable2340Library UP-TO-DATE
:apimanager:prepareComAndroidVolleyVolleyUnspecifiedLibrary
:apimanager:prepareReleaseDependencies
:apimanager:compileReleaseAidl UP-TO-DATE
:apimanager:compileReleaseRenderscript UP-TO-DATE
:apimanager:generateReleaseBuildConfig UP-TO-DATE
:apimanager:mergeReleaseShaders UP-TO-DATE
:apimanager:compileReleaseShaders UP-TO-DATE
:apimanager:generateReleaseAssets UP-TO-DATE
:apimanager:mergeReleaseAssets UP-TO-DATE
:apimanager:generateReleaseResValues UP-TO-DATE
:apimanager:generateReleaseResources UP-TO-DATE
:apimanager:mergeReleaseResources UP-TO-DATE
:apimanager:processReleaseManifest UP-TO-DATE
:apimanager:processReleaseResources UP-TO-DATE
:apimanager:generateReleaseSources UP-TO-DATE
:apimanager:incrementalReleaseJavaCompilationSafeguard UP-TO-DATE
:apimanager:compileReleaseJavaWithJavac
:apimanager:compileReleaseJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
--Path--\apimanager\APIManager.java
Error:(124, 105) error: cannot find symbol class ErrorListener
Error:(133, 107) error: cannot find symbol class ErrorListener
Error:(50, 32) error: cannot find symbol class ImageCache
Error:(66, 32) error: cannot find symbol class ImageCache
--Path--\apimanager\CategoryRequest.java
Error:(24, 82) error: cannot find symbol class ErrorListener
Error:(25, 15) error: cannot find symbol variable Method
--Path--\apimanager\ProductRequest.java
Error:(32, 80) error: cannot find symbol class ErrorListener
Error:(33, 15) error: cannot find symbol variable Method
:apimanager:compileReleaseJavaWithJavac FAILED
Error:Execution failed for task ':apimanager:compileReleaseJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
Information:BUILD FAILED

Code runs fine without proguard, I have tried almost everything and went through a lot of tutorials too without help.

Bryan
  • 14,756
  • 10
  • 70
  • 125
NKJ
  • 63
  • 6
  • The problem you are seeing has nothing to do with ProGuard. The error happens during compilation of your source files and indicate that you might import some wrong classes or symbols. – T. Neidhart Jun 17 '16 at 12:13
  • @tome It works perfectly without proguard. Actually We finished the program first and then started to implement proguard. During rebuild proguard removes some of the essential classes that I am unable to figure out – NKJ Jun 18 '16 at 13:15
  • Do you have maybe multiple dependent library projects on which the application project depends and apply proguard also on the library projects? Then it is possible that proguard removes classes that might be needed by the application. Either do not apply proguard on library projects or add appropriate -keep rules. – T. Neidhart Jun 18 '16 at 14:59
  • Thanks, you're right, I guess that is the main issue. I have spending time just to find it out step by step. Unfortunately you cannot debug this module by module and you have to proguard every module together. This leads to a lot of bugs to handle. – NKJ Jun 20 '16 at 05:14
  • If you use ProGuard also in library projects, you should specify the needed rules using `consumerProGuardFiles`. That way, they will be automatically included in the consuming application as well. – T. Neidhart Jun 20 '16 at 07:17
  • Thanks that really helped me, I searched for your advice and landed here http://stackoverflow.com/questions/26983248/proguard-ignores-config-file-of-library. Thanks a lot. I am able to reduce errors. I also gave the Proguard official tutorial a thorough read – NKJ Jun 20 '16 at 07:32

1 Answers1

0

When applying ProGuard to library projects in a multi-project build, you should specify the used rules with the following directive in gradle:

consumerProguardFiles('...')

This way they will also be automatically included in the consuming application project and the required keep rules will be applied.

T. Neidhart
  • 6,060
  • 2
  • 15
  • 38