meteor / cordova-plugin-meteor-webapp

Cordova plugin that serves a Meteor web app through a local server and implements hot code push
MIT License
66 stars 74 forks source link

[meteor 1.10.1] android's webapp plugin is unable to download a new mobile version once a change is detected #93

Closed delki8 closed 4 years ago

delki8 commented 4 years ago

reproduction recipe:

$ meteor create hotcodepush-android-fail
$ cd hotcodepush-android-fail
$ meteor add-platform android
// add a mobile-config.js to the root directory with the following content:
App.appendToConfig('
    <edit-config file="app/src/main/AndroidManifest.xml"
                     mode="merge"
                     target="/manifest/application"
                     xmlns:android="http://schemas.android.com/apk/res/android">
        <application android:usesCleartextTraffic="true"></application>
    </edit-config>
');
$ meteor run android
// wait for the emulator to be opened
// change anything inside main.css or main.js

if you open a chrome tab and inspect the app running on android (by typing chrome://inspect) you'll be able to see the following error:

webapp.js?hash=1b0eb4b502ab8149f4b77aa36a3ab7362d8b590f:37 Error: Error downloading asset manifest
    at webapp_local_server.js:51
    at Object.callbackFromNative (cordova.js:287)
    at <anonymous>:1:9

dirty fix

replace this line: https://github.com/meteor/cordova-plugin-meteor-webapp/blob/master/src/android/WebAppLocalServer.java#L262 with this: HttpUrl rootUrl = HttpUrl.parse(currentAssetBundle.getRootUrlString().replace("localhost", "10.0.2.2"));

delki8 commented 4 years ago

It turns out we don't really have a bug here. I found out that Meteor already passes whatever the user fills as the --mobile-server to ROOT_URL. The ROOT_URL is then passed through the index.html and it gets read by the cordova-plugin-meteor-webapp.

So instead of a simple meteor run android if you do a meteor run android --mobile-server 10.0.2.2:3000your hot code push will probably work (once you add the right permissions as I mentioned in the reproduction recipe).

Closing this one.