Unable to get provider androidx.lifecycle.ProcessLifecycleOwnerInitializr
Asked Answered
H

5

16

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.

Works fine in device with 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]]
Hag answered 15/3, 2019 at 7:13 Comment(1)
In my case i ran a android studio performance test between windows and linux when i came back to windows after android studio performance tests in Linux i got this error so i simply Cleaned the project and Rebuild it and it worked perfectlyCartwell
H
32

Thanks Andrews Alves

From post

It was a Dex problem. in android 4.4

1 - in app gradle, inside defaultConfig enable multidex

defaultConfig{
  ....
  multiDexEnabled true
}

2 - to support multidex in other versions, add this dependency to your app gradle

implementation 'com.android.support:multidex:1.0.3' 

3 - if you have a class that extends Application, make it extend

MultiDexApplication

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

android {
    defaultConfig {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

that's it. worked for me

Hag answered 15/3, 2019 at 7:40 Comment(1)
As a result of these changes, the application opening slowed down. I wonder why.Unhopedfor
C
6

In my case, Somehow android architecture lifecycle files getting omitted with Android bundle on Pie(Android9). So what I did was added keep statement for the same in proguard-rules.pro

For AndroidX :

-keep class androidx.lifecycle.** {*;}

For Support :

-keep class android.arch.lifecycle.** {*;}
Capuchin answered 4/10, 2019 at 6:40 Comment(0)
U
4

For kotlin add this to your gradle :

kotlinOptions {
        jvmTarget = '1.8'
}
compileOptions {
        targetCompatibility = "8"
        sourceCompatibility = "8"
}
Uncial answered 17/5, 2020 at 10:34 Comment(0)
W
1

You can find the official docs about Multidex here. Use this link to check the latest multidex gradle dependency version.

if you're using 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'
}
Wadleigh answered 24/8, 2019 at 17:23 Comment(0)
I
0

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.

Interruption answered 19/10, 2020 at 20:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.