Capacitor: this.platform.ready() not firing in production?

Hello

I’m having a very strange issue. I have code in my initializeApp() method that takes care of some configurations like ignoring native font zooming, disabling screen rotation, some statusbar configurations, etc. I’m also fetching some data from my backend.

When I open the app on my physical android device after running ‘ionic cap sync’ everything works fine. But after bundling my app and publishing it in the PlayStore nothing happens on the same device. No splashscreen, no data, no configurations, nothing. It seems like the function is getting ignored? I have no clue why. Here is the code in initializeApp():

initializeApp(): void {
      this.platform.ready().then(async () => {
         if (this.platform.width() > 500) {
            this.usingLargeDevice = true;
         }

         this.previousRouteService.init();

         const info = await Device.getInfo();

         if (info.platform !== 'web') {
            const hasCompletedTutorial = await this.appSettingsService.hasCompletedTutorial();
            if (!hasCompletedTutorial) {
               this.router.navigate(['/intro']);
            }

            if (!await this.appSettingsService.isReloadingAppAfterExitingTutorial()) {
               // show custom splashscreen
               this.showingSplash = true;
            }

            // disable screen rotation
            this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.PORTRAIT);

            // ignore native font zooming
            this.mobileAccessibility.setTextZoom(100);
            this.mobileAccessibility.updateTextZoom();
            this.mobileAccessibility.usePreferredTextZoom(false);

            StatusBar.setOverlaysWebView({
               overlay: true
            });
            StatusBar.setStyle({
               style: StatusBarStyle.Light
            });

            this.oneSignal.startInit(environment.oneSignal.appId, environment.oneSignal.googleProjectNumber);
            this.oneSignal.inFocusDisplaying(this.oneSignal.OSInFocusDisplayOption.Notification);
            this.oneSignal.endInit();

            // hide default splashscreen
            this.splashScreen.hide();

            // hide custom splashscreen after 3 seconds
            timer(3000).subscribe(() => {
               this.showingSplash = false;
            });
         }

         this.divisionService.setDivisionPreviewModels();
      });
   }

Thanks in advance!

Update:

Added some toasts to test the signed apk. It seems like the ‘this.platform.ready().then(async () => {}’ is never hit after signing the app. Any suggestions?

Found the problem. I was using minify, guess I can’t do that.

I believe there are no functions “platform ready” with capacitor.
Try to launch app in prod mode on your Android. And inspect with chrome://inspect/#devices

ionic capacitor build android--prod

Real root of the issue is probably mixing both promises and async await without actually returning the original promise from platform.ready()

Idk, my hardware backbutton wasn’t working either. After disabling minify the app worked as expected. The async await functionality is being used in the callback of the platform.ready(). Can you explain what’s wrong with that approach?

  async initializeApp(): void {
    await this.platform.ready();
  }

You can simplify your code by using async await automatically. Minification is probably showing/hiding the error because of how async/await and promises can get rewritten during minification.

Also, there’s an unnecessary subscription in there

    timer(3000).subscribe(() => {
               this.showingSplash = false;
            });

Since this is never unsubscribed to, it will cause a memory leak. Just use setTimeout instead.

1 Like