Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use PhoneGap with Android Studio 0.5.4?

Can anybody tell me how get Android Studio 0.5.x to properly import and build a PhoneGap project ?

I've successfully installed the JDK SE 1.8.0, Ant 1.9.3, PhoneGap 3.4.0 and Android Studio 0.5.4.

JAVA_HOME, ANT_HOME, ANDROID_HOME are properly set, PATH was extended to include the %JAVA_HOME%\bin as well as %ANDROID_HOME%\tools and %ANDROID_HOME%\platform-tools.

I can create a PhoneGap hello-world project as outlined here: http://phonegap.com/install/

The vanilla hello-world project as is will build and run with the configured AVD:

phonegap run android --emulator

However, when I try to import the project according to this tutorial into Android Studio 0.5.4, it won't compile.

First, import in 0.5.4 is entirely different from what is shown on the linked page, there are none of the presented options (you can only select the folder from which to import, the destination directory, and whether to "Replace jars with dependencies, when possible" / "Replace library sources with dependencies, when possible" and "Create Gradle-style (camelCase) module names", all selected by default).

Android Studio shows errors such as these:

Error:(19, 26) error: package android.annotation does not exist
Error:(26, 16) error: package org.json does not exist
Error:(30, 23) error: package android.content does not exist

However, I do see < Android API 19 Platform > and < JDK > in the External Libraries section, with android.jar and annotations.jar and e.g. android.annotation in there.

I tried to set minSdkVersion 19 for project helloWorld but this didn't fix anything.

like image 270
Arc Avatar asked Apr 09 '14 10:04

Arc


1 Answers

I've faced this same issue, except it's been with Cordova rather than PhoneGap. I'm unaware of what needs changing in the Android project to have it work in Android Studio (or Eclipse - found issues with both).

Instead I started to play around with versions. It looks like the error that occurs with Cordova version 3.5.0-0.2.4 doesn't occur with Cordova version 3.0.0. It's now building and running fine for me.

Getting an older Cordova version is simple, if on Mac OS X/*nix:

sudo npm install -g [email protected]

I suspect there is some sort of bug/inconsistency with the later Cordova versions. Note I chose v3.0.0 simply because I wasn't able to do the above for v3.1+.

If I get more time later on, I'll try analyse the differences between the 3.0.0 build and the 3.5.0 build.

like image 166
andrewb Avatar answered Oct 03 '22 17:10

andrewb