joda-time或joda-time-android错误:任务执行失败':app:dexDebug'

时间:2015-11-17 10:58:59

标签: android jodatime

我有build.gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
  applicationId "com.xcompany.xapplication"
  minSdkVersion 15
  targetSdkVersion 23
  versionCode 1
  versionName "1.0"
}

buildTypes {
  release {
    minifyEnabled false
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  }
}

packagingOptions {
  exclude 'META-INF/LICENSE.txt'
  exclude 'META-INF/NOTICE.txt'
  }
}

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

当我尝试制作apk并运行应用程序时出错:

Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_66.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2

看起来像proguard配置问题,但是proguard-rules.pro中joda类的设置没有帮助。

我的Proguard配置:

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

1 个答案:

答案 0 :(得分:0)

我通过将 multiDexEnabled true 添加到build.gradle的defaultConfig部分来解决了这个问题

defaultConfig {
  applicationId "com.xcompany.xapplication"
  multiDexEnabled true      
  minSdkVersion 15
  targetSdkVersion 23
  versionCode 1
  versionName "1.0"
}

我找到了解决方案here