问题
In my app I send emails to some specific address, it all works fine, but when it comes to obfuscation, shrinking, etc with ProGuard it fails
I've tried adding some ProGuard rules, which didn't work
That's my ProGuard
-keepclassmembernames class com.sun.mail.imap
2019-08-08 14:29:26.811 11724-12675/? E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #5
Process: com.redegrow.besttaxi, PID: 11724
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:354)
...
Caused by: java.util.ServiceConfigurationError: e.b.r: Provider com.sun.mail.imap.IMAPProvider not found
at java.util.ServiceLoader.fail(ServiceLoader.java:233)
at java.util.ServiceLoader.access$100(ServiceLoader.java:183)
at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:373)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:416)
at java.util.ServiceLoader$1.next(ServiceLoader.java:494)
...
Caused by: java.lang.ClassNotFoundException: com.sun.mail.imap.IMAPProvider
...
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.sun.mail.imap.IMAPProvider" on path: DexPathList[[zip file "/data/app/com.redegrow.besttaxi-_Kl-yVNRgbmmwzLXuKKmWQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.redegrow.besttaxi-_Kl-yVNRgbmmwzLXuKKmWQ==/lib/arm64, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
...
回答1:
Well, I found the solution. It's not great, but at least it works
-keep class com.sun.mail.imap.IMAPProvider
-keep class com.sun.mail.imap.IMAPSSLProvider
-keep class com.sun.mail.smtp.** {*;}
回答2:
Using keepclassmembernames
for a class tells ProGuard not to obfuscate the class members, but does not have an effect on the class itself. So ProGuard does its job and changes the class name.
So if you want to prevent ProGuard from obfuscating the class name you should use keepnames
instead.
To prevent both the obfuscation and shrinking (which is removing in case of not being used), you should use keepclassmembers
if you want to target only the class members and keep
to target the class itself and its members.
来源:https://stackoverflow.com/questions/57409930/proguard-removes-com-sun-mail-imap-imapprovider