1

I have installed the Phonegap using

$ npm install -g PhoneGap

And I have created the Project too. After that I did

$ PhoneGap build android

It gives [phonegap] detecting Android SDK environment... [phonegap] using the local environment [phonegap] adding the Android platform...

I am stuck with this screen for a lot of time.. I closed cmd and opened again and tried.. But again it stands on the same screen for lot of time..

I have installed Node.js and I have android SDk too. Please help Thanks in advance..

EDIT:

I closed again and opened.. It gives

Error : C:\Users\Kutty.cordova\lib\npm_cache\cordova-android\3.6.3\package\bin\create.bat: command failed with exit code 8

Please help..

My Path : C:\Users\Kutty\AppData\Roaming\npm\;%ANT_HOME%\bin

Kumar
  • 11
  • 2

4 Answers4

4

A) Software required:

1) MAC : [For both iOS, Android] a) Android Studios [For Android] b) ANT 1.8.1 c) NODE.JS

d) Xcode 5.1 and above [for iOS]

2) Windows : a) Eclipse ADT Latest [For Android] b) ANT 1.8.1 c) NODE.JS

B) Steps to install Phonegap/Cordova:

1) MAC:

  1. Open Terminal a. Install Android Studios

  2. Setup

your PATH environment variable on Mac OS

a. Open the Terminal program (this is in your Applications/Utilities folder by default).

i. Run the following command

$ touch ~/.bash_profile; open ~/.bash_profile

This will open the file in your default text editor. You need to add the path to your Android SDK platform-tools and tools directory. In my example I will use "/Development/android-sdk-macosx" as the directory the SDK is installed in (For Android Studios, it can be found in /Users/<user>/Library/Android/sdk/ by default). Add the following line:

$ export PATH=${PATH}:/Development/android-sdk-macosx/platform- tools:/Development/android-sdk-macosx/tools

Save the file and quit the text editor. Execute your .bash profile to update your PATH.

$ source ~/.bash_profile

Now every time you open the Terminal program your PATH will include the Android SDK

sudo npm install -g cordova

Create a new app

$ cordova create <directory name> <bundle identifier> <name of project>
$ cd <directory name>
$ cordova platform add android OR iOS
$ cordova run android OR iOS

If you come across problem of Please install Android target "android-19" then run android from Terminal. It will open up Android SDK manager and from there install Android 4.4.2 (API 19)

2) Windows:

  1. Open Command prompt a. Put ANT [Downloaded folder] folder into “android ADT folder”/sdk

  2. Setup your PATH environment variable on Windows

From the Desktop, right-click My Computer and click Properties.

Click Advanced System Settings link in the left column.

In the System Properties window click the Environment Variables button.

Select the PATH variable from the System variables section. Select the Edit button. i. You need to add the path to your Android SDK platform-tools and tools directory. In my example I will use C:\Development\android-sdk- windows as the directory the SDK is installed in. Append the following text into the text box: ii. ;C:\Development\android-sdk-windows\platform- tools;C:\Development\android-sdk-windows\tools iii. Save your edit. Close the Environment Variables dialog.

Additionally, you may need to include %JAVA_HOME%\bin to your PATH as well. To check to see if this is required, run a command prompt and type java. If the program cannot be found add %JAVA_HOME%\bin to the PATH. You may need to specify the full path instead of using the %JAVA_HOME% environment variable. Finally, you may need to include %ANT_HOME%\bin to your PATH as well. To check to see if this is required, run a command prompt and type ant. If the program cannot be found add %ANT_HOME%\bin to the PATH. You may need to specify the full path instead of using the %ANT_HOME% environment variable.

sudo npm install -g cordova

Create a new app

$ cordova create <directory name> <bundle identifier> <name of project>
$ cd <directory name>
$ cordova platform add android 
$ cordova run android
0

I also tried ,there is a problem in phonegap updated version . run the following commands in command prompt

npm uninstall -g phonegap  -> to unsinstall
npm install -gphonegap@4.2.0-0.24.2  -> to install specific version. 

Now use whatever sdk you have,it will work.

Arun
  • 1,177
  • 9
  • 15
0

PHONEGAP Manual Method

Another method is placing the things manually, and how it can be implemented is shown

below:

• set up the normal Android Application Project

• Create www folder inside assets

• download the phonegap zip file

• copy the phonegap jar file from downloaded phonegap place into libs folder

• copy the phonegap .js file from downloaded phonegap place into www folder that we

have created inside the assets.

• copy the xml complete folder and out into res folder of android

• create index.html file inside the www folder which is the gateway of the phonegap

application.

• Now we can transfer the control from MainActivity.java to our index.html which will

look like this:

"public class MainActivity extends DroidGap {

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

super.loadUrl("file:///android_asset/www/index.html");

}

}

• open the AndroidManifest.xml file and paste the code that is shown in the picture.

Figure 4.1: Android Manifest File which allows permissions for device usage.

41

After writing this code, now whatever we code in the index.html file will be shown on the

android emulator or the phone.

PHONEGAP CLI Method

Phonegap Command Line Interface(CLI) Method can be called as automated method because

commands will do all the work for you to initialize the PhoneGap project that we have to set up

by yourself in the manual method. Following are the steps that need to be followed in order to

set up the PhoneGap project:

Download Nod.js and install it.

• Now run this command "npm install -g cordova" on Node.js, this command will install

the cordova module with the help of Node Package Manager(npm) for windows, where

-g states that installation of cordova globally.

• Another command "cordova create first com.example.First FirstProgram", this command

will take little processing tim, the argument first will determine the directory of the

project, second argument com.example.First gets a package and the last argument

FirstProgram is define the application title.

• This command "cd first" will give the control inside the cordova project.

• Now this command "cordova platform add android" , it will set up the target platform

on which platform you want to install this application, other commands for several

platform are described below:

• Cordova platform add wp8cordova platform add windows

• cordova platform add amazon-fireos

• cordova platform add blackberry10

• cordova platform add Firefox's

• "cordova platforms ls" command will check the current platforms and we can also

delete the platform by "cordova platform rm amazon-fireos"

• Now the process come on the building block of application by running the command on

console " cordova emulate android".

42

• Finally this command will run the basic application "cordova run android" and the

settings of the folders like www in assets and all other things in AndroidManifest.html is

setup according to the phonegap project.

-2

add android sdks 'tools' and 'platform-tools' to path variable. Keep in mind if you have installed 'phonegap' always use 'phonegap' instead of 'cordova' anywhere.

I personally prefer using cordova.

Vishnuraj
  • 71
  • 10