I'm using Picasso and Retrofit together in my app. Everything works perfectly in debug version, but whenever I try to generate a signed apk I get something like this Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'
I searched for a while and tried using -dontwarn retrofit.* in proguard-rules.pro
This isn't working
Picasso proguard configuration
-dontwarn com.squareup.okhttp.**
Retrofit proguard configuration
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions
-keepclasseswithmembers class * {
#retrofit2.http.* <methods>;
}
Related
I turned proguard on in my android project and got the warning below. Searched on Google but couldn't find much info.
Warning:retrofit.Platform$Java8: can't find referenced class
org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
I've put the retrofit2 proguard rules in my project.
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions
-keepclasseswithmembers class * {
#retrofit2.http.* <methods>;
}
Use following proguard rules for Retrofit 2.3.0 and okhttp 3.8.0
-dontnote retrofit2.Platform
-dontwarn retrofit2.Platform$Java8adapters.
-keepattributes Signature
-keepattributes Exceptions
-dontwarn org.xmlpull.v1.**
-dontwarn okhttp3.**
-dontwarn okio.**
-dontwarn javax.annotation.**
change it like this:
-dontwarn okio.**
-dontwarn retrofit2.Platform$Java8
Retrofit page has noted about this proguard build,when running on Java 8 VMs:
Why this happens?
Reason is:
Compiler tries to reference Java 8 classes,When u don't mention it through Proguard,After u explicitly mention it,Java 8 classes won't be used.
For example
Package java.nio.* of Java 8 isn't available on Android and will be never called
I used retrofit 2, okhttp and moshi-jsonapi in android project.
Debug Build apk and application is correct, But I have error in build signed apk (release mode), I used dontwarn in proguard-rules.pro for pass the build signed apk, But my application in signed mode every time run onFailure from Callback.
Throwable message:
platform java.util.LinkedHashMap<java.lang.String,a.a.a.j> annotated [] requires explicit JsonAdapter to be registered
I never have used LinkedHashMap!
When useing minifyEnabled false signed apk and application is correct But it's not secure solution.
proguard-rules.pro:
-dontwarn okio.**
-keep class okio.** { *; }
-dontwarn retrofit2.**
-dontwarn org.codehaus.mojo.**
-dontnote retrofit2.Platform
-dontnote retrofit2.Platform$IOS$MainThreadExecutor
-dontwarn retrofit2.Platform$Java8
-keep class retrofit2.** { *; }
-keepattributes Exceptions
-keepattributes Signature
-keepattributes RuntimeVisibleAnnotations
-keepattributes RuntimeInvisibleAnnotations
-keepattributes RuntimeVisibleParameterAnnotations
-keepattributes RuntimeInvisibleParameterAnnotations
-keepattributes EnclosingMethod
-keepclasseswithmembers class * {
#retrofit2.http.* <methods>;
}
-keepclasseswithmembers interface * {
#retrofit2.* <methods>;
}
You may need to keep your Model attributes unminified. If all the models are in one package then you can use,
-keepclassmembers class com.example.model.** { <fields>; }
or you have to use like the following
#SerializedName("name")
public String name;
I could not reply on comment with the following code...so just editing the answer.. do you mind trying this
-keepclassmembers class ** {
#com.squareup.moshi.FromJson *;
#com.squareup.moshi.ToJson *;}
Resolved it after use this code in proguard:
-keepclassmembers public abstract class moe.banana.jsonapi2.** {
*;
}
I am using IBM's mobilefirst worklight version 6.3 for push notification. Everything works fine when i dont apply proguard.
When i apply proguard and run the build while subscribing for the push notification only i get the following exception.
java.lang.RuntimeException: Failed to find the icon resource. Add the icon file under the /res/drawable folder.
I have the push.png named file in the drawable folder.
Any suggestions on how to handle that on the proguard or is it a worklights bug?
had the same issue with another third party library but it was resolved when i added keep class com.classname.** {*;} i did the same for worklight as well -keep class com.worklight.** {*;} but it is of no use.
below is the proguard configuration that i have used
-keepclassmembers class * {
#android.webkit.JavascriptInterface <methods>;
}
-keep class com.google.gson.Gson
-keep class com.billdesk.** {*;}
-keep public class com.worklight.** {*;}
-dontwarn com.worklight.**
-dontwarn com.auth0.jwt.**
-dontwarn com.squareup.picasso.**
-dontwarn com.viewpagerindicator.**
-dontwarn org.bouncycastle.**
MobileFirst 6.3 does not officially support obfuscation using Proguard.
Even so, an Android project obfuscated using Proguard works fine without issues in most cases.
I am not able to recreate the issue you mention.I tested the MFP 6.3 Eventsource notifications sample after obfuscating with Proguard and the application worked fine. No runtime exceptions were seen.
Android SDK Tools : 25.1.1
Target API Level : 19
Proguard version : 4.7
To begin with:
Ensure that push.png is present in all drawable folders and not just the generic one.
Check the proguard obfusction logs to see if "push.png" is being crunched in all folders and look for error messages.
Modify the proguard configuration to contain-
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keepattributes InnerClasses
-keep class **.R
-keep class **.R$* {
<fields>;
}
-keep class org.apache.cordova.** { *; }
-keep public class * extends org.apache.cordova.CordovaPlugin
-keep class com.worklight.androidgap.push.** { *; }
-keep class com.worklight.wlclient.push.** { *; }
-keep class com.worklight.common.security.AppAuthenticityToken { *; }
-keep class com.google.** { *;}
-dontwarn com.google.common.**
-dontwarn com.google.ads.**
-dontwarn com.worklight.androidgap.push.GCMIntentService
-dontwarn com.worklight.androidgap.plugin.WLInitializationPlugin
-dontwarn com.worklight.wlclient.push.GCMIntentService
-dontwarn org.bouncycastle.**
-dontwarn com.worklight.nativeandroid.common.WLUtils
-dontwarn com.worklight.wlclient.push.WLBroadcastReceiver
-dontwarn com.worklight.wlclient.push.common.*
-dontwarn com.worklight.wlclient.api.WLPush
Hi i am developing an app with Javacv. The app works fine until i proguard the build. After proguarding, the app crashes at the place of jni function call.
-dontshrink
-dontoptimize
-dontpreverify
-dontwarn android.support.**
-keep class com.googlecode.javacv.**
-dontwarn com.googlecode.javacv.**
-keep class com.googlecode.javacpp.**
-dontwarn com.googlecode.javacpp.**
-keepclasseswithmembernames class * {
native <methods>;
}
-keepattributes *Annotation*
I can't find any answer that solves my problem. I am getting NoSuchMethodError. Anybody help me. I am using the latest version of Javacv library.
You have to keep your native methods (which you're already doing), as well as the Java methods called from native code.
You can keep all javacv and javacpp methods like so:
-keep class com.googlecode.javacv.**{ *; }
-keepclassmembers class com.googlecode.javacv.** {
<methods>;
}
-keep class com.googlecode.javacpp.**{ *; }
-keepclassmembers class com.googlecode.javacpp.** {
<methods>;
}
Also, if you want to cut down on warnings in the build output:
-dontwarn com.googlecode.javacv.**, com.googlecode.javacpp.**
-dontnote com.googlecode.javacv.**, com.googlecode.javacpp.**
I want to use Proguard mainly for obfuscation reasons.
My problem is that I have three libraries, Twitter4J and two signpost libraries. These libraries caused errors when I tried to create an signed APK. To get over this I put the following in the proguard.config file...
-dontwarn org.apache.commons.codec.binary.**
-dontwarn org.slf4j.**
-dontwarn com.sun.syndication.io.**
-dontwarn com.sun.syndication.feed.synd.*
While this got rid of the errors in the console, when i loaded my signed APK onto my mobile phone it instantly crashed. The DDMS said this was due to a class not found in Twitter4J.
Getting rid of the "dontwarns" above did not help. Neither did adding dontshrink dontoptimise.
I would like Proguard to completely ignore the libraries (as they are open source anyway). Is this possible?
Try this:
-keep class javax.** { *; }
-keep class org.** { *; }
-keep class twitter4j.** { *; }
Cf post from #CaspNZ:
Android Proguard with external jar
You should be able to add to the proguard.cfg the following lines to exclude all classes within a package (and subpackages)
-keep class org.apache.commons.codec.binary.**
-keep interface org.apache.commons.codec.binary.**
-keep enum org.apache.commons.codec.binary.**
-keep class org.slf4j.**
-keep interface org.slf4j.**
-keep enum org.slf4j.**
-keep class com.sun.syndication.io.**
-keep interface com.sun.syndication.io.**
-keep enum com.sun.syndication.io.**
-keep class com.sun.syndication.feed.synd.**
-keep interface com.sun.syndication.feed.synd.**
-keep enum com.sun.syndication.feed.synd.**
I'd like to add that you should sync your project with Gradle files after adding proguard rules, otherwise they may not work.