Android的,JavaMail的和ProGuard的Android、JavaMail、ProGuard

2023-09-12 10:22:12 作者:不羁的心

我想使用JavaMail在我的Andr​​oid应用程序,但ProGuard的抱怨有关的东西整​​个负载,它无法找到。我曾尝试,我发现,当搜寻互联网的各种补救措施,但似乎没有任何工作。有没有人有这个东西的工作?谢谢你。

I am trying to use javamail in my Android app, but proguard complains about a whole load of stuff that it cannot find. I have tried various remedies that I have found while searching the internet, but nothing seems to work. Has anyone got this thing working? Thanks.

我增加了一些-dontwarn命令到defauly proguard.cfg,并成功地消除所有的警告信息,除了这一个:

I have added some -dontwarn commands to the defauly proguard.cfg, and succeeded in eliminating all of the warning messages except this one:

Warning: org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class [Ljava.awt.datatransfer.DataFlavor;

此警告甚至不是在相同的格式,因为所有其他的。

This warning is not even in the same format as all the others.

推荐答案

我现在用的是2.1的SDK,这可能会有所作为。我也有一个相当复杂的电子邮件。但是,我已经整理,现在,通过升级到ProGuard的4.6并添加以下行到我的ProGuard,CFG:

I am using the 2.1 SDK, which might make a difference. I also have a fairly complex email. But I have sorted it now, by upgrading to proguard 4.6 and adding the following lines to my proguard,cfg:

-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.** {*;}

线的最后一组是不平凡的。我通过运行焦油TF命令对每个罐子的JavaMail包获得它。

The last group of lines is non-trivial. I obtained it by running tar tf commands against each of the jars in the javamail package.

更新SDK 17

Android SDK中17介绍了这罐装载方式的一些变化。如果您有使用外部罐项目,升级到SDK 17或以后可能会打破它。为了解决这个问题,选择项目>属性> Java构建路径>订单和出口从菜单中,并留下所用的JavaMail三个罐子的检查框。这确保了罐子得到出口到靶的构建。如果没有这个功能,在项目仍然会建造,但JavaMail的将不再工作,ProGuard的也将失败。这是不会 ProGuard的问题都没有。这是一个Android SDK的问题。无需更改proguard.cfg是必需的。

Android SDK 17 introduces some changes in the way that jars are loaded. If you have a project that uses external jars, upgrading to SDK 17 or beyond will probably break it. To fix this, select Project > Properties > Java Build Path > Order and Export from the menu, and check the boxes to left of the three jars used by javamail. This ensures that the jars get exported to the target build. Without this fix, the project will still build, but javamail will no longer work and proguard will also fail. This is not a proguard issue at all. It is an Android SDK issue. No changes to proguard.cfg are required.

升级的SDK的另一个后果是,它不再需要手动升级proguard的

Another consequence of upgrading the SDK is that it is no longer necessary to upgrade proguard manually.