如何阻止 proguard 在 Android 上删除 joda 时间资源 [英] How to stop proguard from removing joda time resources on Android

查看:26
本文介绍了如何阻止 proguard 在 Android 上删除 joda 时间资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 Android 应用程序中使用 ProGuard 和 Joda Time(当然,我使用为 Android 优化的版本:https://github.com/dlew/joda-time-android).我遇到了打开优化和混淆的问题,当我尝试使用 PeriodFormat 时出现错误:

I use ProGuard and Joda Time in my Android application (of course, I use a version optimized for Android: https://github.com/dlew/joda-time-android). I ran into the problem that with optimization and obfuscation turned on, I get an error when I try to use PeriodFormat:

java.util.MissingResourceException: can't find resource for bundle java.util.PropertyResourceBundle, key PeriodFormat.space

我对比了有proguard和没有proguard的APK内容,发现非优化版的org/joda/time/format目录有15个属性文件,优化版只有9个.在这些文件中我看到了 PeriodFormat.space 键,所以毫无疑问是这些文件丢失引起的异常.

I compared the contents of the APK when building with and without proguard and saw that the org/joda/time/format directory in the non-optimized version contains 15 properties files, and only 9 in the optimized version. In these files I saw the PeriodFormat.space keys, so leaves no doubt that the exception caused by the loss of these files.

如何配置proguard,让这个目录的内容在没有任何优化的情况下传输到优化后的APK?

How to configure proguard so that the contents of this directory are transferred to the optimized APK without any optimizations?

我已经对 Joda Time 使用了以下规则:

I already use the following rules for Joda Time:

-dontwarn org.joda.convert.**
-dontwarn org.joda.time.**
-keep class org.joda.** { *; }
-keep interface org.joda.** { *; }
-keepdirectories org.joda.**

然而,它们还不够,因为文件仍然消失了.

However, they are not enough, because the files still disappear.

推荐答案

java.util.MissingResourceException:找不到包的资源java.util.PropertyResourceBundle, key PeriodFormat.space

java.util.MissingResourceException: can't find resource for bundle java.util.PropertyResourceBundle, key PeriodFormat.space

不要

-keep class org.joda.** { *; }
-keep interface org.joda.** { *; }

 -keep class org.joda.time.** { *; }
 -keep interface org.joda.time.** { *; }

您的proguard 将是

-dontwarn org.joda.convert.**
-dontwarn org.joda.time.**
-keep class org.joda.time.** { *; }
-keep interface org.joda.time.** { *; }

阅读-keep options.

这篇关于如何阻止 proguard 在 Android 上删除 joda 时间资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆