Apache cordova file plugin does not load

Hi,

I’m trying to use org.apache.cordova.file plugin but it fails on load time. I’m very surprised because I understand org.apache.cordova.file plugin is very common. I’ve tried different cordova plugin file versions and even cordova versions too but I’m not able to find a way to make it work. Probably, I’m missing some fundamental step but I’ve read many times the documentations and I did not find anything …

In order to ensure it is not related to my app, I’ve installed a clean ionic template and I’m having the same problem. If I run with "CordovaSim I see following error.

!JavaScript ERROR: SyntaxError: Unexpected token '?' on line 2 for http://localhost:50480/plugins/org.apache.cordova.file/www/FileWriter.js 

If I start with an emulator I see following error.

Channel not fired: onFileSystemPathsReady

I’m able to easily reproduce the problem just executing following commands:

$ ionic -version
1.3.11
$ cordova -version
4.2.0
$ ionic start ionic-testfile -a 'TestFile' -i com.ionicframework.test.file tabs
Creating Ionic app in folder /Users/jcastro/workspace.picdeal/ionic-testfile based on tabs project

Downloading: https://github.com/driftyco/ionic-app-base/archive/master.zip
[=============================]  100%  0.0s

Downloading: https://github.com/driftyco/ionic-starter-tabs/archive/master.zip
[=============================]  100%  0.0s

Update config.xml
Initializing cordova project
…
$ cd ionic-testfile/
$ ionic plugin add org.apache.cordova.file
Fetching plugin "org.apache.cordova.file" via plugin registry
Running command: /Users/jcastro/workspace.picdeal/ionic-testfile/hooks/after_plugin_add/010_register_plugin.js /Users/jcastro/workspace.picdeal/ionic-testfile
$ ionic platform add android
Running command: /Users/jcastro/workspace.picdeal/ionic-testfile/hooks/before_platform_add/init_directories.js /Users/jcastro/workspace.picdeal/ionic-testfile
Creating android project...
…
Running command: /Users/jcastro/workspace.picdeal/ionic-testfile/hooks/after_plugin_add/010_register_plugin.js /Users/jcastro/workspace.picdeal/ionic-testfile

$ ionic emulate android -l -c
Setup Live Reload
…
Waiting for emulator...
HAX is working and emulator runs in fast virt mode
Booting up emulator (this may take a while).....BOOT COMPLETE
Installing app on emulator...
Using apk: /Users/jcastro/workspace.picdeal/ionic-testfile/platforms/android/ant-build/CordovaApp-debug.apk
Launching application...
LAUNCH SUCCESS
0     961179   log      deviceready has not fired after 5 seconds.
1     961181   log      Channel not fired: onFileSystemPathsReady

Just in case anyone else gets this issue I was able to make cordova plugin file works with Android/IOS emulators. Finally, I’m only having above problem with Cordovasim.
Currently I’m using following packages versions:

  • apache plugin org.apache.cordova.file 1.3.3 “File”
  • ngCordova $cordovaFile to use easier the plugin
  • cordova platforms android 3.7.1, ios 3.7.0

I’m running android/ios emulator with livereload so it is also very convenient and I do not need cordovasim anymore.

ionic build android; ionic emulate android -l -c

or

ionic build ios; ionic emulate ios -l -c

Hi @Jonimalabarea, would you mind to post your simple working aplication on github so others can learn the simple working sample immediately?

Hi abdshomad,

I was using Jboss CordovaSim to run my application and this was the source of my problem. I was not able to make Cordova File Plugin works with Jboss CordovaSim even with the default app created by ionic.

So, I’m not using anymore Jboss Cordovasim to emulate my app and I’m directly running it with Android emulator or IOS emulator. I do not make anything special in my app, just Cordova File plugin + cordovaFile from ngCordova. For example,

$cordovaFile.createDir(cordova.file.dataDirectory, registerDir, true)
  .then(function (success) {
		    	  console.log('enterCode: dir created ' + JSON.stringify(success));		    	  
  }, function (error) {
		    	  console.log('enterCode: dir not created ' + JSON.stringify(error));		    	
  });

Hi @Jonimalabarea, Thank you for the explanation. I have found simple working samples here: https://github.com/driftyco/ng-cordova/tree/master/demo/www/app/file I hope others will find it useful.

Hi Jonimalbarea,

I am facing the same issue, after installing cordova file plugin into my ionic app

!JavaScript ERROR: SyntaxError: Invalid character ‘\u0187’ on line 2 for http://localhost:54076/plugins/org.apache.cordova.file/www/FileWriter.js
!JavaScript ERROR: Error: Module org.apache.cordova.file.FileWriter does not exist. on line 1385 for http://localhost:54076/cordova.js.

I generated APK from the app, becuase of cordova file plugin issue. other plugins like Camera, IMEI, GeoLocation also not working in mobile. Please help me resolving the issue. I am stuck in this issue from past 5 days.

Thanks in advance.

Sorry, I cannot help you. I was facing that issue only using Cordovasim emulator so I was just testing the app using IOS or Android emulator as a workaround

Thanks for the reply.

Have you tried generating APK file from the app.?

If so, did file functionality is working in Mobile?

Please let me know.

or

is there any alternative plugin for File upload in cordova.

I was able to generate the apk and install it in a Android phone. The File plugin worked. I just faced that problem using Cordova sim.

Good luck!

Ya , there is some problem with cordovasim .

File transfer plugin -> while running in cordovasim , javascript files in the plugins gets appended with some special characters.

Hence i choose to install the plugin via command line & generated the APK file.

Installed the apk in Mobile. It worked fine for me(both file & file transfer).

Reason:Red hat JBOSS .8.04.1 IDE is having issues while developing Ionic applications.

If anyone facing issues while using in cordova file & filetransfer plugin.There is no problem with plugins.Issue is with JBoss -Cordovasim.

Thanks Jonimalabarea for response.