Verify non-Google Play app installs using Play core library
Asked Answered
P

1

11

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 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.

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.

Default FirebaseApp is not initialised in this process

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.

Code:
Project's build.gradle:

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

App module's build.gradle:

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

Class that extends Application:

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

Any help would be really great.

Potful answered 23/6, 2019 at 15:38 Comment(10)
Could you detail what you mean by "The crash happens only when the app re-downloads because of side loading issue". What actions do you perform?Chubb
@Chubb which means, when I install side-loaded app, play core library identifies the app is side-laded and shows the popup saying "installation failed" and redirects to play store to install missing split apks. When I install the missing split apks from Play store and now if I run the apk, it crashes with the above said error.Potful
The app needs to be uninstalled and re-installed.Chubb
@Chubb That's right. This is how it should be. But when the popup redirects to play store, we see two options "Uninstall" & "Update". People will choose "Update". We cannot expect people who have side-loaded the app will uninstall and reinstall. This has to be forced somewhere or the better approach to be implemented.Potful
I think you may see "Update" in your case because there is actually a newer version of the app available. We are working on improvements though, yes.Chubb
I was testing this feature on a latest version. So, No. There wasn't any new version released. Thanks.Potful
Interesting. We're working on a better behaviour which should address this.Chubb
When can we expect the improvements @Pierre?Potful
Hey @NaveenTP I had written the same steps as per your question but I am getting errors like : (Unable to install, Package not found...on different devices) Steps: Upload an .abb in internal test 2) install it in high resolution device 3) shared this apk to low resolution devices via shareIT (app) 4) Getting installation errors. I have not written any split code or any thing like that in module. They are simple modules.Sclerodermatous
Hi @Pierre, with play core v1.6.3, this issue is still exists. Any work around at least?Potful
P
2

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

App module's build.gradle:

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

Other implementation remains same.

A class that extends Application:

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

How to test:

  • 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).

  • Simulate installing invalid apks - Use bundletool to get .apks file out of bundle, extract it and install base_master.apk using adb command adb install base_master.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.

Hope this helps

Potful answered 27/4, 2020 at 6:24 Comment(3)
This method is now deprecatedPlexiform
@marticztn do you know if there is a replacement?Balustrade
The replacement is supposed to be that Play Protect takes care of it. But that's not the case in my testing. It's been a while. Has anyone come up with anything?Barrio

© 2022 - 2024 — McMap. All rights reserved.