[Android] How to fix “Unable to get provider androidx.lifecycle.ProcessLifecycleOwnerInitializer"

This is a DEX problem. Enabling multidex can fix it.

Note: If your mindsVersion is set to 21 or higher, multidex is enabled by default and you do not need the multidex support library.

  1. Enable multidex inside defaultConfig in app gradle.
defaultConfig {
    multiDexEnabled true
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
  }
}
  1. Add dependency in app gradle.
dependencies {
    def multidex_version = "2.0.1"
    implementation 'androidx.multidex:multidex:$multidex_version'
}
  1. Add App class to extend MultiDexApplication.
class MyApplication : MultiDexApplication() {...}
  1. Edit manifest to set android:name in <application> tag.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapp">
    <application
        android:name="android.support.multidex.MultiDexApplication" >
        ...
    </application>
</manifest>

發表留言

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料