Android - Proguard 未使用 Joda Time jar 文件编译
Posted
技术标签:
【中文标题】Android - Proguard 未使用 Joda Time jar 文件编译【英文标题】:Android - Proguard didn't compile with Joda Time jar file 【发布时间】:2013-07-19 04:55:47 【问题描述】:我在我的android项目中使用了Joda time API,当我导出一个签名的apk时我的项目没有编译,它显示错误“Proguard返回错误代码1。见控制台”,下面是错误日志,
[2013-07-20 00:50:25 - CC] Proguard returned with error code 1. See console
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.DateMidnight: can't find referenced class org.joda.convert.FromString
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.DateTime: can't find referenced class org.joda.convert.FromString
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.DateTimeZone: can't find referenced class org.joda.convert.FromString
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.DateTimeZone: can't find referenced class org.joda.convert.ToString
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.Days: can't find referenced class org.joda.convert.FromString
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.Days: can't find referenced class org.joda.convert.ToString
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.Duration: can't find referenced class org.joda.convert.FromString
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.Hours: can't find referenced class org.joda.convert.FromString
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.Hours: can't find referenced class org.joda.convert.ToString
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.Instant: can't find referenced class org.joda.convert.FromString
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.LocalDate: can't find referenced class org.joda.convert.FromString
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.LocalDate: can't find referenced class org.joda.convert.ToString
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.LocalDateTime: can't find referenced class org.joda.convert.FromString
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.LocalDateTime: can't find referenced class org.joda.convert.ToString
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.LocalTime: can't find referenced class org.joda.convert.FromString
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.LocalTime: can't find referenced class org.joda.convert.ToString
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.Minutes: can't find referenced class org.joda.convert.FromString
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.Minutes: can't find referenced class org.joda.convert.ToString
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.MonthDay: can't find referenced class org.joda.convert.FromString
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.MonthDay: can't find referenced class org.joda.convert.ToString
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.Months: can't find referenced class org.joda.convert.FromString
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.Months: can't find referenced class org.joda.convert.ToString
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.MutableDateTime: can't find referenced class org.joda.convert.FromString
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.MutableDateTime: can't find referenced class org.joda.convert.ToString
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.MutablePeriod: can't find referenced class org.joda.convert.FromString
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.Period: can't find referenced class org.joda.convert.FromString
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.Seconds: can't find referenced class org.joda.convert.FromString
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.Seconds: can't find referenced class org.joda.convert.ToString
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.Weeks: can't find referenced class org.joda.convert.FromString
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.Weeks: can't find referenced class org.joda.convert.ToString
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.YearMonth: can't find referenced class org.joda.convert.FromString
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.YearMonth: can't find referenced class org.joda.convert.ToString
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.Years: can't find referenced class org.joda.convert.FromString
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.Years: can't find referenced class org.joda.convert.ToString
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.base.AbstractDuration: can't find referenced class org.joda.convert.ToString
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.base.AbstractInstant: can't find referenced class org.joda.convert.ToString
[2013-07-20 00:50:25 - CC] Warning: org.joda.time.base.AbstractPeriod: can't find referenced class org.joda.convert.ToString
[2013-07-20 00:50:25 - CC] You should check if you need to specify additional program jars.
[2013-07-20 00:50:25 - CC] Warning: there were 37 unresolved references to classes or interfaces.
[2013-07-20 00:50:25 - CC] You may need to specify additional library jars (using '-libraryjars').
[2013-07-20 00:50:25 - CC] java.io.IOException: Please correct the above warnings first.
[2013-07-20 00:50:25 - CC] at proguard.Initializer.execute(Initializer.java:321)
[2013-07-20 00:50:25 - CC] at proguard.ProGuard.initialize(ProGuard.java:211)
[2013-07-20 00:50:25 - CC] at proguard.ProGuard.execute(ProGuard.java:86)
[2013-07-20 00:50:25 - CC] at proguard.ProGuard.main(ProGuard.java:492)
我的 proguard.cfg 文件看起来像,
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
-keepclasseswithmembernames class *
native <methods>;
-keepclasseswithmembers class *
public <init>(android.content.Context, android.util.AttributeSet);
-keepclasseswithmembers class *
public <init>(android.content.Context, android.util.AttributeSet, int);
-keepclassmembers class * extends android.app.Activity
public void *(android.view.View);
-keepclassmembers enum *
public static **[] values();
public static ** valueOf(java.lang.String);
-keep class * implements android.os.Parcelable
public static final android.os.Parcelable$Creator *;
谁能帮我解决这个问题?我需要发布我的应用程序。 该解决方案将不胜感激。 提前致谢。
【问题讨论】:
【参考方案1】:如果不需要缺少的类,您可以取消警告:
-dontwarn org.joda.convert.**
参见 ProGuard 手册 > 疑难解答 > Warning: can't find referenced class
【讨论】:
嗨@Eric Lafortune,我应该在哪里使用上面的代码。 project.properties 还是 proguard.cfg? 嗨@Eric Lafortune,现在我可以构建了。但它在运行应用程序时在 actionbar sherlock 中显示错误。 您好,现在我可以成功构建和运行 prj。感谢您的支持。我在我的 proguard 文件中添加了 actionbar sherlock 支持代码。 这应该是这个问题的公认答案。 @EricLafortune 为这篇简短而温馨的帖子点赞两个。 在哪里添加dontwarn
行?【参考方案2】:
基于此处的帖子:https://plus.google.com/112998433182673852267/posts/ApBBBjv9szw
实际发生的情况是缺少的“FromString”类是一个注释,它实际上并未作为类文件存在于 joda-time-2.0.jar 中。有人声称 (http://www.scala-lang.org/node/10575) 缺少注释类文件不应该影响编译,这听起来是正确的,但我不知道这是在哪里正式声明的。
您需要将http://joda-convert.sourceforge.net/ 添加到项目的构建路径中。
【讨论】:
嗨@Morrison Chang,我添加了joda-convert-1.3.1 jar文件,仍然存在这个问题。现在警告减少了 31 个。你能帮我解决这个问题吗? @Amarnath 如果是一个不同的问题(警告/错误),你最好用一个不同的问题。否则更新您的问题。 嗨@Morrison Chang,我在下面添加了最后的错误日志作为答案。你能帮我解决这个问题吗? 您应该将其添加为您的问题的一部分。您还同时导出 joda-time 和 joda-convert? 当我删除 joda-time jar 时,它在 DateTime 类中显示错误【参考方案3】:我通过将以下内容添加到我的 build.gradle > 依赖项块来修复它:
dependencies
implementation group: 'org.joda', name: 'joda-convert', version: '2.0.1', classifier: 'classic'
implementation 'joda-time:joda-time:2.9.4'
【讨论】:
以上是关于Android - Proguard 未使用 Joda Time jar 文件编译的主要内容,如果未能解决你的问题,请参考以下文章
使用 Proguard 时未生成 mapping.txt 文件