• info@happli.be

Category ArchiveAndroid

Adding Android platform to an existing Cordova app

Today, I tried adding a platform to an existing cordova app, which used to work under iOS  was developed on a Macbook Pro. This post lists the things I had to do in order to get it working and the bumps I hit.

Setup the environment

You have to follow the Android platform guide. It’s very well explained and easy to follow. I found it pretty annoying that I’ve had lots of timeouts during the download of the several packages (through the SDK manager). Just keep on trying and you’ll end up with a working environment.

I’ve had another problem when I tried to run the emulator. I was told that Intel HAXM wasn’t installed, so I installed it.

But I couldn’t get the emulator running, I didn’t have much info through the avd manager, so I created a blank project in Android Studio, then I tried to run it in the emulator. And then I was able to read more info about the problem:

Failed to sync vcpu reg.

I was just one google search away from getting it running This SO post helped me. This message seemed to be in relation with the VirtualBox that was running on my Mac at the same time. Shutting down the VirtualBox VM allowed me to get the Android emulator running.

Add the Android platform to the cordova project

cordova platform add android.

So far so good, but when trying to compile the app like below, I had a problem.

cordova build android

I was told that

Screen Shot 2015-09-28 at 22.28.33

Multiple dex files define Landroid/support/annotation/AnimRes;

I found the solution in this post. I simply had to remove the android v4 support from my project’s plugins. I don’t know how this one got there.

Debug the project

Once able to build the project and to make it run, I needed a way to debug it. Just launch chrome and type chrome://inspect/#devices in the address bar (the app must be running first).

Conclusion

It took me less than 2 hours to make my project run on Android. Most of that time was linked to the setup of the environment.  So I’m still convinced that cordova was the right choice to build this cross-platform mobile app.