Android 9在 SplashActivity启动时崩溃:ProviderInstaller失败后应用程序单例为空

移动开发 2026-07-09

我是后端开发人员,因此我的Android知识有限。我在努力判断这次崩溃是由我的应用初始化流程引起,还是由Android 9上的ProviderInstaller / Google Play服务行为所致。

应用在某些三星Android 9设备上启动时崩溃,恰好在 SplashActivity 启动后。

崩溃日志:

Fatal Exception: java.lang.RuntimeException

Unable to start activity ComponentInfo{Sample.Sample.production/Sample.Sample.activity.entry.SplashActivity}: java.lang.NullPointerException: Attempt to read from field '...SampleApplication...' on a null object reference

Caused by java.lang.NullPointerException

at Sample.Sample.SampleApplication.getApplicationComponent(SampleApplication.java:25)

at Sample.Sample.activity.entry.SplashActivity.onCreate(SplashActivity.kt:48)

相关代码:

SampleBaseApplication.java

@Override
public void onCreate() {
    initTimber();

    if (initBefore()) {
        return;
    }

    Sin.ce(this);
    super.onCreate();
    initInject();
}

initBefore():

protected boolean initBefore() {
    try {
        ProviderInstaller.installIfNeeded(this);
        return false;
    } catch (GooglePlayServicesRepairableException e) {
        GoogleApiAvailability.getInstance().showErrorNotification(this, e.getConnectionStatusCode());
    } catch (GooglePlayServicesNotAvailableException e) {
        Timber.e(e, "cannot execute providerInstaller");
    }
    return true;
}

SplashActivity.kt

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    Sin.gle().applicationComponent.injectActivity(this)
    setContentView(binding.root)
}

我的问题是:

  1. 应该以哪种正确方式来修复这个启动崩溃?
  2. 为什么似乎只在Android 9 / 某些三星设备上发生?
  3. 应否将Sin.ce(this) 移到initBefore() 之前,还是ProviderInstaller的失败不应阻塞应用初始化?

解决方案

看起来与最近的三星固件更新有关,该更新针对Galaxy S8 / S8+ / Note8,于2026-05-28发布,最近的三星固件更新

在那次更新之后,在我们的案例中,ProviderInstaller.installIfNeeded() 开始在Android 9的三星设备上失败。

+ 进一步查询

站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。

相关文章