Remote update your Cordova App based on https://github.com/markmarijnissen/cordova-app-loader
The aim of this project is help who has been facing some dificults to implement the cordova-app-loader. It can easily help you make an Mobile App that can be remote update. It is extremely important that you follow all steps.
This instructions presume that you will run it on Mac OS X or Linux Environment.
- Node.js
- NPM
- Gulp - Global installation
- Cordova - Global installation
- [for iOS] An Apple Computer running Mac OS X
- [for iOS] Xcode 6.4+
- [for Android] An Android Device
- It is not recommended test it on Android Emulator.
- Set up a Web Server
- Change host file
- Set up a proxy (my suggestion, squidman)
git clone https://github.com/betorobson/cordova-remote-update
cd cordova-remote-update
npm install
gulp
Set up your Web Server to resolve the domain cordovaremoteupdate.dev
and point it to folder remote-files
inside your project folder.
If are you using apache, you can make it editing the vhost like this example:
<VirtualHost *:80>
DocumentRoot "/var/www/cordova-remote-update/remote-files/"
ServerName cordovaremoteupdate.dev
</VirtualHost>
- Do not forget modify the DocumentRoot, you must put there your folder project full path +
/remote-files
Edit your host file as sudo, it might be at:
/etc/host
Add on the bottom file the follow line:
127.0.0.1 cordovaremoteupdate.dev
Open any browser and type:
http://cordovaremoteupdate.dev/
You must see a gray color page which containing a pharse: appWrapper
This is the most important thing. You must set up it and be sure that it is working properly. So, if you are not familiar with how to set up it, I strongly recommed you install squidman.
It will make your devices able to access the address cordovaremoteupdate.dev
. If you remember, we did it one step before.
Install it from http://squidman.net/, and follow all instructions. It is painless :)
When you finished, you must open squidman.
Add on Clients section your wifi ip subnet, for example: 192.168.2.0/24
Remove any domain on Direct section
On template section find the following section:
# protect web apps running on the proxy host from external users
http_access deny to_localhost
And comment out the second line with a #.
Next, you need to tell Squid where your hosts file is
# hosts file
hosts_file /etc/hosts
- Even if after follow these proxy instructions you did not make it, have a look in this article http://egalo.com/2012/05/29/testing-mac-web-site-using-local-hostname-on-mobile-device/
- Before start it, be sure your webserver is running.
(http://egalo.com/uploads/2012/05/SquidMan-main-window.png)
For Android, follow these instructions http://webcazine.com/13617/android-5-0-lollipop-how-to-setup-proxy-server/
For iOS, follow these instructions http://www.ibvpn.com/billing/knowledgebase/72/How-to-configure-proxy-usage-for-iphoneoripad.html
Do not forget to put your computer IP on proxy setup, also put there port number 8080
Now you whould be able to browse through the proxy on your computer. To be sure, open a browser like Chrome or Safari, type http://www.google.com/ and then try make a search. After that, if you can browse on internet, your are fine to the next step.
In both of your devices, open a browser and type http://cordovaremoteupdate.dev/
.
You must see a gray color page which containing a pharse: appWrapper
, it must be the same what happen on step 6.
Run the command bellow on terminal, on your project folder. It will generate all your remote files.
gulp
You might see something like that:
[18:23:28] Starting 'default'...
[18:23:28] Starting 'mobile'...
[18:23:28] Starting 'copyMobileAppFilesToMobileRemoteFolder'...
[18:23:28] Finished 'mobile' after 15 ms
[18:23:28] Finished 'default' after 17 ms
[18:23:28] Finished 'copyMobileAppFilesToMobileRemoteFolder' after 102 ms
[18:23:28] Starting 'bumpTimestampFile'...
[18:23:28] Finished 'bumpTimestampFile' after 8.62 ms
[18:23:28] Starting 'mobileMarkup'...
[18:23:28] Finished 'mobileMarkup' after 39 ms
[18:23:28] Starting 'generateManifest'...
[18:23:28] Finished 'generateManifest' after 52 ms
[18:23:28] Starting 'copyRemoteMobileFolderToMobileFolder'...
[18:23:28] Finished 'copyRemoteMobileFolderToMobileFolder' after 34 ms
[18:23:28] Starting 'bumpTimestampFile'...
[18:23:28] Finished 'bumpTimestampFile' after 2.23 ms
[18:23:28] Starting 'generateManifest'...
[18:23:28] Finished 'generateManifest' after 43 ms
Now your remote files were generated. Before compile your app, it would be better try another test on your devices.
Run the commands bellow on mobileApp
folder which is in your project folder.
cordova build android
cordova build ios
Now, plug your android device and run:
cordova run android
For iOS simulator, you just need run:
cordova run ios
For iOS devices, you need open your project on Xcode, plug a iOS device and then run your project from Xcode.
After having your project comiled, it is time to remote update it. In order to show how remote update, we will changed a javascript file which has a simple innerHTML instruction.
On your text editor, open mobileApp/src/js/app.js
. Look at line #55 and change Hello world 011
to My app has been remote updated
Now, run gulp tasks again in order to renegerate all source files.
gulp
Put your app on background and open up it again. You must see a spinner dialog tell you that your app is updataing. After that, the spinner will be close and your app will automatically