Android、javamail 和 proguard
我试图在我的 Android 应用程序中使用 javamail,但是 proguard 抱怨它无法找到一大堆东西。我尝试了在互联网上搜索时找到的各种补救措施,但似乎没有任何效果。有人让这东西工作吗?谢谢。
我在默认的 proguard.cfg 中添加了一些 -dontwarn 命令,并成功消除了除此之外的所有警告消息:
Warning: org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class [Ljava.awt.datatransfer.DataFlavor;
此警告的格式甚至与所有其他警告的格式不同。
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我正在使用 2.1 SDK,这可能会有所不同。我还有一封相当复杂的电子邮件。但我现在已经对其进行了排序,升级到 proguard 4.6 并将以下行添加到我的 proguard,cfg 中:
最后一组行非常重要。我通过对 javamail 包中的每个 jar 运行 tar tf 命令来获得它。
SDK 17 更新
Android SDK 17 引入了 jar 加载方式的一些变化。如果您有一个使用外部 jar 的项目,升级到 SDK 17 或更高版本可能会破坏它。要解决此问题,请选择“项目”>“属性> Java 构建路径 >从菜单中订购和导出,然后选中 javamail 使用的三个 jar 左侧的框。这确保了 jar 被导出到目标构建。如果没有此修复,项目仍将构建,但 javamail 将不再工作,并且 proguard 也会失败。这根本不是一个 proguard 问题。这是Android SDK的问题。无需更改 proguard.cfg。
升级 SDK 的另一个后果是不再需要手动升级 proguard。
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:
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.
Update for SDK 17
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.
Another consequence of upgrading the SDK is that it is no longer necessary to upgrade proguard manually.
比照。 ProGuard 手册 >故障排除>>警告:找不到超类或接口。
今天更详细的类似问题和解答: stackoverflow 上的一个 和 ProGuard 帮助论坛中的一个。
乱码错误信息“[Ljava.awt.datatransfer.DataFlavor;”已在 ProGuard 4.6 中解决。您只需替换 Android SDK 中的 proguard.jar 即可。或者,您可以通过列出引用类而不是引用的类来解决该问题:“-dontwarn org.apache.harmony.awt.datatransfer.DataProxy”。
Cfr. ProGuard manual > Troubleshooting > Warning: can't find superclass or interface.
More detailed similar questions and answers today: one on stackoverflow and one in ProGuard's help forum.
The garbled error message "[Ljava.awt.datatransfer.DataFlavor;" has been solved in ProGuard 4.6. You can simply replace proguard.jar in the Android SDK. Alternatively, you can work around the problem by listing the referencing class instead of the referenced class: "-dontwarn org.apache.harmony.awt.datatransfer.DataProxy".
您是否使用此项目:javamail-android ?
它对我来说没有任何问题(诚然使用 2.3 SDK 中的默认 Proguard 设置),所以问题可能是标准 javamail 需要 Android 中不存在的 AWT 类。
关联的示例代码位于在 Android 中无需用户干预(无意图)发送电子邮件
Are you using this project: javamail-android ?
It worked for me without a single hitch (admittedly using the default Proguard settings in the 2.3 SDK) so the problem might be that the standard javamail requires AWT classes that aren't present in Android.
The associated sample code is at Sending Emails without User Intervention (no Intents) in Android