问题描述
我收到此错误:
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/util/Function;
这是完整的输出:
2018-11-09 18:33:22.546 24224-24224/com.test.notes.notes E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.test.notes.notes, PID: 24224
java.lang.RuntimeException: Internal error in Firestore (0.6.6-dev).
at com.google.android.gms.internal.firebase-firestore.zzkj.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:241)
at android.app.ActivityThread.main(ActivityThread.java:6274)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/util/Function;
at com.google.android.gms.internal.firebase-firestore.zzfu.zzd(Unknown Source)
at com.google.android.gms.internal.firebase-firestore.zzeg.<init>(Unknown Source)
at com.google.android.gms.internal.firebase-firestore.zzcj.zza(Unknown Source)
at com.google.android.gms.internal.firebase-firestore.zzcl.run(Unknown Source)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:272)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at com.google.android.gms.internal.firebase-firestore.zzkg$zza.run(Unknown Source)
at java.lang.Thread.run(Thread.java:761)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.util.Function" on path: DexPathList[[zip file "/data/app/com.test.notes.notes-1/base.apk", zip file "/data/app/com.test.notes.notes-1/split_lib_dependencies_apk.apk", zip file "/data/app/com.test.notes.notes-1/split_lib_slice_0_apk.apk", zip file "/data/app/com.test.notes.notes-1/split_lib_slice_1_apk.apk", zip file "/data/app/com.test.notes.notes-1/split_lib_slice_2_apk.apk", zip file "/data/app/com.test.notes.notes-1/split_lib_slice_3_apk.apk", zip file "/data/app/com.test.notes.notes-1/split_lib_slice_4_apk.apk", zip file "/data/app/com.test.notes.notes-1/split_lib_slice_5_apk.apk", zip file "/data/app/com.test.notes.notes-1/split_lib_slice_6_apk.apk", zip file "/data/app/com.test.notes.notes-1/split_lib_slice_7_apk.apk", zip file "/data/app/com.test.notes.notes-1/split_lib_slice_8_apk.apk", zip file "/data/app/com.test.notes.notes-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.test.notes.notes-1/lib/arm64, /system/lib64, /vendor/lib64]]
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 com.google.android.gms.internal.firebase-firestore.zzfu.zzd(Unknown Source)
at com.google.android.gms.internal.firebase-firestore.zzeg.<init>(Unknown Source)
at com.google.android.gms.internal.firebase-firestore.zzcj.zza(Unknown Source)
at com.google.android.gms.internal.firebase-firestore.zzcl.run(Unknown Source)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:272)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at com.google.android.gms.internal.firebase-firestore.zzkg$zza.run(Unknown Source)
at java.lang.Thread.run(Thread.java:761)
Suppressed: java.io.IOException: No original dex files found for dex location /data/app/com.test.notes.notes-1/split_lib_slice_7_apk.apk
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:367)
at dalvik.system.DexFile.<init>(DexFile.java:112)
at dalvik.system.DexFile.<init>(DexFile.java:77)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:359)
at dalvik.system.DexPathList.makeElements(DexPathList.java:323)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:263)
at dalvik.system.DexPathList.<init>(DexPathList.java:126)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:48)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
at com.android.internal.os.PathClassLoaderFactory.createClassLoader(PathClassLoaderFactory.java:43)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:58)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:541)
2018-11-09 18:33:22.546 24224-24224/com.test.notes.notes E/AndroidRuntime: at android.app.LoadedApk.getClassLoader(LoadedApk.java:574)
at android.app.ActivityThread.getTopLevelResources(ActivityThread.java:1900)
at android.app.LoadedApk.getResources(LoadedApk.java:787)
at android.app.ContextImpl.<init>(ContextImpl.java:2038)
at android.app.ContextImpl.createAppContext(ContextImpl.java:1983)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5439)
at android.app.ActivityThread.-wrap2(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1576)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:241)
at android.app.ActivityThread.main(ActivityThread.java:6274)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
我认为需要我的build.gradle,所以这是我的build.gradle(Project:test):
And I think my build.gradle is needed so here is my build.gradle(Project: test):
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
android {
compileSdkVersion 27
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.test.notes.notes"
minSdkVersion 16
targetSdkVersion 27
versionCode 17
versionName "5.1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
checkReleaseBuilds false
}
aaptOptions {
cruncherEnabled = false
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support:design:27.0.2'
implementation 'com.android.support:cardview-v7:27.0.2'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:27.0.2'
implementation 'com.android.support:support-vector-drawable:27.0.2'
implementation 'com.google.firebase:firebase-firestore:15.0.0'
implementation 'com.firebaseui:firebase-ui-firestore:3.1.1'
api 'com.joooonho:selectableroundedimageview:1.0.1'
api 'com.github.bumptech.glide:glide:3.7.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
api 'com.google.firebase:firebase-core:16.0.5'
api 'com.google.firebase:firebase-firestore:15.0.0'
api 'com.google.firebase:firebase-storage:16.0.4'
api 'com.google.firebase:firebase-auth:16.0.5'
api 'com.crashlytics.sdk.android:crashlytics:2.9.5'
}
apply plugin: 'com.google.gms.google-services'
出现该错误,应用崩溃.
我认为firebase SDK可能有什么问题,但无法弄清楚吗?
请帮助我解决此问题.很长时间以来,我都没有找到解决它的方法.:(
With that error, the app crashes.
I think there could be anything wrong with the firebase SDK, but can't figure it out?
Please help me to fix this. I didn't find a way to fix it, for a long time.:(
将所有内容更新到最新版本并添加后:
After updated everything to the newest version and added:
multiDexEnabled true
...一切正常.但是现在我有了问题,为什么我最终将版本降级了.请看一下我的问题:我没有得到答复:
在Firebase 16.0.+更新后更新代码
...everything works fine. But now I have the Problem, why I downgraded the versions finally. Please have a look at my question: I don't get a response:
Updating code after firebase 16.0.+ update
我可以解决的话,一切都会好起来的.
When I could fix that everything would be fine.
推荐答案
我在您的 build.gradle
中看到了很多问题.
I see a whole mess of problems in your build.gradle
.
第一类问题是您的大多数依赖项已经过时了.
The first category of issues is that most of your dependencies are pretty outdated.
- Android API 27支持库位于27.1.1,而不是27.0.2.
-
firebase-firestore
位于17.1.2,而不是15.0.0. -
firebase-ui-firestore
位于4.2.1而非2.1.1.上. -
glide
位于4.8.0,而不是3.7.0.
- The Android API 27 support libraries are on 27.1.1, not 27.0.2.
firebase-firestore
is on 17.1.2, not 15.0.0.firebase-ui-firestore
is on 4.2.1, not 2.1.1.glide
is on 4.8.0, not 3.7.0.
从属版本通常应该是最新的,但是如果它们来自Google,则绝对 必须是最新的.否则,您将碰到您所遇到的错误类型.
Dependency versions should be up-to-date in general, but absolutely must be up-to-date if they're from Google. Otherwise you run into exactly the type of error you have.
第二个问题是您两次实施 firebase-firestore
,一次是通过 implementation
实施,另一次是通过 api
实施.删除其中一个.
The second problem is that you implement firebase-firestore
twice, once with implementation
and again with api
. Remove one or the other.
一个方便的提示:如果依赖项以黄色突出显示,则表示它已经过时了!单击文本,单击 + 并选择将其更新为最新版本的选项.
A handy tip: if a dependency is highlighted in yellow, that means it's outdated! Click the text, hit + and choose the option to update it to the latest version.
这篇关于由以下原因引起:java.lang.NoClassDefFoundError:无法解决以下问题:Lcom/google/android/gms/common/util/Function;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!