Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android: proguard obfuscating problem

I made a mail client with the use of javamail api for android and the app runs well in emulator or device... Now I want to export the project using eclipse but I got the following errors:

     Warning: org.apache.harmony.awt.datatransfer.DataProxy: can't find superclass or interface java.awt.datatransfer.Transferable
 Warning: org.apache.harmony.awt.datatransfer.NativeClipboard: can't find superclass or interface java.awt.datatransfer.Clipboard
 Warning: javax.activation.CommandInfo: can't find referenced class java.beans.Beans
 Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.Sasl
 Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.SaslClient
 Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.SaslException
 Warning: org.apache.harmony.awt.datatransfer.DragSourceEventProxy: can't find referenced class java.awt.Point
 Warning: org.apache.harmony.awt.datatransfer.DragSourceEventProxy: can't find referenced class java.awt.dnd.DragSourceContext
 Warning: org.apache.harmony.awt.datatransfer.DragSourceEventProxy: can't find referenced class java.awt.dnd.DragSourceEvent

As I can see the javamail api uses java.awt and javax.security libs... how can I add them in my project so I can export my project and obfuscate it?

Thank you very much!

UPDATE:

I tried to import the jre library in my project and those errors are gone but new ones apeared:

Proguard returned with error code 1. See console
 Note: there were 4243 duplicate class definitions.
 Warning: library class com.sun.xml.internal.messaging.saaj.soap.FastInfosetDataContentHandler extends or implements program class javax.activation.DataContentHandler
 Warning: library class com.sun.xml.internal.ws.encoding.XmlDataContentHandler extends or implements program class javax.activation.DataContentHandler
 Warning: library class com.sun.xml.internal.messaging.saaj.soap.MessageImpl$1 extends or implements program class javax.activation.DataSource
 Warning: library class com.sun.xml.internal.ws.encoding.StringDataContentHandler extends or implements program class javax.activation.DataContentHandler 

What can I do?

like image 563
Cata Avatar asked Mar 22 '11 08:03

Cata


People also ask

Does obfuscation reduce file size?

Obfuscation: shortens the name of classes and members, which results in reduced DEX file sizes.

How do I debug a ProGuard error?

To debug Proguard/R8 configuration, navigate to app\build\outputs\mapping\release. There we can see the following files: configuration. txt – merged file with all configurations – from the app, default Android, AAPT, all the libraries, etc.

Is ProGuard deprecated?

enableR8 setting itself is deprecated, causing these deprecation warnings. If you have android. enableR8 = false to use proguard for optimiation and obfuscation, consider migrating to R8 instead.

How do I obfuscate my library on Android?

In order to obfuscate your library what you need to do is: Make sure gradle settings for lib module state minifyEnabled true . run ./gradlew assemble{flavor}Release.


2 Answers

The listed java classes are not part of the Android runtime. The cleanest solution would be to remove the classes that reference them from the javamail library, because they can never work in this environment.

In general, you could also filter them out in your ProGuard configuration, but the Android build script doesn't support filters.

As a simple alternative, you can suppress the warnings:

-dontwarn java.awt.**,javax.security.**,java.beans.**

ProGuard will then proceed without complaining.

like image 192
Eric Lafortune Avatar answered Oct 02 '22 01:10

Eric Lafortune


I have solved the problem by adding the jre library in the project and ten adding this comand to proguard.cfg file:

-libraryjars <java.home>/lib/rt.jar(java/**,javax/security/**,javax/activation/**)

hope this help somebody :P

like image 44
Cata Avatar answered Oct 02 '22 01:10

Cata