简体   繁体   English

使用Joda Time时,无法生成带有proguard的签名APK

[英]Unable to generate signed APK with proguard enabled when Joda Time is used

I tried to build a signed APK. 我试图建立一个签名的APK。 I am also using proguard . 我也在使用proguard In my application I used JodaTime for some purposes. 在我的应用程序中,我将JodaTime用于某些目的。 I used joda-time-2.7.jar in there. 我在那里使用了joda-time-2.7.jar First I could get a signed APK without enabling proguard , there were no errors. 首先我可以在没有启用proguard的情况下获得已签名的APK,没有错误。 Then I enabled proguard and tried to generate the APK but I it generated errors. 然后我启用了proguard并尝试生成APK但我生成了错误。 Below are the errors generated. 以下是生成的错误。

Warning:org.joda.time.LocalDateTime: can't find referenced class org.joda.convert.ToString
Warning:org.joda.time.LocalTime: can't find referenced class org.joda.convert.FromString
Warning:org.joda.time.LocalTime: can't find referenced class org.joda.convert.ToString
Warning:org.joda.time.Minutes: can't find referenced class org.joda.convert.FromString
Warning:org.joda.time.Minutes: can't find referenced class org.joda.convert.ToString
Warning:org.joda.time.MonthDay: can't find referenced class org.joda.convert.FromString
Warning:org.joda.time.MonthDay: can't find referenced class org.joda.convert.ToString
Warning:org.joda.time.Months: can't find referenced class org.joda.convert.FromString
Warning:org.joda.time.Months: can't find referenced class org.joda.convert.ToString
Warning:org.joda.time.MutableDateTime: can't find referenced class org.joda.convert.FromString
Warning:org.joda.time.MutablePeriod: can't find referenced class org.joda.convert.FromString
Warning:org.joda.time.Period: can't find referenced class org.joda.convert.FromString
Warning:org.joda.time.Seconds: can't find referenced class org.joda.convert.FromString
Warning:org.joda.time.Seconds: can't find referenced class org.joda.convert.ToString
Warning:org.joda.time.Weeks: can't find referenced class org.joda.convert.FromString
Warning:org.joda.time.Weeks: can't find referenced class org.joda.convert.ToString
Warning:org.joda.time.YearMonth: can't find referenced class org.joda.convert.FromString
Warning:org.joda.time.YearMonth: can't find referenced class org.joda.convert.ToString
Warning:org.joda.time.Years: can't find referenced class org.joda.convert.FromString
Warning:org.joda.time.Years: can't find referenced class org.joda.convert.ToString
Warning:org.joda.time.base.AbstractDateTime: can't find referenced class org.joda.convert.ToString
Warning:org.joda.time.base.AbstractDuration: can't find referenced class org.joda.convert.ToString
Warning:org.joda.time.base.AbstractInstant: can't find referenced class org.joda.convert.ToString
Warning:org.joda.time.base.AbstractPeriod: can't find referenced class org.joda.convert.ToString
Warning:there were 37 unresolved references to classes or interfaces.
     You may need to add missing library jars or update their versions.
     If your code works fine without the missing classes, you can suppress
     the warnings with '-dontwarn' options.
     (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
Exception while processing task java.io.IOException: Please correct the above warnings first.
  at proguard.Initializer.execute(Initializer.java:473)
  at proguard.ProGuard.initialize(ProGuard.java:233)
  at proguard.ProGuard.execute(ProGuard.java:98)
  at proguard.gradle.ProGuardTask.proguard(ProGuardTask.java:1074)
  at com.android.build.gradle.tasks.AndroidProGuardTask.doMinification(AndroidProGuardTask.java:139)
  at com.android.build.gradle.tasks.AndroidProGuardTask$1.run(AndroidProGuardTask.java:115)
  at com.android.builder.tasks.Job.runTask(Job.java:48)
  at com.android.build.gradle.tasks.SimpleWorkQueue$EmptyThreadContext.runTask(SimpleWorkQueue.java:41)
  at com.android.builder.tasks.WorkQueue.run(WorkQueue.java:227)
  at java.lang.Thread.run(Thread.java:745)

Below is my build.gradle file: 下面是我的build.gradle文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.theacetechnologies.voicetype"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile files('libs/joda-time-2.7.jar')
}

Any idea why I am unable to generate the singed APK when proguard is enabled? 知道为什么我在启用proguard时无法生成被烧毁的APK? I believe this is something related to Joda Time as well, because I have generated proguard enabled signed APKs previously without JODA time. 我相信这也与Joda Time有关,因为我之前没有JODA时间生成了已启用proguard的签名APK。

Add these lines to your proguard file 将这些行添加到proguard文件中

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM