DEV Community 👩‍💻👨‍💻

dotorimook
dotorimook

Posted on

Important to know for Ionic AppFlow's Live Update

When you decided to develop a hybrid app, it could be the one of the advantages of hybrid app that you can update the app right away without updating through App Store or Play Store.
I investigated the live update feature of Ionic AppFlow, and the AppFlow service itself is pretty much neat and looking-good and the process of deploying and live-updating looks so much easy. So I chose to use Ionic AppFlow for live updating.
BUT, for almost more than a week, I was in trouble making the live update to work, and the support department in Ionic was not helpful so much. So I decided to write What the problem I met was and share to solve the problem.

I tried the live update feature from the instruction from appFlow page like following: linking with ionic link ${your_app_id} and ionic deploy add to set up Ionic Deploy.

Then you can meet the following errors.

1. Missing values

Then you can see some added text in the android/app/src/main/res/values/strings.xml:

...
  <string name="ionic_app_id">${your_app_id}</string>
  <string name="ionic_channel_name">Master</string>
  <string name="ionic_update_method">auto</string>

If you chaned the channel name and update method, it would be different.
Then if you run the application from Android Studio, you will meet the following error:

E/m.midas.jobfle: Invalid ID 0x00000000.
E/PluginManager: Uncaught exception from plugin
    android.content.res.Resources$NotFoundException: String resource ID #0x0
        at android.content.res.Resources.getText(Resources.java:363)
        at android.content.res.Resources.getString(Resources.java:456)
        at android.content.Context.getString(Context.java:580)
        at com.ionicframework.common.IonicCordovaCommon.getStringResourceByName(IonicCordovaCommon.java:341)
        at com.ionicframework.common.IonicCordovaCommon.getNativeConfig(IonicCordovaCommon.java:425)
        at com.ionicframework.common.IonicCordovaCommon.getPreferences(IonicCordovaCommon.java:384)
        at com.ionicframework.common.IonicCordovaCommon.execute(IonicCordovaCommon.java:92)
        at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:98)
        at org.apache.cordova.PluginManager.exec(PluginManager.java:132)
        at com.getcapacitor.MessageHandler.callCordovaPluginMethod(MessageHandler.java:69)
        at com.getcapacitor.MessageHandler.postMessage(MessageHandler.java:45)
        at android.os.MessageQueue.nativePollOnce(Native Method)
        at android.os.MessageQueue.next(MessageQueue.java:326)
        at android.os.Looper.loop(Looper.java:181)
        at android.os.HandlerThread.run(HandlerThread.java:65)
E/Capacitor/Console: File: capacitor-runtime.js - Line 2654 - Msg: Uncaught (in promise) String resource ID #0x0

You can see the error message related in chrome inspector Uncaught (in promise) String resource ID #0x0. It means that live update didn't make due to the error.
In the process of loading and live updating the app, it checks some environmental values from strings.xml or SharedPreference. However, if there is some missing values, the process will stop and just go to the next step.
I found some missing value keys: ionic_max_versions, ionic_update_api, ionic_min_background_duration.
So, what you have to do is adding some additional values in strings.xml:

<resources>
...
  <string name="ionic_app_id">${your_app_id}</string>
  <string name="ionic_channel_name">Master</string>
  <string name="ionic_update_method">auto</string>
  <string name="ionic_max_versions" >2</string>
  <string name="ionic_update_api">https://api.ionicjs.com</string>
  <string name="ionic_min_background_duration">30</string>
</resources>

Then the error will be resolved and live update will done.
Next is additional information while I was solving the problem.

2. ionic_update_api

First, I've got the missing key values from debugging and tracking the code IonicCordovaCommon.java inside the Android proejct, so I did not know what that mean and what is the appropriate values for that keys. I found a hint from the merged commit (https://github.com/ionic-team/ionic-cli/pull/4065/files), but it was not helpful to find the appropriate value.
Then I typed the value for ionic_update_api like following:

<string name="ionic_update_api">https://api.ionicjs.com</string>

and the error happened:

Uncaught SyntaxError: Unexpected token < in JSON at position 0

After I resolved the problem, I now know that the api address for checking the update is wrong. I fond the appropriate value https://api.ionicjs.com googling almost a week. It means that you can manipulate the api address.
I don't understand why this important information cannot be found anywhere.

Anyway, now the live update is perfectly done.

you can find the post in the Ionic Forum here: https://forum.ionicframework.com/t/appflow-live-update-cant-make-it-work/185996/9?u=dotorimook

Top comments (2)

Collapse
rangerrick profile image
Benjamin Reed

OH GOD thank you for this post. I changed the channel config and some plugin stuff at the same time and I was beating myself over the head trying to figure out what plugin initialization was busted. ;)

Fixing up strings.xml did it for me. 👍

Collapse
wmadden profile image
Will Madden

You deserve a medal! 🥇

🌚 Browsing with dark mode makes you a better developer.

It's a scientific fact.