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 *
Related
I'm building an Android app using Android Gradle Plugin 4.1.0 and Gradle 6.5.1. In my build.gradle file the flag minifyEnabled has the value true. This is my proguard-rules.pro file:
#rx
-dontwarn rx.**
-keep class rx.** { *; }
#retrofit / okhttp
-dontwarn retrofit.**
-keep class retrofit.** { *; }
-keep class okio.** { *; }
-keep class com.squareup.okhttp.** { *; }
-keep interface com.squareup.okhttp.** { *; }
-dontwarn com.squareup.okhttp.**
-dontwarn okhttp3.internal.platform.**
-dontwarn okio.**
-dontwarn org.conscrypt.**
#gson
-keepattributes SerializedName
-keep class com.google.gson.** { *; }
-keep class sun.misc.Unsafe { *; }
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer
-keepclassmembers enum * { *; }
-keepattributes Signature
-keepattributes Exceptions
-keepattributes *Annotation*
-dontwarn javax.annotation.Nullable
-dontwarn javax.annotation.ParametersAreNonnullByDefault
-dontwarn javax.annotation.concurrent.GuardedBy
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
#guava
-dontwarn afu.org.checkerframework.checker.formatter.**
-dontwarn afu.org.checkerframework.checker.nullness.**
-dontwarn afu.org.checkerframework.checker.regex.**
-dontwarn afu.org.checkerframework.checker.units.**
-keep class * implements ru.surfstudio.android.network.Transformable
-keep class * implements ru.surfstudio.android.network.response.BaseResponse
-dontwarn com.bumptech.glide.**
#firebase crashlytics
-printmapping mapping.txt
-keepattributes *Annotation*,SourceFile,LineNumberTable
-keep public class * extends java.lang.Exception
-keep class com.google.firebase.crashlytics.** { *; }
-dontwarn com.google.firebase.crashlytics.**
#kotlin-reflect
#https://stackoverflow.com/questions/45871970/kotlin-reflect-proguard-smallsortedmap
-dontwarn kotlin.reflect.jvm.internal.**
#Cashoff javascript interface
-keep class ru.sbi.android.f_analytics.analytics.CashoffInteface { *; }
-dontwarn ru.sbi.android.f_main.R$id
-keep class ru.sbi.android.ui.navigation.MainTabType
#Cross-feature navigation keeps
-keep interface ru.sbi.android.ui.fragment.CrossFeatureFragment {*;}
-keep class * implements ru.sbi.android.ui.fragment.CrossFeatureFragment
#android standard
-keep class ru.surfstudio.android.rx.extension.ConsumerSafe { *; }
-keep class ru.surfstudio.android.rx.extension.ActionSafe { *; }
#AndroidPdfViewer
-keep class com.shockwave.pdfium.util.Size
#firebase
-dontwarn com.google.firebase.messaging.**
#android material
-keep class com.google.android.material.** { *; }
-dontwarn com.google.android.material.**
#Если вы хотите применять новый API Google API для отслеживания инициаторов
-dontwarn com.android.installreferrer.com.android.installreferrer
-ignorewarnings
I see lots of minifyReleaseWithR8 tasks being executed during the build.
But when I'm decompiling the resulting APK using apktool I see that all the package, class, methods names are the same as in my Android Studio. How can I understand why R8 doesn't obfuscate the code?
You have a keep rule for every single class you use in your app. If you have a -keep rule matching a class it will be kept and not obfuscated. For obfuscation to rename items (classes/fields and methods) that either have to not be matched by a keep rule (or matched by a keep rule with modifier allowobfuscation).
Keep rules are only required for items which are looked up through reflection, so you will have to trim down your rules to a much smaller set. I suggest that you start out by an empty proguard-rules.pro and only get what getDefaultProguardFile('proguard-android-optimize.txt') generates (like here). Then your app might not work, but then you can figure out what is going wrong and start adding additional rules. One way to start there is to only keep the classes in you own application package (-keep class ru.sbi.android.** { *; }), as libraries normally does not need keep rules, and then try to trim that further.
Please take a look at Shrink, obfuscate, and optimize your app as well.
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.** {*;}
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 :)
I am facing issue while obfuscating my app using proguard.
I am able to use proguard and it is generating mapping.txt when i am creating a new application in android studio, however mapping.txt is not being generated when i am trying to use proguard on a project migrated from eclipse to android studio.
Following is my proguard-rules.pro file
-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 javax.mail.internet.** {*;}
-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 javax.ws.rs.** { *; }
-keep class mailcap.** {*;}
-keep class mimetypes.** {*;}
-keep class myjava.awt.datatransfer.** {*;}
-keep class org.apache.harmony.awt.** {*;}
-keep class org.apache.harmony.misc.** {*;}
-dontwarn com.fasterxml.jackson.**
-dontwarn java.awt.**
-dontwarn java.beans.Beans
-dontwarn javax.security.**
-ignorewarnings
-printmapping build/outputs/mapping/release/mapping.txt
try removing following lines from your file:
-dontobfuscate
.
.
.
-printmapping build/outputs/mapping/release/mapping.txt
first line seems to disable obfuscation and last one seems to copy mapping file on a location other then default.
Remove -dontobfuscate from the whole project and you will get your mapping file generated under build/outputs/mapping/..
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.** {*;}