Ionic Cordova Hot Update (referenced from www.zyyapp.com/post/116.html)

Source: Internet
Author: User
Tags file url

The previous article Cordova HTML packaging cheer Android app http://www.zyyapp.com/post/115.html

Cordova Hot update is a big pit, and I looked at it all day and night before I understood it. Online tutorials are not the point, they only said in the local debugging, did not say that the release to their own server, only one said but not detailed.

Below is no pit of the tutorial, package you shunliu to finish the process.

    1. Open a command prompt into the project directory, if you can only run the Cordova command in node. js command prompt, because you did not add the path to node. js in the system variable path.

Once added, you can run the Cordova command at a command prompt.

2. Enter the engineering catalogue

3. Add a hot update plugin

Cordova Plugin Add Cordova-hot-code-push-plugin

Or

Ionic plugin Add Cordova-hot-code-push-plugin

(Other tutorials say to install Cordova-hot-code-push-local-dev-addon, in fact, not this, he just help you debug use.) )

Install the Hot Update Command tool. It's relatively slow to install, you need to wait a minute.

NPM install-g CORDOVA-HOT-CODE-PUSH-CLI

(If you installed Taobao NPM you can enter CNPM install-g cordova-hot-code-push-cli, Taobao npm installation tutorial http://www.zyyapp.com/post/114.html)

4. Here to explain the principle, do not want to see the words jump directly to the 5th step, this step no operation!

We need to add someone to update the template for the check file. None of this other tutorials, I was seen in the official tutorials abroad.

The principle of hot update is that each time you launch the app, you will compare the local Chcp.json file to the service.

The contents of the Chcp.json file are as follows:

The format of this content on the server is the same.

Each time the app launches checks if the value of release in the local Chcp.json file is the same as in the server, the smart student has released the value as a time.

If not the same, start the update, the app will first copy the local www folder, named the server's release value, and then compare the Chcp.manifest file

The contents of the Chcp.manifest file are as follows, he contains all the files under the WWW folder, and they all have hash values. The update will compare the hash value to see which file has changed, download the corresponding file from the Content_url path and copy it to the folder named after the server release value, so it saves traffic and is fast.

After the update, the parameters define what time is updated after the download, and if start indicates the next startup. If it is now, it is updated immediately after download. There are pros and cons in both ways, and you can experience the same.

The tradeoff is resume that the updates are installed when you switch from the background.

After the update, the app loads the resource file from the folder named after the server release value. This allows each update to be replaced by a resource folder, ensuring that the update is not visible because of the cache.

5. After installing Cordova-hot-code-push-plugin, the WWW folder already has Chcp.json and chcp.manifest, but we modify index.html and other files after how to update Chcp.json And Chcp.manifest, of course, do not manually change the release value, and do not have to manually change the hash.

We need mister into a Chcp.json template.

Enter CORDOVA-HCP init in the project directory

Need to enter a name, here you fill in the name of the app, such as klkj (do not fill in Chinese OH)

Amazon S3 doesn't need to fill in (this is where you fill out your Amazon server and hot update files, because you don't have Amazon services so you don't have to fill them out.) )

Path S3 not required

Just fill in these 3, others press ENTER directly. Update method Fill start indicates that the application will be updated when the next launch, fill now means to download the update file directly after the update, fill resume in the background to switch from the time to install the update.

Enter the full URL to fill in the path to the server where you put the update file.

The Cordova-hcp.json file is generated in the project root directory

The contents are as follows

Ios_indentifier and Android_identifier These two lines can be deleted, no use.

6. Enter CORDOVA-HCP build to regenerate Chcp.json chcp.manifest in the www file, where Chcp.json's release value is the time to enter the command.

We then put the contents of the entire WWW directory into the service and put it in the Content_url path. Mine is placed in the WWW folder in the root directory of the www.zyyapp.com site.

7. Modify the CONFIG. config file, which is located in the project's more directory.

Add to

<chcp>

<config-file url= "Http://www.zyyapp.com/www/chcp.json"/>

</chcp>

8. Open Android Studio

Modify CONFIG. res-xml under the folder

9. Copy the file under WWW to the platforms\android\assets\www file, overwriting the same file.

Install apps to your phone with Android studio.

Change the index file in the bottom folder.

Run at the command prompt

CORDOVA-HCP Build

At this time Chcp.json and Chcp.manifest will be updated. For the sake of convenience, you directly overwrite the contents of the WWW folder to the server.

Your phone opens the app, wait a moment, then turn off the app and turn it back on. You should see your updated content at this time.

This concludes the tutorial, if you do not know you can leave a message below.

Ionic Cordova Hot Update (referenced from www.zyyapp.com/post/116.html)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.