我正在构建一个应用程序并在其中使用 Joda Time 而不是内置在日期/时间类中的 java。但是我遇到了一个问题,当我使用 Android API 22 它运行良好,但是当我使用 android API 23 编译它时它抛出 NoClassDefFoundError 异常。 我的 build.gradle 正在执行
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
defaultConfig {
multiDexEnabled true
applicationId 'com.my.app'
minSdkVersion 11
targetSdkVersion 23
versionCode 6
versionName '5.0.1'
}
buildTypes {
release {
//runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
sourceSets {
main {
assets.srcDirs = ['src/main/assets', 'src/main/assets/downloadMusicMishari', 'src/main/assets/downloadmusicSaad']
}
}
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
//compile 'com.android.support:support-v4:20.0.0'
compile project(':facebook')
compile project(':library')
compile files('libs/PayPalAndroidSDK-2.9.10.jar')
compile files('libs/picasso-2.5.2.jar')
compile project(':justifiedTextViewmaster')
compile 'joda-time:joda-time:2.3'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.google.android.gms:play-services:8.3.0'
compile 'com.android.support:multidex:1.0.0'
}
repositories {
mavenCentral()
}
最佳答案
NoClassDefFoundError
Thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.
请检查 Joda-Time library with Android specialization
尝试:
dependencies {
compile 'net.danlew:android.joda:2.9.2' // For API Level 23 or Above
}
然后清理-重建您的 IDE
编辑
确保初始化 JodaTimeAndroid.init(this);
Once that's done, you must initialize the library before using it by calling JodaTimeAndroid.init(). I suggest putting this code in Application.onCreate():
public class YourApplicationClass extends Application {
@Override
public void onCreate() {
super.onCreate();
JodaTimeAndroid.init(this);
}
}
最终编辑
Removed Joda plugin
关于java - NoClassDefFoundError 异常 android joda 时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35865127/