3

I was downloading files using Cordova File, Cordova FileTransfer and Cordova Device API and checked all of those inside windows XDK app but cordova.file is undefined inside cordova crosswalk builds, I use same version and same code in Cordova windows build (using cmd) and it works.

Intel XDK ver 1621

org.apache.cordova.file: 1.3.2

my html at end of body:

<script src="./cordova.js"></script>
<script src="./intelxdk.js"></script>
<script>
function onDeviceReady() {
   console.log(cordova.file);
   alert(cordova.file);
}
document.addEventListener("deviceready", onDeviceReady, false);
</script> 

Is there other solution to get cordova.file.dataDirectory?

or I can just wait for another release to manage that?

Developia
  • 3,928
  • 1
  • 28
  • 43

2 Answers2

3

Just for reference:

org.apache.cordova.file version used in XDK(1621) is 1.1.0 and it doesn't have cordova.file so I changed File plugin version in XDK to 1.3.2 and no result since using Emulator or Debugger (using XDK Crosswalk app)

I'm sure that File plugin is included using this method:

JSON.stringify(cordova.require('cordova/plugin_list').metadata, null, 1)

but Emulator and Debugger keep using version 1.1.0

Then I build it from BUILD page in XDK and it works and shows using version 1.3.2. Problem Solved.

I'm sorry that I didn't try that before posting, but in my defence building every time, download it, then install it on device takes so much time, like 20 mins for each test and it's not very logical.

Update plugins for Emulator

When I find out that XDK using default version of plugins in emulator, I decided to update plugins manually in XDK Folder in Windows:

%LOCALAPPDATA%\Intel\XDK\xdk\components\server\cordova-plugins

I just removed org.apache.cordova.file folder and got new clone from https://github.com/apache/cordova-plugin-file to make my tests in Emulator with updated version.

Use updated plugins in Intel App Preview (it may cause issues with other tabs)

Just update plugins in this folder in Windows:

%LOCALAPPDATA%\Intel\XDK\xdk\brackets\b\extensions\default\StaticServer\node\node_modules\cp\res\middleware\cordova\intel-app-preview\android\plugins

and Debugger works well with updated plugins.


Make it easy for update

Clone from git like this in each folder:

In folder org.apache.cordova.file

git init && git remote add origin https://github.com/apache/cordova-plugin-file.git && git pull

now you have all versions in git.

For updating all plugins you can just run this bash command in plugin root directory: (in Windows use Git Bash)

for i in $(find $PWD -maxdepth 1 -type d); do echo $i && cd $i && git pull; done
Developia
  • 3,928
  • 1
  • 28
  • 43
  • I just checked the plugins that I use - file, file-transfer, geolocation, network-status and they were all old. You saved me hours. Anyone know how to automatically updated them all? – Alien Technology Jan 06 '15 at 23:29
  • 1
    The Debug option uses yet another copy of the plugins found at: %LOCALAPPDATA%\Intel\XDK\xdk\brackets\b\extensions\default\StaticServer\node\node_modules\cp\res\middleware\cordova\intel-app-preview\android\plugins\ – Alien Technology Jan 07 '15 at 00:53
  • Thank you @AlienTechnology, I updated answer with Debug location. That bash command may help you with automatic update :) – Developia Jan 07 '15 at 07:16
  • 2
    This solution will work for the Emulate tab, but I advise against making updates anywhere else, as it may cause issues with other tabs. We are updating the "built-in" plugins for the next release, in the meantime, you can use the latest version of a plugin in your build by specifying the version explicitly in the Projects tab plugins panel or by making the version number blank in that same panel (click the pencil icon that appears when you "check" the plugin to change the version of the plugin that is used during build). – xmnboy Jan 08 '15 at 17:31
  • thanks you very much @Developia I was going to crazy. tool is a good tool i hope they will fix this plugin update issue soon. – hdayi Jan 20 '15 at 12:09
  • @Developia thanks for the great post , but can i ask how can you test file plugin on emulator , for example creating files or reading files ?! – ProllyGeek Feb 20 '15 at 17:56
  • 1
    @ProllyGeek I didn't really use file plugin on emulator (like reading and writing files), just watched console logs and testing app other functionalities. (updating file plugin in emulator remove errors in console) – Developia Feb 27 '15 at 18:30
0

Are you sure the plugin was added? Try building again and looking at the build log. It sounds like an error during the build that prevented the plugin from being added.

Ian Maffett
  • 176
  • 3
  • 1
    To see what plugins have been included in your build you can inspect the string returned by this code `JSON.stringify(cordova.require('cordova/plugin_list').metadata, null, 1)` -- just as a way to confirm the plugin is getting included in your build. If it is getting included in the build but the plugin namespace is not showing up, there may be some other issue with the build system or with that plugin and Crosswalk. – xmnboy Jan 05 '15 at 21:47
  • Thanks Ian, but yeah it loaded correctly, but not true version, and thank you Mr. Fischer ( @xmnboy ) for taking care of StackOverFlow questions, your code snippet helped to find out solution. – Developia Jan 06 '15 at 05:36