[英]Unable to get provider androidx.lifecycle.ProcessLifecycleOwnerInitializr
Getting error while running app which have dependencies 'androidx.lifecycle:lifecycle-extensions:2.1.0-alpha03'
and 'androidx.lifecycle:lifecycle-viewmodel:2.1.0-alpha03'
on device with Android 4.4.在使用 Android 4.4 的设备上运行具有依赖项
'androidx.lifecycle:lifecycle-extensions:2.1.0-alpha03'
和'androidx.lifecycle:lifecycle-viewmodel:2.1.0-alpha03'
应用程序时出错。
Works fine in device with Android 6在装有 Android 6 的设备上运行良好
App getting crashed with error应用程序因错误而崩溃
java.lang.RuntimeException: Unable to get provider androidx.lifecycle.ProcessLifecycleOwnerInitializer: java.lang.ClassNotFoundException: Didn't find class "androidx.lifecycle.ProcessLifecycleOwnerInitializer" on path: DexPathList[[zip file "/data/app/**********.apk"],nativeLibraryDirectories=[/data/app-lib/***********, /vendor/lib, /system/lib]]
at android.app.ActivityThread.installProvider(ActivityThread.java:5052)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4623)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4563)
at android.app.ActivityThread.access$1500(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1402)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5333)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.lifecycle.ProcessLifecycleOwnerInitializer" on path: DexPathList[[zip file "/data/app/**********.apk"],nativeLibraryDirectories=[/data/app-lib/********, /vendor/lib, /system/lib]]
Thanks Andrews Alves感谢安德鲁斯阿尔维斯
It was a Dex problem.这是一个 Dex 问题。 in android 4.4
在安卓 4.4 中
1 - in app gradle, inside defaultConfig enable multidex 1 - 在 app gradle 中,在 defaultConfig 中启用 multidex
defaultConfig{
....
multiDexEnabled true
}
2 - to support multidex in other versions, add this dependency to your app gradle 2 - 要在其他版本中支持 multidex,请将此依赖项添加到您的应用程序 gradle
implementation 'com.android.support:multidex:1.0.3'
3 - if you have a class that extends Application, make it extend 3 - 如果你有一个扩展应用程序的类,让它扩展
MultiDexApplication
多Dex应用程序
if you don't, add this to your manifest file inside application tag如果不这样做,请将其添加到应用程序标记内的清单文件中
android:name="android.support.multidex.MultiDexApplication"
Besides, if you created a new application, dont forget to add the following to your app/build.gradle此外,如果您创建了一个新应用程序,请不要忘记将以下内容添加到您的 app/build.gradle
android {
defaultConfig {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
that's it.就是这样。 worked for me
为我工作
In my case, Somehow android architecture lifecycle files getting omitted with Android bundle on Pie(Android9).就我而言,Pie(Android9)上的 Android 包以某种方式省略了 android 架构生命周期文件。 So what I did was added keep statement for the same in proguard-rules.pro
所以我所做的是在 proguard-rules.pro 中添加了相同的 keep 语句
For AndroidX :对于 AndroidX :
-keep class androidx.lifecycle.** {*;}
For Support :为了支持 :
-keep class android.arch.lifecycle.** {*;}
For kotlin add this to your gradle :对于 kotlin,将此添加到您的 gradle 中:
kotlinOptions {
jvmTarget = '1.8'
}
compileOptions {
targetCompatibility = "8"
sourceCompatibility = "8"
}
You can find the official docs about Multidex here .您可以在此处找到有关 Multidex 的官方文档。 Use this link to check the latest multidex gradle dependency version.
使用此链接检查最新的 multidex gradle 依赖项版本。
if you're using AndroidX如果您使用的是 AndroidX
dependencies {
def multidex_version = "2.0.1" // Check this from the link
implementation 'androidx.multidex:multidex:$multidex_version'
}
otherwise use否则使用
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
For me nothing of the above worked.对我来说,以上都没有奏效。 Also restarting and invalidating didnt do anything.
也重新启动和无效没有做任何事情。 After uninstalling the app and "Build > Clean Project" every thing worked as expected.
卸载应用程序和“构建>清理项目”后,一切都按预期工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.