Android~Unable to get provider androidx.lifecycle.ProcessLifecycleOwnerInitializer
在新项目中已开始迁移到Androidx遇到Unable to get provider androidx.lifecycle.ProcessLifecycleOwnerInitializer错误,APP在安卓4.4上面启动奔溃,记录解决办法。参考原文在安卓4.4中,这是一个dex问题。解决办法是1、在app.gradle中,defaultconfig内启用multidexdefaultCo...
在新项目中已开始迁移到Androidx遇到Unable to get provider androidx.lifecycle.ProcessLifecycleOwnerInitializer错误,APP在安卓4.4上面启动奔溃,记录解决办法。参考原文
在安卓4.4中,这是一个dex问题。解决办法是
1、在app.gradle中,defaultconfig内启用multidex
defaultConfig{
…
multiDexEnabled true
}
2、在gradle中添加 multidex依赖
implementation ‘com.android.support:multidex:1.0.3’
3、如你创建了Application类,不能继承自Application 需要继承MultiDexApplication。相反,在清单文件中添加标记
<application
android:name="android.support.multidex.MultiDexApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:theme="@style/AppTheme.Launcher"
android:supportsRtl="true">
补充:突破65535方法限制
因为恰好这一块是相互关联的 解决65535 问题 ,其实在Google官方已经给出解决方案,[Building Apps with Over 65K Methods]
(https://developer.android.com/tools/building/multidex.html)
- 在Module 的 build.gradle 中引用 compile ‘com.android.support:multidex:1.0.3’ , 同时在 defaultConfig 中添加 multiDexEnabled true
- 继承 MultiDexApplication 或 复写Application的attachBaseContext()方法 因为我们有的时候用的是别人提供的Application
public class XXX extends Application{
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
- 最后同步代码
更为详细的参考:
https://blog.csdn.net/t12x3456/article/details/40837287
https://blog.csdn.net/fan7983377/article/details/73850282
更多推荐
所有评论(0)