本文介绍了使用Play核心库验证是否安装了非Google Play应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

某些情况下:当我们迁移到 Android应用程序包发布方法时,我们大多数人可能都遇到了此 ResourceNotFoundException 。显然,问题出在侧面加载应用程序。

Some context: Most of us may have faced this ResourceNotFoundException when we migrated to Android app bundle release method. It is evident that the issue is because of Side-loading the app. Reference here.

Google最近宣布了解决方案解决这个问题。使用播放核心库,我们可以确定该应用是否为侧面加载(标识丢失的拆分apk)。如果应用是侧面加载的,则会显示 安装失败弹出窗口,并重定向到Play商店,用户可以在其中通过Google Play商店正确安装该应用。

Google recently announced solution to this problem. Using play core library we can identify whether the app is side-loaded or not (Identifies the missing split apks). If the app is side-loaded it shows "Installation failed" popup and redirects to play store, where user can properly install the app via the Google Play store.

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

Problem: Everything works fine until the installation of missing split apks from play store. Now when I relaunch the app, it immediately crashes with an error saying.

注意:从Play商店直接下载该应用程序可以正常运行而不会崩溃。仅当应用由于侧向加载问题而重新下载时,才会发生崩溃。

Note: Directly downloading the app from play store works perfectly fine without any crash. The crash happens only when the app re-downloads because of side loading issue.

代码:

项目的 build.gradle

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

应用程序模块的 build.gradle

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

扩展应用程序的类:

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

任何帮助都是非常好的。

Any help would be really great.

推荐答案

我已使用最新版本的Play核心库解决了此问题:

I have solved this issue with the latest version of Play core library:

应用程序模块的build.gradle:

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

其他实现保持不变。

扩展应用程序的类:

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

如何测试:


  • 一种更好的测试方法是在Play商店内部发布具有上述修复功能的应用包测试频道(将您自己添加为测试人员)。

  • A better way to test it properly is to release the app bundle with these above fixes in play store internal test channel (Add yourself as a tester).

模拟安装无效的APK-使用bundletool获取 .apks 打包打包,解压缩并使用adb命令
adb install base_master.apk 安装base_master.apk。

Simulate installing invalid apks - Use bundletool to get .apks file out of bundle, extract it and install base_master.apk using adb commandadb install base_master.apk.

启动应用程序,您应该看到安装失败对话框,它会重定向到Play商店,单击更新,Play商店将安装缺少的apk。

Launch the app, you should see "Installation failed" dialog and it redirects to Play store, clicking on Update, play store will install the missing apks.

启动应用程序现在应该可以正常运行。

Launching the app should work properly by now.

希望这会有所帮助

这篇关于使用Play核心库验证是否安装了非Google Play应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 19:07