3

I am developing a new Phonegap 3 application. I find the development process very slow. Each time I want to test a change in my app, I have to run in the console:

phonegap run android

This command takes about 30 seconds to run! Any idea on how to improve the time to test each change?

poiuytrez
  • 21,330
  • 35
  • 113
  • 172

2 Answers2

1

If you are developing for android using ecllipse you can use an android handset, connect it with your development machine with usb cable and install necessary drivers from here . Drivers are required mostly for windows in mac and linux it is usually not necessary. After set up it is just a matter of clicking run in your ide.

Community
  • 1
  • 1
Illegal Argument
  • 10,090
  • 2
  • 44
  • 61
0

If you have a huge amount of files (libraries with demos, non-minified files, etc.), installing on the app can take a long long time.

I created this hook (added to before_prepare) which only copies the necessary files (specified in "requirements.json" in my project).

You need to run cd hooks/before_prepare && npm install ncp to install the dependency.

hooks/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);
}

example requirements.json

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

Note that you can move stuff directly into the build www directory (inside platforms) but they have different paths under ios and android

Richard Löwenström
  • 1,533
  • 13
  • 16