user1716672
user1716672

Reputation: 1073

Cannot build Phonegap project from command line

I have built a Phonegap app and am now trying to integrate it with Phonegap Build. I'm following the very simple guide here.

So I am doing:

sudo npm install -g phonegap
sudo phonegap create hello com.example.hello HelloWorld
cd hello

sudo phonegap local build android

The last command results in the error:

The command `android` failed. Make sure you have the latest Android SDK installed, and the `android` command (inside the tools/ folder) added to your path. Output: /bin/sh: 1: android: not found

I then did:

which android

with the result:

/home/mark/Development/adt-bundle-linux-x86_64-20130522/sdk/tools/android

which is the corrent path.

The phonegap version is 3.1.0-0.15.0.

Any ideas why I am getting this error?

Edit If I run:

sudo phonegap local build /home/mark/Development/adt-bundle-linux-x86_64-20130522/sdk/tools/android 

I get yet another error:

/usr/local/lib/node_modules/phonegap/lib/phonegap/local.build.js:141
    platformPath = path.join('.', 'platforms', platform.local);
                                                       ^
TypeError: Cannot read property 'local' of undefined
at LocalBuildCommand.module.exports.addPlatform (/usr/local/lib/node_modules/phonegap/lib/phonegap/local.build.js:141:60)
at LocalBuildCommand.execute (/usr/local/lib/node_modules/phonegap/lib/phonegap/local.build.js:95:32)
at LocalBuildCommand.run (/usr/local/lib/node_modules/phonegap/lib/phonegap/local.build.js:70:10)
at Object.build (/usr/local/lib/node_modules/phonegap/lib/phonegap/util/command.js:28:25)
at CLI.module.exports (/usr/local/lib/node_modules/phonegap/lib/cli/local.build.js:34:20)
at CLI.module.exports [as argv] (/usr/local/lib/node_modules/phonegap/lib/cli/argv.js:66:17)
at Object.<anonymous> (/usr/local/lib/node_modules/phonegap/bin/phonegap.js:24:21)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:349:32)

Upvotes: 0

Views: 3988

Answers (3)

Atilla Ozgur
Atilla Ozgur

Reputation: 14701

Laters version of android sdk moved adb to platform-tools. Try to include both tools and platform-tools in your path. see

~/Tools/adt-bundle-linux-x86_64-20131030/sdk $ cat tools/adb_has_moved.txt
The adb tool has moved to platform-tools/

If you don't see this directory in your SDK, launch the SDK and AVD Manager (execute the android tool) and install "Android SDK Platform-tools"

Please also update your PATH environment variable to include the platform-tools/ directory, so you can execute adb from any location.

I use following export commands.

export ANDROID_BUNDLE_HOME="$ATILLA_TOOLS/adt-bundle-linux-x86_64-20131030"
export ANDROID_SDK_HOME="$ANDROID_BUNDLE_HOME/sdk"
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

export PATH=$PATH:$ANDROID_SDK_HOME/tools
export PATH=$PATH:$ANDROID_SDK_HOME/platform-tools

both adb and android should work in command line. Also try to use

phonegap local build android

without sudo.

see following example

 $phonegap create deneme1 
[phonegap] created project at /home/atilla/Projects/Denemeler/a/deneme1 
 $cd deneme1/ 
 $phonegap local build android
[phonegap] adding the Android platform... 
[phonegap] compiling
Android... [phonegap] successfully compiled Android app

After this successful message try to find your platform and apk file.

 $ls -al platforms/ 
 $ls -al platforms/android/ 
 $ls -al platforms/android/bin

you should see HelloWorld-debug.apk in this directory.

-rw-r--r-- 1 atilla atilla 1542462 Ara 5 14:31 HelloWorld-debug.apk

Upvotes: 1

alfonsodev
alfonsodev

Reputation: 2754

install the phonegap npm global package with sudo, it's ok. But then you should run phonegap with your own user

sudo npm install -g phonegap
phonegap create hello com.example.hello HelloWorld
phonegap local build android

executing with sudo you are switching to root user therefore environment variables as $PATH are not necessarily the same.

Upvotes: 0

Cooper
Cooper

Reputation: 1

Try to Add your Android Path to your PATH Enviroment Variables.

if you use Linux, first try:

echo $PATH

This command display your PATH variable, search the Android path on this. If you don't see the android path, you need to add that path on your enviroment variable. Try this:

echo 'export PATH=$PATH:/home/user/mis_prog' >> /home/user/.bashrc

You must edit the configuration file of your login shell. As usually the BASH shell is the most used, you must edit your /home/user/.bashrc.

For this you will use a text editor or just a command to make the task easier.

If you use some Windows Version, you can edith the enviroment variable PATH from system propertyes, something like this: http://www.computerhope.com/issues/ch000549.htm

Upvotes: 0

Related Questions