3

我正在开发一个新的 Phonegap 3 应用程序。我发现开发过程非常缓慢。每次我想测试我的应用程序中的更改时,我都必须在控制台中运行:

phonegap 运行安卓

此命令运行大约需要 30 秒!关于如何缩短测试每个更改的时间的任何想法?

4

2 回答 2

1

如果您正在使用 ecllipse 为 android 开发,您可以使用 android 手机,使用 USB 电缆将其与您的开发机器连接,并从此处安装必要的驱动程序 。mac 和 linux 中的 windows 大多需要驱动程序,通常不需要。设置完成后,只需在您的 ide 中单击运行即可。

于 2013-10-02T06:02:35.213 回答
0

如果您有大量文件(带有演示的库、非压缩文件等),在应用程序上安装可能需要很长时间。

我创建了这个钩子(添加到 before_prepare),它只复制必要的文件(在我的项目中的“requirements.json”中指定)。

您需要运行cd hooks/before_prepare && npm install ncp以安装依赖项。

钩子/before_prepare/010copy_assets.js

#!/usr/bin/env node

console.log("=== Running copy required assets hook ===");

var fs = require('fs'),
    path = require('path');

var mkdirSync = function(path) {
    try {
        fs.mkdirSync(path);
    } catch (e) {
        if (e.code != 'EEXIST') throw e;
    }
}

var mkdirpSync = function(dirpath) {
    var parts = dirpath.split(path.sep);
    for (var i = 1; i <= parts.length; i++) {
        mkdirSync(path.join.apply(null, parts.slice(0, i)));
    }
}

try {
    var ncp = require('ncp').ncp

    var requirements = require('./../../myproject/requirements.json');

    ncp.limit = 200;
    ncp.stopOnErr = true;

    requirements.forEach(function(requirement) {

        var source = './myproject/' + requirement;
        var destination = './www/' + requirement;

        var folders = destination.split('/');
        folders.pop();

        mkdirpSync(path.normalize(folders.join('/')));

        ncp(source, destination, function(err) {
            if (err) {
                console.log('====== Error! Did not copy asset from ' + source + ' to ' + destination + ' ======');
                console.error(err);
                process.exit(1001);
            } else
                console.log('====== Copied asset from ' + source + ' to ' + destination + ' ======');
        });

    });

} catch (e) {
    console.error(e);
    console.error(e.stack);
    process.exit(1000);
}

示例 requirements.json

[
    "js",
    "css",
    "img",
    "index.html"
]

请注意,您可以将内容直接移动到构建 www 目录(平台内部),但它们在 ios 和 android 下具有不同的路径

于 2014-09-23T11:24:22.897 回答