android proguard, skip jars

2019-04-13 05:50发布

I want to know if it is possible to skip jars in proguard so that it don't obfuscate them... I am trying to do that with this comand: -libraryjars myjar.jar but I keep having problems with my code..

I am trying to export a project that has javamail api for android and the project is supposed to retreive my exchange emails using imaps protocol...

I am using a trust manager to pass the certificate validation (because I have self signed certificate on my exc server). If I compile and run the app without exporting it, everything works fine. If I export the app I am getting the invalid certificate error.

In my activity I pass the SSLSocketFactory (the one that skips the cert validation) on a Property object :

props.setProperty("mail.store.protocol", "imaps");
props.setProperty("mail.imaps.socketFactory.class", "mail.utils.DummySSLSocketFactory");  

So I think the problem could be somewhere in the javamail jar but I don't know how to let all classes from the jar to be skipped by proguard...

1条回答
戒情不戒烟
2楼-- · 2019-04-13 06:33

In a general ProGuard configuration, specifying -libraryjars would be the preferred solution indeed.

In the Android build script, jars in the libs directory are already added automatically as -injars, which makes this less convenient. You can still specify to preserve all code though, e.g. all public classes, fields, and methods in the library:

-keep public class mail.** {
  public *;
}

You may be able to refine the configuration by only keeping relevant classes, e.g.

-keep class mail.imaps.socketFactory
-keep class mail.utils.DummySSLSocketFactory
...

Without knowing the internal implementation of the library, this refinement will probably require some experimentation.

查看更多
登录 后发表回答