简体   繁体   中英

Cordova Android platform upgrade from CLI 3 to 4 breaks build

I'm running cordova 5. I used to have the android platform 3.7.1 and everything was fine. Today I upgraded the android platform to 4.0.2 (cordova platform android update@4.0.2). Since then, my compiled projects get a 404 error when trying to load remote .js scripts. Went back to 3.7.1 and it works. What's the proper way to upgrade a Cordova Android project? Is there a new setting for network access?? Something I missed in the upgrade?

Posting the answer.. So far, the only way for me to make my project work again was to create a new cordova project and re-import plugins and edit config.xml. I tried upgrading the current project in its current folder but it would never work even if the upgrading was a success (according to cordova). Bottom line: upgrading does not work .

If you're running cordova 5.0 the chances are you haven't installed the white-list plugin .

cordova plugin add cordova-plugin-whitelist

or if you want to save the reference to your config.xml file:

cordova plugin add cordova-plugin-whitelist --save

You can find more info here .

This is because cordova uses cordova-android@4.0.0 as the default version now. http://cordova.apache.org/announcements/2015/04/15/cordova-android-4.0.0.html

You need to add the whitelist plugin as described by @LeftyX earlier.

cordova plugin add https://github.com/apache/cordova-plugin-whitelist.git

But then you also need to edit the config.xml to allow access to your sites - the whitelist plugin only allows access to file URLs by default.

The easiest way to restore functionality is to add:

<!-- A wildcard can be used to whitelist the entire network,
 over HTTP and HTTPS.
 *NOT RECOMMENDED* -->
<allow-navigation href="*" />

But as you can see, that is not recommended. You should really lock it down to make it more secure.

Other options are documented in the README for the whitelist plugin. https://github.com/apache/cordova-plugin-whitelist

Source: After I performed both the steps mentioned above, my 404s disappeared.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM