使用 Play 核心库验证非 Google Play 应用安装

Verify non-Google Play app installs using Play core library

一些上下文: 我们大多数人在迁移到 Android app bundle[=43= 时可能都遇到过这个问题 ResourceNotFoundException 】 释放方法。很明显,问题是因为侧加载应用程序。

Google 最近宣布 solution 这个问题。使用 play 核心库,我们可以识别应用程序是否是侧加载的(识别丢失的拆分 apks)。如果应用程序是侧面加载的,它会显示“安装失败”弹出窗口并重定向到 Play 商店,用户可以在其中通过 Google Play 商店正确安装应用程序。

问题:一切正常,直到从 Play 商店安装缺少的拆分 apk。现在,当我重新启动该应用程序时,它立即崩溃并显示一条错误消息。

Default FirebaseApp is not initialised in this process

注意: 直接从 Play 商店下载该应用程序非常好,没有任何崩溃。仅当应用因侧载问题而重新下载时才会发生崩溃。

代码:
项目的 build.gradle

buildscript {
 dependencies {
  classpath 'com.android.tools.build:bundletool:0.9.0'
 }
}

应用模块的build.gradle

 implementation 'com.google.android.play:core:1.6.1'

Class 扩展应用程序:

 public void onCreate() {
    if (MissingSplitsManagerFactory.create(this).disableAppIfMissingRequiredSplits()) {
        // Skip app initialization.
        return;
    }
    super.onCreate();
    .....
 }

任何帮助都会非常有用。

我已经用最新版本的 Play 核心库解决了这个问题:

App模块的build.gradle:

implementation "com.google.android.play:core:1.7.2"

其他实现保持不变。

扩展应用程序的class:

public void onCreate() {
 if (MissingSplitsManagerFactory.create(this).disableAppIfMissingRequiredSplits()) {
    // Skip app initialization.
    return;
 }
 super.onCreate();
 .....
}

如何测试:

  • 正确测试它的更好方法是在 Play 商店内部测试频道(将您自己添加为测试人员)中发布包含上述修复的应用程序包。

  • 模拟安装无效的 apks - 使用 bundletool 从 bundle 中获取 .apks 文件,解压并使用 adb 命令安装 base_master.apk adb install base_master.apk.

  • 启动应用程序,您应该会看到 "Installation failed" 对话框,它会重定向到 Play 商店,点击更新,Play 商店将安装缺少的 apks。

  • 启动应用程序现在应该可以正常工作了。

希望对您有所帮助