如何使用Cordova/PhoneGap构建Sencha应用程序

3
为了客户需要,我需要使用Sencha Touch和Cordova构建原生应用程序。
为了提高性能,我使用SDK工具中的“sencha app build package”命令来压缩JavaScript源代码。
如果我在开发中使用Sencha并且使用Corova进行Webview,则没有问题。但是,我需要使用Cordova函数(如FileSystem等),这是我无法在Sencha中完成的。
问题在于当我使用“sencha app build package”时,会出现错误,例如“[ERROR] ReferenceError:Can't find variable: fileSystem”。
我阅读了许多关于Sencha + Cordova的文章,但其中没有一篇涉及使用Cordova + Sencha构建/压缩源码。
是否有人遇到过这个问题,以及您是如何解决的?
最好的问候
更新于05/31/2012
我为每个需要访问cordova变量的方法使用一个名为CordovaFunctions.js的文件,并且我的app.js和其他View / Controller调用CordovaFunctions.js中的方法...
以下是我的app.json:
{
/**
 * The application's namespace, used by Sencha Command to generate classes
 */
"name": "ImageDownloader",

/**
 * The file path to this application's front HTML document, relative to this app.json file
 */
"indexHtmlPath": "index.html",

/**
 * The absolute URL to this application in development environment, i.e: the URL to run this application
 * on your web browser during development, e.g: "http://localhost/myapp/index.html".
 *
 * This value is needed when build to resolve your application's dependencies if it requires server-side resources
 * that are not accessible via file system protocol.
 */
"url": null,

/**
 * List of all JavaScript assets in the right execution order.
 * Each item is an object with the following format:
 *      {
 *          "path": "path/to/script.js" // Relative path to this app.json file
 *          "update": "delta"           // (Optional)
 *                                      //  - If not specified, this file will only be loaded once, and
 *                                      //    cached inside localStorage until this value is changed.
 *                                      //  - "delta" to enable over-the-air delta update for this file
 *                                      //  - "full" means full update will be made when this file changes
 *
 *      }
 */
"js": [

    {
       "path": "cordova-1.7.0.js"
    },/*
    {
       "path": "CordovaFunctions.js"
    },*/
    {
        "path": "sdk/sencha-touch.js"
    }
    ,
    {
        "path": "app.js",
        "bundle": true,  // Indicates that all class dependencies are concatenated into this file when build 
        "update": "delta"
    }
],

/**
 * List of all CSS assets in the right inclusion order.
 * Each item is an object with the following format:
 *      {
 *          "path": "path/to/item.css" // Relative path to this app.json file
 *          "update": "delta"          // (Optional)
 *                                     //  - If not specified, this file will only be loaded once, and
 *                                     //    cached inside localStorage until this value is changed to either one below
 *                                     //  - "delta" to enable over-the-air delta update for this file
 *                                     //  - "full" means full update will be made when this file changes
 *
 *      }
 */
"css": [
    {
        "path": "resources/css/app.css",
        "update": "delta"
    }
],

/**
 * Used to automatically generate cache.manifest (HTML 5 application cache manifest) file when you build
 */
"appCache": {
    /**
     * List of items in the CACHE MANIFEST section
     */
    "cache": [
        "index.html"
    ],
    /**
     * List of items in the NETWORK section
     */
    "network": [
        "*"
    ],
    /**
     * List of items in the FALLBACK section
     */
    "fallback": []
},

/**
 * Extra resources to be copied along when build
 */
"resources": [
    "resources/images",
    "resources/icons",
    "resources/startup"
],

/**
 * File / directory name matchers to ignore when copying to the builds, must be valid regular expressions
 */
"ignore": [
    "\.svn$"
],

/**
 * Directory path to store all previous production builds. Note that the content generated inside this directory
 * must be kept intact for proper generation of deltas between updates
 */
"archivePath": "archive",

/**
 * Default paths to build this application to for each environment
 */
"buildPaths": {
    "testing": "build/testing",
    "production": "build/production",
    "package": "build/package",
    "native": "build/native"
},

/**
 * Build options
 */
"buildOptions": {
    "product": "touch",
    "minVersion": 3,
    "debug": false,
    "logger": "no"
},

/**
 * Uniquely generated id for this application, used as prefix for localStorage keys.
 * Normally you should never change this value.
 */
"id": "dfbad430-a63b-11e1-a218-a1757e9a8324"
}
1个回答

0
在您的 app.json 配置文件中,您需要告诉 Sencha 构建命令,您的应用程序需要使用 phoneGap 库。将其添加到 js 节点中:
/**
 * List of all JavaScript assets in the right execution order.
 * Each item is an object with the following format:
 *      {
 *          "path": "path/to/script.js" // Relative path to this app.json file
 *          "update": "delta"           // (Optional)
 *                                      //  - If not specified, this file will only be loaded once, and
 *                                      //    cached inside localStorage until this value is changed.
 *                                      //  - "delta" to enable over-the-air delta update for this file
 *                                      //  - "full" means full update will be made when this file changes
 *
 *      }
 */
"js": [
    {
        "path": "sdk/sencha-touch.js"
    },
    {
        "path": "cordova-1.5.0.js"
    },
    {
        "path": "app.js",
        "bundle": true,  /* Indicates that all class dependencies are concatenated into this file when build */
        "update": "delta"
    }
],

我很感激你的努力,但是我已经完成了这个任务。因为我在cordova和sencha之间使用了一个名为CaordvaFunctions.js的文件,所以它无法正常工作:[ERROR] ReferenceError: Can't find variable: fileSystem。我会更新我的帖子,并附上我的app.json内容。 - Alexandre B.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接