Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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]]
like image 270
Ajay Simiyon Avatar asked Mar 15 '19 07:03

Ajay Simiyon


3 Answers

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

like image 126
Ajay Simiyon Avatar answered Nov 15 '22 01:11

Ajay Simiyon


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.** {*;}
like image 6
VishnuPrajapati Avatar answered Nov 15 '22 02:11

VishnuPrajapati


For kotlin add this to your gradle :

kotlinOptions {
        jvmTarget = '1.8'
}
compileOptions {
        targetCompatibility = "8"
        sourceCompatibility = "8"
}
like image 4
Ouail Bellal Avatar answered Nov 15 '22 02:11

Ouail Bellal