Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
443 views
in Technique[技术] by (71.8m points)

cordova - sencha touch with phonegap (using sencha cmd and phonegap build) causes Error : LocalFileSystem not defined

I followed these sencha cmd guide to produce a phoneGap based sencha touch 2 project: Using Latest Sencha Cmd v4.0.2.67 , Latest sencha touch 2.3.1 , phoneGap ver- 3.1.0

1) Make a sencha touch 2 project by :

sencha -sdk /path/to/sencha-touch-sdk generate app MyApp /path/to/www/myapp

2) Add phoneGap to the above project

sencha phonegap init

3) configure the phonegap.local.properties

phonegap.platform=android
phonegap.build.remote=true
phonegap.build.remote.username=myUseName
phonegap.build.remote.password=myPassword

4) Updated the config.xml by adding all the core plugins

<!-- Core plugins -->
    <gap:plugin name="org.apache.cordova.battery-status" />
    <gap:plugin name="org.apache.cordova.camera" />
    <gap:plugin name="org.apache.cordova.media-capture" />
    <gap:plugin name="org.apache.cordova.console" />
    <gap:plugin name="org.apache.cordova.contacts" />
    <gap:plugin name="org.apache.cordova.device" />
    <gap:plugin name="org.apache.cordova.device-motion" />
    <gap:plugin name="org.apache.cordova.device-orientation" />
    <gap:plugin name="org.apache.cordova.dialogs" />
    <gap:plugin name="org.apache.cordova.file" />
    <gap:plugin name="org.apache.cordova.file-transfer" />
    <gap:plugin name="org.apache.cordova.geolocation" />
    <gap:plugin name="org.apache.cordova.globalization" />
    <gap:plugin name="org.apache.cordova.inappbrowser" />
    <gap:plugin name="org.apache.cordova.media" />
    <gap:plugin name="org.apache.cordova.network-information" />
    <gap:plugin name="org.apache.cordova.splashscreen" />
    <gap:plugin name="org.apache.cordova.vibration" />

and removed the <preference name="permissions" value="none"/> permission config

5) Created a external js file named dirReader.js and included its path in app.json

dirReader.js Contents

window.onerror=function(msg, url, linenumber){
     alert('Error message: '+msg+'
URL: '+url+'
Line Number: '+linenumber)
     return true
    }

var dirList = [{name: 'Chart 1'},{name: 'Chart 2'}];
 // Wait for device API libraries to load
    //
    document.addEventListener("deviceready", onDeviceReady, false);

    // device APIs are available
    //
    function onDeviceReady() {
        alert("device ready");
            Ext.device.FileSystem.requestFileSystem(
                LocalFileSystem.PERSISTENT, 0, function(fs) {   // LocalFileSystem not defined error here
                alert("Root = " + fs.root.fullPath);
                var directoryReader = fs.root.createReader();
                directoryReader.readEntries(function(entries) {
                var i;
                for (i=0; i<entries.length; i++) {
                    //alert(entries[i].name);
                    var itemObj = {};
                        itemObj.name = entries[i].name;
                    dirList.push(itemObj);
                }
                var dirListString = JSON.stringify(dirList);
                alert(dirListString);
                }, function (error) {
                alert(error.code);
                })
                }, function (error) {
                alert(error.code);
            });
    }

6) Added 'Ext.device.FileSystem' in requires under app.js

7) Finally ran sencha app build native This causes many mumbo jumbo to take place in the command prompt (No Errors) . the app is compressed and uploaded to build.phonegap for android build. Build succeeds.

----------------------------------------------------------------------------------------

PROBLEM

The app installs and starts fine. I receive the "Device Ready" alert from the dirReader.js file. The next error I get is that LocalFileSystem is undefined in dirReader.js.

I tried lots of things but nothing works.

I checked that the built apk contains the plugins folder with all the plugins including the org.apache.cordova.file . Also , the cordova_plugins.js is present and has the window.LocalFileSystem entry.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I saw somewhere the same issue.. is the cordova_plugin.js contain

{
    "file": "plugins/org.apache.cordova.core.file/www/FileSystem.js",
    "id": "org.apache.cordova.core.file.FileSystem",
    "clobbers": [
        "window.FileSystem"
    ]
},

did you try build with >cordova build android

can you call to any other API method?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...