Cannot load cdvfile on android #39

Closed
guykileveryone opened this Issue May 7, 2015 · 30 comments

Projects

None yet
@guykileveryone

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

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

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
murlex commented Jun 5, 2015

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

@agamemnus
Contributor

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

@murlex
murlex commented Jun 8, 2015

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
Contributor

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
murlex commented Jun 9, 2015

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

@micky2be

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

@yossi-shasho

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

@agamemnus
Contributor
@micky2be

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

@agamemnus
Contributor

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

@micky2be

This is Cordova. Not the plugin.

@agamemnus
Contributor
@betorobson

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

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
Collaborator

@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
Contributor

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
Collaborator

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 😭

@ObjectiveTruth
Collaborator

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="*://*/*"/>
@ashleycoker

I had tried that but with no success.....I am using phonegap build though,
but should be the same?
Does that work on Android for you?

On Tue, Aug 18, 2015 at 11:29 PM, Jose Miguel Mendez <
notifications@github.com> wrote:

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

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


Reply to this email directly or view it on GitHub
#39 (comment)
.

Ashley Coker
w: ProWebSoftware.Net
e: ashley.coker@prowebsoftware.net
m: 077382 64519

Unit 7, Fosters Business Park, Old School Road, Hook, Hampshire, RG27 9NY, UK
Tel: +44 (0)1256 486557 Web: www.prowebsoftware.net, (Company No. 6898498)

@ObjectiveTruth
Collaborator

@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
darinda commented Sep 1, 2015

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
Collaborator

@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
steaks commented Sep 8, 2015

@darinda worked for me too. Thanks!

@ObjectiveTruth
Collaborator

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
jhash commented Oct 21, 2015

You guys rock! This took me forever to find

@JumpLink JumpLink referenced this issue in chrisben/imgcache.js Dec 17, 2015
Closed

v1.0rc2 breaks on Android #148

@youjenli

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

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment