cohenadair
cohenadair

Reputation: 2072

File plugin not working with PhoneGap Build

I've been battling with this for a while. I haven't found many other people with this problem, and the ones I did find, didn't have the File plugin installed.

In my case, the File plugin is installed as a dependency of File-Transfer.

Problem: When I build and install the application directly from my PC to my Android device, everything works fine, but when it's built with PhoneGap Build, it doesn't work.

What happens: In app.initialize(), I call cordova.file.applicationStorageDirectory:

var app = {
    initialize: function() {
        this.bindEvents();
    },

    bindEvents: function() {
        document.addEventListener("deviceready", this.onDeviceReady, false);
    },

    onDeviceReady: function() {
        initApp();
        alert(1);
        alert(cordova.file.applicationStorageDirectory);
        alert(2);
    }
};

When I build and install locally, all three alerts are shown, and the directory path is correct, but when it's built by PhoneGap Build alert(1); is shown, but the second two calls aren't. This leads me to believe that cordova.file is undefined.

I've tried using PhoneGap Build's remote debugging tool, but nothing seems to print in the console, despite the documentation saying it should.

Here are the plugins installed: enter image description here

And here is my config.xml:

<?xml version='1.0' encoding='utf-8'?>

<widget xmlns     = "http://www.w3.org/ns/widgets"
        xmlns:gap = "http://phonegap.com/ns/1.0"
        id        = "id-removed"
        version   = "0.0.0">

    <preference name="phonegap-version" value="3.3.0" />

    <name>Name removed</name>

    <description>
        Description removed.
    </description>

    <author email="email removed" href="removed">
        Removed
    </author>

    <content src="index.html" />

    <icon src="icon.png" />

    <preference name="Orientation" value="portrait" />

    <access origin="*" />

    <gap:plugin name="org.apache.cordova.camera" version="0.2.9"/>
    <gap:plugin name="org.apache.cordova.device-motion" version="0.2.6"/>
    <gap:plugin name="org.apache.cordova.device-orientation" version="0.3.5"/>
    <gap:plugin name="org.apache.cordova.file-transfer" version="0.4.2"/>
    <gap:plugin name="org.apache.cordova.geolocation" version="0.3.7"/>
    <gap:plugin name="org.apache.cordova.globalization" version="0.2.6"/>
    <gap:plugin name="org.apache.cordova.inappbrowser" version="0.2.4"/>
    <gap:plugin name="org.apache.cordova.network-information" version="0.2.7"/>
    <gap:plugin name="de.appplant.cordova.plugin.local-notification" version="0.7.4"/>
</widget>

Any help is appreciated.

Upvotes: 0

Views: 3298

Answers (2)

R&#233;mi Becheras
R&#233;mi Becheras

Reputation: 15232

Ok I just understand what were under my eyes hours ago :

In the official documentation , it said :

As of v1.2.0, URLs to important file-system directories are provided. [...]

While you are using the phonegap build platform to build your project, where the latest available version is 1.0.1

See there : https://build.phonegap.com/plugins/617

Will this situation, cordova.file will remain undefined.

Phonegap build seems encounter some difficulties to upgrade the plugins, even the core plugins.

Upvotes: 0

R&#233;mi Becheras
R&#233;mi Becheras

Reputation: 15232

Try this

var debugFilePlugin = function(){
    try{
        if (cordova.file && typeof(cordova.file == 'object')) {
            alert(JSON.stringify(cordova.file));
            if (cordova.file.applicationStorageDirectory) {
                alert(cordova.file.applicationStorageDirectory);
            }
        } else {
            alert('cordova.file is a ' + typeof cordova.file + ' value.');
        }
    } catch(e){
        var t = typeof e ;
        if(t == "object") {
            alert(JSON.stringify(e));
        } else if (t == "string") {
            alert(e);
        } else {
            alert("typeof e =" + t);
        }
    }        
};

debugFilePlugin();

Upvotes: 1

Related Questions