Has anybody tried using the Server-Sent Events client from org.glassfish.jersey.media:jersey-media-sse:2.22.1on Android while proguard is enabled?
For some reason it doesn't get past:
Client client = ClientBuilder.newBuilder()
.register(SseFeature.class).build();
without giving any errors or warnings.
Right now I've tried setting the following proguard rules to no avail:
-keep class org.glassfish.jersey.media.** {*;}
-keep class javax.** {*;}
So I figured it out by trying different stuff. The following is the rules I used:
-dontwarn org.glassfish.***
-keep class org.glassfish.** {*;}
-keep interface org.glassfish.** {*;}
-keep class * implements org.glassfish.** {*;}
-keepattributes Signature,*Annotation*,EnclosingMethod
-keep class javax.** {*;}
-keep interface javax.** {*;}
-keep class * implements javax.** {*;}
-keepattributes Exceptions, InnerClasses, Signature, Deprecated, *Annotation*, EnclosingMethod
-dontoptimize
mind you, I have other rules for proguard as well that may contribute to the situation without me knowing, but these are the changes that I had to make to get it working :)
Related
I am getting this error after trying to generate my apk
Warning:com.sun.mail.handlers.handler_base: can't find referenced method 'boolean equals(java.awt.datatransfer.DataFlavor)' in program class javax.activation.ActivationDataFlavor
i can run my code to a device but not generating an APK
Try to add this in the Proguard part of the gradle file:
-dontwarn java.awt.**,javax.activation.**,java.beans.**
As #SilSur comments, the chosen solution only hides the Proguard warning but doesn't prevent runtime errors due to missing classes. After some trial-error I found that this Proguard configuration works OK preventing any runtime problems:
# JavaMail
-dontwarn java.awt.**
-dontwarn javax.activation.**
-dontwarn java.beans.**
-keep class javamail.** {*;}
-keep class javax.mail.** {*;}
-keep class javax.activation.** {*;}
-keep class com.sun.mail.** {*;}
-keep class mailcap.** {*;}
-keep class mimetypes.** {*;}
-keep class myjava.awt.datatransfer.** {*;}
-keep class org.apache.harmony.awt.** {*;}
-keep class org.apache.harmony.misc.** {*;}
I'm using Amazon mobile ads (Just com.amazon.device.ads.InterstitialAd ad format).
What should I include in the Proguard file?
There is documentation on Proguard for in-app-purchases, but not for mobile ads.
Amazon stated in 2013 that they were fixing the proguard issue. So it should have been fixed. if you are still having errors try putting this in your proguard
-keep class com.amazon.device.ads.** { *; }
-keep class **.R { }
-keep class **.R$* { }
-keepattributes *Annotation*
-dontwarn org.apache.commons.**
-dontwarn com.amazon.** -keep class org.apache.** {*;}
-keep class com.amazon.** {*;}
I import crosswalk in my app. To keep the crosswalk code, I add this in proguard-project.txt:
-dontwarn org.chromium.**
-dontwarn org.xwalk.core.**
-keep class com.google.common.** {*;}
-keep class com.googlecode.eyesfree.braille.** {*;}
-keep class javax.annotation.** {*;}
-keep class org.chromium.** {*;}
-keep class org.xwalk.core.** {*;}
But, it seems wrong. Who can help me? Thanks very much!
found this:
-keep class org.xwalk.core.** {
*;
}
-keep class org.chromium.** {
*;
}
-keepattributes **
from here:
https://crosswalk-project.org/documentation/about/faq.html
You need add another statement:
-keepattributes *
First off, i've already to referred to a similar post, Android, javamail and proguard
The solution mentioned was to explicitly keep the following in proguard-project.txt:
-dontwarn java.awt.**
-dontwarn java.beans.Beans
-dontwarn javax.security.**
-keep class javamail.** {*;}
-keep class javax.mail.** {*;}
-keep class javax.activation.** {*;}
-keep class com.sun.mail.dsn.** {*;}
-keep class com.sun.mail.handlers.** {*;}
-keep class com.sun.mail.smtp.** {*;}
-keep class com.sun.mail.util.** {*;}
-keep class mailcap.** {*;}
-keep class mimetypes.** {*;}
-keep class myjava.awt.datatransfer.** {*;}
-keep class org.apache.harmony.awt.** {*;}
-keep class org.apache.harmony.misc.** {*;}
At first sight, this seemed to work, as it compiled without any warnings. However, it fails at reading the message content and just skips right over it. I've tried the following:
-includelibraryjars explicitly naming the 3 jar files required for javamail.
-removed the jars as an external library, following the new libs/ include format.
-maintained the default android settings in proguard-android.txt
-followed the troubleshooting guide in the proguard faq.
-started a new project and copied over the source files to it.
-tried various proguard options, including -dontshrink, keepnames, etc
-obsessive project/clean
After a few hours of frustration, here's what i found that seemed to work:
-dontobfuscate
-dontshrink
-keepdirectories
-keeppackagenames javax.mail.**
-keeppackagenames javax.activation.**
-keeppackagenames com.sun.mail.**
-keeppackagenames myjava.**
-keeppackagenames org.apache.harmony.**
-keeppackagenames mailcap.**
-keeppackagenames mimetypes.**
-keep class javamail.** {*;}
-keep class javax.mail.** {*;}
-keep class javax.activation.** {*;}
-keep class com.sun.mail.dsn.** {*;}
-keep class com.sun.mail.handlers.** {*;}
-keep class com.sun.mail.smtp.** {*;}
-keep class com.sun.mail.util.** {*;}
-keep class mailcap.** {*;}
-keep class mimetypes.** {*;}
-keep class myjava.awt.datatransfer.** {*;}
-keep class org.apache.harmony.awt.** {*;}
-keep class org.apache.harmony.misc.** {*;}
-dontwarn java.awt.**
-dontwarn java.beans.Beans
-dontwarn javax.security.**
Of course that's absurd because i'm turning on -dontobfuscate and -dontshrink. Any proguard and javamail gurus have a solution to this? I'm ADT17, using 2.1(api7) for the build. If i could exclude the jars entirely from the process maybe? Any advice will be a godsend at this point.
Problem solved. I've posted the solution here for anyone having issues with the other solution mentioned in the link above.
Because i was using a helper class with javamail (Mail.java), i needed to include that class as a -keep so that it would work. I edited the solution provided at Android, javamail and proguard to include the helper class, since many use this and the other solution may fail horribly without it.
Put this in your proguard-project.txt file. I used the default android settings otherwise.
-dontshrink
-keep class javax.** {*;}
-keep class com.sun.** {*;}
-keep class myjava.** {*;}
-keep class org.apache.harmony.** {*;}
-keep public class Mail {*;}
-dontwarn java.awt.**
-dontwarn java.beans.Beans
-dontwarn javax.security.**
In my case the javax.activation was causing the following problem:
Warning: com.sun.mail.handlers.handler_base: can't find referenced method 'boolean equals(java.awt.datatransfer.DataFlavor)' in program class javax.activation.ActivationDataFlavor
So i had to add -dontwarn javax.activation.** in ThumbsDP solution. So all together are the below additions on proguard-rules that did the trick to me:
-dontshrink
-keep class javax.** {*;}
-keep class com.sun.** {*;}
-keep class myjava.** {*;}
-keep class org.apache.harmony.** {*;}
-keep public class Mail {*;}
-dontwarn java.awt.**
-dontwarn java.beans.Beans
-dontwarn javax.security.**
-dontwarn javax.activation.**
The existing solution were a bit far fetched for my taste. :)
I think this is a better solution, put inside proguard-rules.pro file:
-libraryjars libs/mail.jar
-libraryjars libs/activation.jar
-libraryjars libs/additionnal.jar
As a bonus
After solving proguard issue, I also did get the following exception:
"com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not Found"
To solve it put also the following line:
-keep class com.google.** {*;}
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.