当尝试观察从ViewModel返回的片段中的实时数据时,我在此之前得到以下异常,我在此post交换中得到了不同的错误
android.arch.lifecycle:common-java8:1.0.0-beta2
android.arch.lifecycle:compiler:1.0.0-beta2
解决了该问题,但现在我收到了以下异常
您可以找到整个代码here
E/AndroidRuntime: FATAL EXCEPTION: pool-1-thread-1
Process: com.nrs.nsnik.architecturecomponents, PID: 4114
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/arch/core/executor/AppToolkitTaskExecutor;
at android.arch.persistence.room.InvalidationTracker.addObserver(InvalidationTracker.java:241)
at android.arch.persistence.room.InvalidationTracker.addWeakObserver(InvalidationTracker.java:257)
at com.nrs.nsnik.architecturecomponents.data.NoteDao_Impl$4.compute(NoteDao_Impl.java:146)
at com.nrs.nsnik.architecturecomponents.data.NoteDao_Impl$4.compute(NoteDao_Impl.java:134)
at android.arch.lifecycle.ComputableLiveData$2.run(ComputableLiveData.java:87)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.arch.core.executor.AppToolkitTaskExecutor" on path: DexPathList[[zip file "/data/app/com.nrs.nsnik.architecturecomponents-1/base.apk", zip file "/data/app/com.nrs.nsnik.architecturecomponents-1/split_lib_dependencies_apk.apk", zip file "/data/app/com.nrs.nsnik.architecturecomponents-1/split_lib_slice_0_apk.apk", zip file "/data/app/com.nrs.nsnik.architecturecomponents-1/split_lib_slice_1_apk.apk", zip file "/data/app/com.nrs.nsnik.architecturecomponents-1/split_lib_slice_2_apk.apk", zip file "/data/app/com.nrs.nsnik.architecturecomponents-1/split_lib_slice_3_apk.apk", zip file "/data/app/com.nrs.nsnik.architecturecomponents-1/split_lib_slice_4_apk.apk", zip file "/data/app/com.nrs.nsnik.architecturecomponents-1/split_lib_slice_5_apk.apk", zip file "/data/app/com.nrs.nsnik.architecturecomponents-1/split_lib_slice_6_apk.apk", zip file "/data/app/com.nrs.nsnik.architecturecomponents-1/split_lib_slice_7_apk.apk", zip file "/data/app/com.nrs.nsnik.architecturecomponents-1/split_lib_slice_8_apk.apk", zip file "/data/app/com.nrs.nsnik.architecturecomponents-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.nrs.nsnik.architecturecomponents-1/lib/x86, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.arch.persistence.room.InvalidationTracker.addObserver(InvalidationTracker.java:241)
at android.arch.persistence.room.InvalidationTracker.addWeakObserver(InvalidationTracker.java:257)
at com.nrs.nsnik.architecturecomponents.data.NoteDao_Impl$4.compute(NoteDao_Impl.java:146)
at com.nrs.nsnik.architecturecomponents.data.NoteDao_Impl$4.compute(NoteDao_Impl.java:134)
at android.arch.lifecycle.ComputableLiveData$2.run(ComputableLiveData.java:87)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
Build.Gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.nrs.nsnik.architecturecomponents"
minSdkVersion 25
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
resConfigs "en"
splits {
abi {
enable true
reset()
include 'x86_64', 'x86', 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'mips'
universalApk false
}
}
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
}
sourceSets {
androidTest.assets.srcDirs += files("$projectDir/schemas".toString())
}
buildTypes {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
ext.versionCodes = ['armeabi': 3, 'armeabi-v7a': 4, 'arm64-v8a': 5, mips: 6, 'x86': 7, 'x86_64': 8]
import com.android.build.OutputFile
android.applicationVariants.all { variant ->
variant.outputs.each { output ->
output.versionCodeOverride =
project.ext.versionCodes.get(output.getFilter(OutputFile.ABI)) * 1000 + android.defaultConfig.versionCode
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', {
exclude group: 'com.android.support', module: 'support-annotations'
})
//SUPPORT LIBRARY
implementation 'com.android.support:appcompat-v7:26.1.0'
//RECYCLER VIEW
implementation 'com.android.support:recyclerview-v7:26.1.0'
//ANNOTATION SUPPORT LIBRARY
implementation 'com.android.support:support-annotations:26.1.0'
//DESIGN SUPPORT LIBRARY
implementation 'com.android.support:design:26.1.0'
//CONSTRAINT LAYOUT
implementation 'com.android.support.constraint:constraint-layout:1.1.0-beta3'
//KOTLIN
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
//RX JAVA & ANDROID
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'io.reactivex.rxjava2:rxjava:2.1.4'
//RX BINDING
implementation 'com.jakewharton.rxbinding2:rxbinding:2.0.0'
implementation 'com.jakewharton.rxbinding2:rxbinding-support-v4:2.0.0'
implementation 'com.jakewharton.rxbinding2:rxbinding-appcompat-v7:2.0.0'
implementation 'com.jakewharton.rxbinding2:rxbinding-design:2.0.0'
implementation 'com.jakewharton.rxbinding2:rxbinding-recyclerview-v7:2.0.0'
//TIMBER LOGGER
implementation 'com.jakewharton.timber:timber:4.5.1'
//GUAVA
implementation 'com.google.guava:guava:23.0'
//DAGGER 2
implementation 'com.google.dagger:dagger-android:2.11'
implementation 'com.google.dagger:dagger-android-support:2.11'
annotationProcessor 'com.google.dagger:dagger-compiler:2.11'
//BUTTER KNIFE
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
//LEAK CANARY
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.4'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4'
//LIFE CYCLE EXTENSIONS
implementation "android.arch.lifecycle:extensions:1.0.0-alpha9-1"
//LIFE CYCLE JAVA 8
//implementation "android.arch.lifecycle:common-java8:1.0.0-beta2"
implementation "android.arch.lifecycle:runtime:1.0.0"
annotationProcessor "android.arch.lifecycle:compiler:1.0.0-alpha9-1"
//LIVE DATA BACKGROUND TEST
testImplementation "android.arch.core:core-testing:1.0.0-alpha9-1"
//LIVE DATA WITH REACTIVE STREAMS
implementation "android.arch.lifecycle:reactivestreams:1.0.0-alpha9-1"
//ROOM
implementation "android.arch.persistence.room:runtime:1.0.0-alpha9-1"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0-alpha9-1"
//ROOM TEST MIGRATION
testImplementation "android.arch.persistence.room:testing:1.0.0-alpha9-1"
//ROOM RxJAVA
implementation "android.arch.persistence.room:rxjava2:1.0.0-alpha9-1"
//PAGING
implementation "android.arch.paging:runtime:1.0.0-alpha3"
}
答案 0 :(得分:3)
这里的问题相同。 我不得不从1.0.0-beta-2更改为1.0.0-alpha9-1版本。
答案 1 :(得分:0)
将gradle依赖项(android.arch.lifecycle)更新到最新版本。