markmarijnissen / cordova-app-loader

Remote update your Cordova app
http://data.madebymark.nl/cordova-app-loader/index.html
644 stars 128 forks source link

Cannot load cdvfile on android #39

Closed guykileveryone closed 8 years ago

guykileveryone commented 9 years ago

I have cordova-app-loader working perfectly in browser and ios, but android devices (including the simulator) cannot seem to load the files. This results in BOOTSTRAP_OK not being set and it loading all the original app files again.

Failed to load resource: the server responded with a status of 404 (Not Found) cdvfile://localhost/persistent/app/CordovaPromiseFS.is?1430969702286 Failed to load resource: the server responded with a status of 404 (Not Found) cdvfile://localhost/persistent/app/cordova—app—loader—complete.is?1430969702286 Failed to load resource: the server responded with a status of 404 (Not Found) cdvfile://localhost/persistent/app/autoupdate.is?1430969702286 Failed to load resource: the server responded with a status of 404 (Not Found) cdvfile://localhost/persistent/app/app.is?1430969702286 Failed to load resource: the server responded with a status of 404 (Not Found) cdvfile://localhost/persistent/app/style.css?1430969702286 Failed to load resource: the server responded with a status of 404 (Not Found) cdvfile://localhost/persistent/app/countries.js?1430969702286 Failed to load resource: the server responded with a status of 404 (Not Found) cdvfile://localhost/persistent/app/style.css?1430969702286

EDIT: I just checked on a fresh install of the demo Cordova App Loader and got the same result. It fails at the 'update' stage.

rgreschner commented 9 years ago

I got exactly the same issue with the plugin and demo on Android.

The download of the app update data itself works as files are downloaded to 'app' directory, but on reload files are not found with cdvfile protocol in URL and 404ing. Using an URL like "file:///storage/emulated/0/app/app.js", they are accessible.

I'm using Cordova 5 with Android Platform Support 4.0.0.

Full list of plugins is:

cordova-plugin-whitelist 1.0.0 "Whitelist" org.apache.cordova.file 1.3.3 "File" org.apache.cordova.file-transfer 0.5.0 "File Transfer"

ExecutorBG commented 9 years ago

I seem to be having the same problem. using cordova 5 with android platform support 4.0.0

installed plugins cordova-plugin-file 2.0.0 "File" cordova-plugin-file-transfer 1.1.0 "File Transfer" cordova-plugin-whitelist 1.0.0 "Whitelist"

murlex commented 8 years ago

Is anyone has solution? I've got the same problem too.

agamemnus commented 8 years ago

This is because the whitelist plugin rejects cdvfile://: https://github.com/apache/cordova-plugin-whitelist/pull/6... see my fork here: https://github.com/agamemnus/cordova-plugin-whitelist.

murlex commented 8 years ago

Thanks @agamemnus! I've realized it already. I had problems of implementing Cordova-app-loader. Finally I've got it all working using the proper CSP:

<meta http-equiv="Content-Security-Policy" content="default-src * 'self' cdvfile://*; style-src 'unsafe-inline' 'self' cdvfile://*; script-src 'self' 'unsafe-eval' cdvfile://*">

See my implementation here for example: https://github.com/murlex/UpdatableApp

agamemnus commented 8 years ago

I tried your header, and that does not require a whitelist plugin change, so well done there! However, it doesn't take into account content://, code inline in html files, or JS code referenced from outside. You also don't need to repeat things after the default-src.

I am currently using this: <meta http-equiv="Content-Security-Policy" content="* * 'self' default-src 'unsafe-inline' 'unsafe-eval' http://* https://* data: cdvfile://* content://*;">

(Note that the permissions reset for scripts and styles you add script-src or style-src -- they aren't additive, and hence why I lump it all in default-src. If you want to separate it out, that will make the header much longer, and watch out for missing things)

murlex commented 8 years ago

Thank you! I'll take these corrections. I just a new in Cordova development so still possibly makes the new guy mistakes :)

micky2be commented 8 years ago

What I did on my side is to put <access origin="cdvfile://*" /> in my config.xml

yossi-shasho commented 8 years ago

the same problem happens to me on all my image resources. I am not using the whitelist plugin. any idea?

agamemnus commented 8 years ago

In Cordova 5, you have to or you get errors. Check your console in chrome. Not sure if this is intended.

micky2be commented 8 years ago

+1 No choice from Cordova Android 4.x. The whitelist plugin is mandatory to make it work.

agamemnus commented 8 years ago

I don't really understand why that was done... and then without any serious testing to compound the issue. :/

micky2be commented 8 years ago

This is Cordova. Not the plugin.

agamemnus commented 8 years ago

Yes, I should have been clearer.

betorobson commented 8 years ago

Thank you murlex, I have follow your implementation and It's great. I did a simple implementation just for understanding my issue on Android. Now I believe I'm ready to implement my Single Page App based on Android there.

Thank YOU!!!

ashleycoker commented 8 years ago

I can not solve this for love nor money. I have tried everything, but still when the app seems to download the new files and reboot to load them using the cdvfile:// protocol I just get a red failed line in the Chrome console (running from the app on the device) for every failed resource (such as app.js) and it fails. It then reboots back to shipped files. It does not work.

ObjectiveTruth commented 8 years ago

@ashleycoker, this is exactly what I'm finding. Been working on this for a day so far.

I can get the local files to load fine and execute, but when it downloads from my file server, it seems to download successfully and append to the DOM but it never runs. I don't get the permission error anymore after using @agamemnus's recommendation, so I don't think its that.

However, when it defaults back to the factory default, it seems to work fine. I'm thinking there's a silent CDV permission issue I'm encountering

I'm using cordova 5 with android platform support 4.0.0

installed plugins cordova-plugin-file 2.0.0 "File" cordova-plugin-file-transfer 1.1.0 "File Transfer" cordova-plugin-whitelist 1.0.0 "Whitelist"

agamemnus commented 8 years ago

I wonder how this plugin works. I have a mechanism that uses a server's last-updated date for my own update system. I don't think it is broken in 5 but not sure.

ObjectiveTruth commented 8 years ago

Tried running on Desktop chrome and apart from not finding cordova.js and having to add CORS on my file server, it seems to be working perfectly but still not joy on android thogh :sob:

ObjectiveTruth commented 8 years ago

Not sure if this will help some unfortunately soul out there in my shoes but check out @murlex's excellent tutorial repo: https://github.com/murlex/UpdatableApp for guidance

What made it all work for me was adding the following to config.xml

  <allow-navigation href="*://*/*"/>
ObjectiveTruth commented 8 years ago

@ashleycoker, I'm not super familiar with phonegap but it should be the same as long as you're building it locally using something like the command line. No idea how it works if you do a remote build through Adobe

darinda commented 8 years ago

Hi,

i thought i'd share my experiences on this since it was driving me crazy. What made it work for me was adding <access origin="cdvfile://*"/> to the config.xml file - even though it already had a <access origin="*"/> entry.

Additionally - since my app is built in AngularJS - i had to modify the imgSrcSanitizationWhitelist property of the $compileProvider to contain cdvfile://:

$compileProvider.imgSrcSanitizationWhitelist(/^\s*(https?|file|blob|cdvfile|content):|data:image\//);

Maybe this is helpful for someone.

ObjectiveTruth commented 8 years ago

@darinda Dude you're a lifesaver thank you for that. I couldn't get any of my files to reference the downloaded content properly.

I'm using Ionic and I didn't need to add the extra <access origin="cdvfile://*"/> to config.xml, just the stuff for $compileProvider

steaks commented 8 years ago

@darinda worked for me too. Thanks!

ObjectiveTruth commented 8 years ago

Closing the issue since it appears to have been resolved, if it is still an issue please reopen.

As an aside this information should be added to the README.md

jhash commented 8 years ago

You guys rock! This took me forever to find

youjenli commented 8 years ago

The approach <access origin="cdvfile://*" /> mentioned in the post of @ObjectiveTruth at Sep 6 works fine in android 6.0.1 Nexus 5X. Thank you!

Ross-Rawlins commented 7 years ago

I cant get this to work on IOS. I have used the meta tag

$compileProvider.imgSrcSanitizationWhitelist(/^\s*(https?|file|blob|cdvfile|content):|data:image\//);

and that compiler code but I still get told its unsupported.

nicowenterodt commented 7 years ago

@Ross-Rawlins are you using some WKWebview or UIWebview? It seems WKWebview doesn't support custom URL schemes at all ..

hughred22 commented 7 years ago

@nicowenterodt So if I use ionic plugin add https://github.com/driftyco/cordova-plugin-wkwebview-engine.git for iOs and it will break the cdvfile path?! I am having this issue and can not get it to work in iOs no matter what I add!!