New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot load cdvfile on android #39

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

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

This comment has been minimized.

Show comment
Hide comment
@rgreschner

rgreschner May 13, 2015

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"

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

This comment has been minimized.

Show comment
Hide comment
@ExecutorBG

ExecutorBG May 29, 2015

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"

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

This comment has been minimized.

Show comment
Hide comment
@murlex

murlex Jun 5, 2015

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

murlex commented Jun 5, 2015

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

@agamemnus

This comment has been minimized.

Show comment
Hide comment
@agamemnus

agamemnus Jun 8, 2015

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.

Contributor

agamemnus commented Jun 8, 2015

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

This comment has been minimized.

Show comment
Hide comment
@murlex

murlex 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

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

This comment has been minimized.

Show comment
Hide comment
@agamemnus

agamemnus Jun 8, 2015

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)

Contributor

agamemnus commented Jun 8, 2015

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

This comment has been minimized.

Show comment
Hide comment
@murlex

murlex 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 :)

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

This comment has been minimized.

Show comment
Hide comment
@micky2be

micky2be Jun 10, 2015

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

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

@yossi-shasho

This comment has been minimized.

Show comment
Hide comment
@yossi-shasho

yossi-shasho Jun 17, 2015

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

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

@agamemnus

This comment has been minimized.

Show comment
Hide comment
@agamemnus

agamemnus Jun 17, 2015

Contributor
Contributor

agamemnus commented Jun 17, 2015

@micky2be

This comment has been minimized.

Show comment
Hide comment
@micky2be

micky2be Jun 18, 2015

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

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

@agamemnus

This comment has been minimized.

Show comment
Hide comment
@agamemnus

agamemnus Jun 18, 2015

Contributor

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

Contributor

agamemnus commented Jun 18, 2015

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

@micky2be

This comment has been minimized.

Show comment
Hide comment
@micky2be

micky2be Jun 19, 2015

This is Cordova. Not the plugin.

This is Cordova. Not the plugin.

@agamemnus

This comment has been minimized.

Show comment
Hide comment
@agamemnus

agamemnus Jun 19, 2015

Contributor
Contributor

agamemnus commented Jun 19, 2015

@betorobson

This comment has been minimized.

Show comment
Hide comment
@betorobson

betorobson Jul 7, 2015

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!!!

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

This comment has been minimized.

Show comment
Hide comment
@ashleycoker

ashleycoker Aug 18, 2015

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.

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

This comment has been minimized.

Show comment
Hide comment
@ObjectiveTruth

ObjectiveTruth Aug 18, 2015

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"

Collaborator

ObjectiveTruth commented Aug 18, 2015

@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

This comment has been minimized.

Show comment
Hide comment
@agamemnus

agamemnus Aug 18, 2015

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.

Contributor

agamemnus commented Aug 18, 2015

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

This comment has been minimized.

Show comment
Hide comment
@ObjectiveTruth

ObjectiveTruth Aug 18, 2015

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 😭

Collaborator

ObjectiveTruth commented Aug 18, 2015

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

This comment has been minimized.

Show comment
Hide comment
@ObjectiveTruth

ObjectiveTruth Aug 18, 2015

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

ObjectiveTruth commented Aug 18, 2015

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

This comment has been minimized.

Show comment
Hide comment
@ashleycoker

ashleycoker Aug 18, 2015

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)

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

This comment has been minimized.

Show comment
Hide comment
@ObjectiveTruth

ObjectiveTruth Aug 18, 2015

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

Collaborator

ObjectiveTruth commented Aug 18, 2015

@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

This comment has been minimized.

Show comment
Hide comment
@darinda

darinda 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.

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

This comment has been minimized.

Show comment
Hide comment
@ObjectiveTruth

ObjectiveTruth Sep 6, 2015

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

Collaborator

ObjectiveTruth commented Sep 6, 2015

@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

This comment has been minimized.

Show comment
Hide comment
@steaks

steaks Sep 8, 2015

@darinda worked for me too. Thanks!

steaks commented Sep 8, 2015

@darinda worked for me too. Thanks!

@ObjectiveTruth

This comment has been minimized.

Show comment
Hide comment
@ObjectiveTruth

ObjectiveTruth Sep 12, 2015

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

Collaborator

ObjectiveTruth commented Sep 12, 2015

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

This comment has been minimized.

Show comment
Hide comment
@jhash

jhash Oct 21, 2015

You guys rock! This took me forever to find

jhash commented Oct 21, 2015

You guys rock! This took me forever to find

@youjenli

This comment has been minimized.

Show comment
Hide comment
@youjenli

youjenli Dec 29, 2015

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!

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

This comment has been minimized.

Show comment
Hide comment
@Ross-Rawlins

Ross-Rawlins Sep 6, 2016

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.

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

This comment has been minimized.

Show comment
Hide comment
@nicowenterodt

nicowenterodt Nov 10, 2016

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

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

@hughred22

This comment has been minimized.

Show comment
Hide comment
@hughred22

hughred22 Mar 21, 2017

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

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

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