ClassNotFoundException:"androidx.work.impl.WorkManagerInitializer" [英] ClassNotFoundException: “androidx.work.impl.WorkManagerInitializer”

查看:152
本文介绍了ClassNotFoundException:"androidx.work.impl.WorkManagerInitializer"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将Google AdMob Ads库版本19.4.0升级到19.5.0后,某些设备上出现了新的例外情况:

A new exception appeared on some devices after upgrading Google AdMob Ads library version 19.4.0 to 19.5.0:

Caused by java.lang.ClassNotFoundException 
Didn't find class "androidx.work.impl.WorkManagerInitializer" on path: ...
dalvik.system.BaseDexClassLoader.findClass (BaseDexClassLoader.java:196)
androidx.core.app.CoreComponentFactory.instantiateProvider (CoreComponentFactory.java)
android.app.ActivityThread.installProvider (ActivityThread.java:7213)
android.app.ActivityThread.installContentProviders (ActivityThread.java:6769)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:941)

该异常出现在装有Android 8及更高版本的设备上10.

The exception appeared on devices with Android 8 & 10.

AdMob库19.5.0(通过Play Services Ads Lite库)增加了对WorkManager 2.1.0的依赖: https://mvnrepository.com/神器/com.google.android.gms/play-services-ads-lite/19.5.0

AdMob library 19.5.0 adds dependency on WorkManager 2.1.0 (via Play Services Ads Lite library): https://mvnrepository.com/artifact/com.google.android.gms/play-services-ads-lite/19.5.0

关于此问题,有一个类似问题,但这似乎没有关系(具有多个dex的旧Android操作系统版本,而这里是单个dex和较新的OS版本).

There is a similar question on this issue, but it seems to be unrelated (older Android OS versions with multiple dex, while here it's single dex and newer OS versions).

目前,我已降级为AdMob 19.4.0,其中不包括WorkManager依赖项.

For now I downgraded to AdMob 19.4.0, which does not include WorkManager dependency.

更新(2020.12.18)

  • 异常频率是每1000个运行Android 10的设备中的1个.
  • 强制WorkManager 2.4.0(而不是2.1.0)也会生成异常.
  • 该问题与AdMob无关.使用AdMob 19.4.0将WorkManager添加到项目中可以解决此问题.
  • 我目前的假设是,该问题是由AudienceNetwork&内容提供商之间的冲突引起的.工作管理器.使用WorkManager将AudienceNetwork添加到项目中生成了具有不同类的相同异常:在某些Android 10设备上找不到类"com.facebook.ads.AudienceNetworkContentProvider" .

推荐答案

解决方法:通过将以下内容添加到 Manifest.xml 中,删除WorkManager的默认内容提供程序初始化:

Remove the WorkManager default content provider initialization by adding the following to the Manifest.xml:

<provider
    android:name="androidx.work.impl.WorkManagerInitializer"
    android:authorities="${applicationId}.workmanager-init"
    tools:node="remove"
    android:exported="false"
    />

将WorkManager的手动初始化添加到 Application.onCreate()方法中:

Add manual initialization of the WorkManager to the Application.onCreate() method:

Configuration myConfig = new Configuration.Builder()
        .build();
WorkManager.initialize(this, myConfig);

这篇关于ClassNotFoundException:"androidx.work.impl.WorkManagerInitializer"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆