Friday Sep 20, 2013

YouTube: How to Develop in Cordova & Deploy to Android

I've been experimenting a bit with Cordova development in NetBeans IDE. In this YouTube clip, I show you how to get started setting up Cordova, while here you see the creation of a new Cordova application, with deployment to an Android emulator:

However, as you see in the screencast above, the Android emulator is extremely slow. The web abounds with complaints about this, as well as information about Genymotion, the solution to the problem, since Genymotion is a really fast Android emulator.

Once you have a virtual machine set up, together with Genymotion, you're good to go. However, once you've created an APK file, i.e., an archive of an Android application, you need to use the ADB tool to deploy to Genymotion. To Simplify that, I created a small plugin, which adds an action to APK files for deploying to Genymotion. Here you see a small YouTube clip that aims to illustrate that Genymotion is really fast, I must say I was very impressed. Now the only slow part is the building of the APK file.

And here's the Action that uses the ADB tool to deploy to Genymotion.

@ActionID(
        category = "Run",
        id = "org.nb.geny.model.Deploy2GenymotionAction"
)
@ActionRegistration(
        displayName = "Deploy to Genymotion"
)
@ActionReference(
        path = "Loaders/application/x-java-archive/Actions", 
        position = 1600)
public final class Deploy2GenymotionAction extends AbstractAction implements LookupListener {

    private Lookup.Result<DataObject> result;
    private DataObject context;

    public Deploy2GenymotionAction() {
        putValue(DynamicMenuContent.HIDE_WHEN_DISABLED, true);
        result = Utilities.actionsGlobalContext().lookupResult(DataObject.class);
        result.addLookupListener(
                WeakListeners.create(LookupListener.class, this, result));
        resultChanged(new LookupEvent(result));
    }

    @Override
    public void actionPerformed(ActionEvent ev) {
        try {
            execute();
            StatusDisplayer.getDefault().setStatusText(context.getPrimaryFile().getNameExt());
        } catch (InterruptedException ex) {
            Exceptions.printStackTrace(ex);
        } catch (ExecutionException ex) {
            Exceptions.printStackTrace(ex);
        }
    }

    public Integer execute() throws InterruptedException, ExecutionException {
        ExternalProcessBuilder processBuilder = new ExternalProcessBuilder("/usr/bin/adb").
                addArgument("install").
                addArgument("-r").
                addArgument(context.getPrimaryFile().getPath());
        ExecutionDescriptor descriptor = new ExecutionDescriptor()
                .frontWindow(true)
                .controllable(true);
        ExecutionService service = ExecutionService.newService(
                processBuilder,
                descriptor,
                "adb installation");
        Future<Integer> task = service.run();
        return task.get();
    }

    @Override
    public boolean isEnabled() {
        return context.getPrimaryFile().getExt().equals("apk");
    }

    @Override
    public void resultChanged(LookupEvent le) {
        Collection<? extends DataObject> p = result.allInstances();
        if (p.size() == 1) {
            context = p.iterator().next();
        }
    }

}
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« September 2013 »
SunMonTueWedThuFriSat
2
3
4
5
8
14
15
     
       
Today