Android signed APK creation: Proguard exception for reference class / method not found

I need to create a signed APK for the Play Store. (using Android Studio) If I do this without proguard (minifyEnabled false in build.gradle), everything works fine!

If , I activate it with the default settings:

buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } 

I get these warnings

 :app:proguardRelease Warning: com.android.volley.error.VolleyErrorHelper$1: can't find superclass or interface com.google.gson.reflect.TypeToken Warning: com.android.volley.error.VolleyErrorHelper: can't find referenced class com.google.gson.Gson Warning: com.android.volley.error.VolleyErrorHelper: can't find referenced class com.google.gson.Gson Warning: com.android.volley.error.VolleyErrorHelper: can't find referenced method 'java.lang.reflect.Type getType()' in program class com.android.volley.error.VolleyErrorHelper$1 Warning: com.android.volley.error.VolleyErrorHelper: can't find referenced class com.google.gson.Gson Warning: com.android.volley.error.VolleyErrorHelper$1: can't find referenced class com.google.gson.reflect.TypeToken Warning: com.android.volley.error.VolleyErrorHelper$1: can't find referenced class com.google.gson.reflect.TypeToken Warning: com.android.volley.error.VolleyErrorHelper$1: can't find referenced class com.google.gson.reflect.TypeToken Warning: com.android.volley.request.GsonRequest: can't find referenced class com.google.gson.Gson Warning: com.android.volley.request.GsonRequest: can't find referenced class com.google.gson.Gson Warning: com.android.volley.request.GsonRequest: can't find referenced class com.google.gson.Gson Warning: com.android.volley.request.GsonRequest: can't find referenced class com.google.gson.JsonSyntaxException Warning: com.android.volley.request.GsonRequest: can't find referenced class com.google.gson.JsonSyntaxException Warning: com.android.volley.request.GsonRequest: can't find referenced class com.google.gson.Gson Warning: com.android.volley.request.GsonRequest: can't find referenced class com.google.gson.JsonSyntaxException Warning: com.squareup.okhttp.internal.huc.HttpsURLConnectionImpl: can't find referenced method 'long getContentLengthLong()' in program class com.squareup.okhttp.internal.huc.HttpURLConnectionImpl Warning: com.squareup.okhttp.internal.huc.HttpsURLConnectionImpl: can't find referenced method 'long getHeaderFieldLong(java.lang.String,long)' in program class com.squareup.okhttp.internal.huc.HttpURLConnectionImpl Warning: okio.DeflaterSink: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement Warning: okio.Okio: can't find referenced class java.nio.file.Files Warning: okio.Okio: can't find referenced class java.nio.file.Files Warning: okio.Okio: can't find referenced class java.nio.file.Files Warning: okio.Okio: can't find referenced class java.nio.file.Path Warning: okio.Okio: can't find referenced class java.nio.file.OpenOption Warning: okio.Okio: can't find referenced class java.nio.file.Path Warning: okio.Okio: can't find referenced class java.nio.file.OpenOption Warning: okio.Okio: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement Warning: okio.Okio: can't find referenced class java.nio.file.Path Warning: okio.Okio: can't find referenced class java.nio.file.OpenOption Warning: okio.Okio: can't find referenced class java.nio.file.Path Warning: okio.Okio: can't find referenced class java.nio.file.OpenOption Warning: okio.Okio: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement Warning: there were 28 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 3 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) Exception while processing task java.io.IOException: Please correct the above warnings first. at proguard.Initializer.execute(Initializer.java:473) at proguard.ProGuard.initialize(ProGuard.java:233) at proguard.ProGuard.execute(ProGuard.java:98) at proguard.gradle.ProGuardTask.proguard(ProGuardTask.java:1074) at com.android.build.gradle.tasks.AndroidProGuardTask.doMinification(AndroidProGuardTask.java:137) at com.android.build.gradle.tasks.AndroidProGuardTask$1.run(AndroidProGuardTask.java:113) at com.android.builder.tasks.Job.runTask(Job.java:48) at com.android.build.gradle.tasks.SimpleWorkQueue$EmptyThreadContext.runTask(SimpleWorkQueue.java:41) at com.android.builder.tasks.WorkQueue.run(WorkQueue.java:227) at java.lang.Thread.run(Thread.java:745) :app:dexRelease UP-TO-DATE :app:validateExternalOverrideSigning :app:packageRelease 

And the build process stops with this message:

 Error:Execution failed for task ':app:packageRelease'. > Unable to compute hash of ...\app\build\intermediates\classes-proguard\release\classes.jar 

After several probes, I found a way to remove warnings with these lines in my "proguard-rules.pro":

 -dontwarn com.android.volley.** -dontwarn com.squareup.okhttp.** -dontwarn okio.** 

But the build process is still in error! Does anyone have a workaround for this problem?

Thanks! Davide

+7
android apk android-build android-proguard
source share
2 answers

After several attempts ... here is the solution:

Set up dontwarn first, as Raymond suggested (maybe it's not necessary, but I left it):

 -dontwarn com.google.gson.** -dontwarn java.nio.file.** -dontwarn org.codehaus.mojo.animal_sniffer.** -dontwarn com.squareup.okhttp.internal.huc.** -dontwarn com.android.volley.error.** 

Then configure Proguard to skip my library:

 -keep class com.android.volley.error.** { *; } -keep class com.squareup.okhttp.internal.huc.** { *; } -keep class okio.** { *; } 

And the fact that the compilation was fine, but at runtime the application crashed. Therefore, to avoid this problem, I added the following lines:

 -keep class android.support.design.widget.** { *; } -keep interface android.support.design.widget.** { *; } -dontwarn android.support.design.** 

based on some information found from this stream:

java.lang.RuntimeException: Failed to inflate behavior subclass

With these settings, I can generate a signed APK of my application.

+5
source share

Instead, you should apply dontwarn to the reference class.

For example:

 -dontwarn com.google.gson.** -dontwarn java.nio.file.** 
+2
source share

All Articles