10

I am trying to migrate my existing project from cordova 2.1 to the latest, 3.1 which can be installev vía command line,

I already have the Android SDK installed,

So:

sudo npm install -g cordova // All good
cordova create hello com.example.hello HelloWorld // All good
cordova platform add android // Then it fires:

Checking Android requirements...
[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: ]

So I installed Macports and tried:

sudo port install android

Which logs:

Warning: All compilers are either blacklisted or unavailable; defaulting to first fallback option
Warning: Xcode does not appear to be installed; most ports will likely fail to build.
--->  Cleaning android
--->  Scanning binaries for linking errors: 100.0%
--->  No broken files found.

Any idea what am I missing here?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Toni Michel Caubet
  • 19,333
  • 56
  • 202
  • 378

5 Answers5

10

It's work cordova Android for MAC 1000000000%. I fought solution and now i'm working try this @Toni Michel Caubet. I will happy to share my Answer.

STEPS:

Open Your Terminal and followed by,

  1. touch ~/.bash_profile

  2. open ~/.bash_profile

  3. PATH="/Users/System-Name/Documents/android-sdk-macosx/sdk/tools:/Development/android-sdk-macosx/sdk/platform-tools:$PATH" (This is Android SDK Location to stored in My system )

enter image description here

4.Save the file and quit the text editor.

5.Execute your .bash_profile to update your PATH:

source ~/.bash_profile

if you want to see your environment path:

7.In your terminal type: set

After you can see like

enter image description here

8.As far as your made it very correct. After your enter command like cordova platform add android. you get following error. because Java SDK doesn't too set environment PATH.

enter image description here

9.open ~/.bash_profile. Add JAVA_HOME value

enter image description here

10.You can see your environment like STEP 7 set. You should be able see:

enter image description here

11.Successfully created environment now you can create Android project with Cordova or PhoneGap

enter image description here

Bruno Peres
  • 2,980
  • 1
  • 21
  • 19
codercat
  • 22,873
  • 9
  • 61
  • 85
  • Hi, thanks a lot for your time but this didnt work fo rme... i think the problem started when i opened `source ~/.bash_profile` and it as empty.. – Toni Michel Caubet Nov 30 '13 at 20:37
  • I had this same error because I didn't have the sdk and all the stuff required, then I just did **brew install android-sdk**, ran **android**, installed everything needed(took me ~2h to install everything) and added **export ANDROID_HOME=/usr/local/opt/android-sdk** to my **.bashrc**. There's no need for such a work – betoharres Sep 15 '14 at 09:22
4

When you installed the Android SDK, it will come with a bunch of folders, like build-tools, platform-tools, tools, and some others. You need to add platform-tools and tools to your main $PATH environment variable.

See the docs here about how to add things to your PATH for whichever system you are on (Windows or Mac): http://cordova.apache.org/docs/en/3.1.0/guide_platforms_android_index.md.html#Android%20Platform%20Guide

Here is how you would edit the $PATH on Windows:

  1. Click on the Start menu in the lower-left corner of the desktop, right-click on Computer, then click Properties.

  2. Click Advanced System Settings in the column on the left.

  3. In the resulting dialog box, press Environment Variables.

  4. Select the PATH variable and press Edit.

  5. Append the following to the PATH based on where you installed the SDK, for example: ;C:\Development\adt-bundle\sdk\platform-tools;C:\Development\adt-bundle\sdk\tools

  6. Save and close both dialogs.

MBillau
  • 5,366
  • 2
  • 28
  • 29
  • The problem is that I don't understand the docs, from where I need to set what command and what's the path? ( Its point 2 of my question ) – Toni Michel Caubet Nov 20 '13 at 10:26
  • You're confused about the $PATH environment variable and the current working path of whichever folder you are on. The $PATH is a global variable that your Windows system uses to find programs. When you are in a command prompt and type `node`, Windows doesn't know where the `node` program is, so it starts looking in all of the folders listed in the PATH variable. So figure out where you installed the android-sdk (search for "build-tools" if you can't find it). Copy that file location (also called that file's path) and edit the (global environment variable) $PATH. – MBillau Nov 20 '13 at 14:27
  • 1
    I use Mac OSX, is there any way you can tell me wich file to edit and what to put? thanks a lot – Toni Michel Caubet Nov 20 '13 at 14:34
  • I don't use Mac OSX, but according to the documentation, you can do: "For Cordova command-line tools to work, you need to include the SDK's tools and platform-tools directories in your PATH environment. On Mac, you can use a text editor to create or modify the ~/.bash_profile file, adding a line such as the following, depending on where the SDK installs: export PATH=${PATH}:/Development/adt-bundle/sdk/platform-tools:/Development/adt-bundle/sdk/tools After this open a new terminal and type "android" and "adb" to make sure it was added to the PATH correctly. – MBillau Nov 20 '13 at 14:36
4

To install the cordova command-line tool, follow these steps:

First of all go through the Cordova Document

For Cordova command-line tools to work, you need to include the SDK's tools and platform-tools directories in your PATH environment. On Mac, you can use a text editor to create or modify the ~/.bash_profile file, adding a line such as the following, depending on where the SDK installs:

export PATH=${PATH}:/Development/adt-bundle/sdk/platform-tools:/Development/adt-bundle/sdk/tools

Next Steps:

Download and install Node.js from Here. Following installation, you should be able to invoke node or npm on your command line.

Install the cordova utility. In Unix(Mac), prefixing the additional sudo command may be necessary to install development utilities in otherwise restricted directories:

 For Mac $ sudo npm install -g cordova

once successful installation of cordova is done ,now you can create your application

across all the platforms.

Create the Cordova Application

Go to the directory where you maintain your source code, and run a command such as the following:

$cordova create hello com.example.hello CordovaDemo

hello is the directory where you want to create your application

com.example.hello is the package name

CordovaDemo is the name of the Application

Once Successful creation of your project, some file will be created inside the directory i.e hello

Add Platforms

All subsequent commands need to be run within the project's directory, or any subdirectories within its scope:

 $ cd hello

Now you need to specify a set of target platforms, Supported OS for Mac

$ cordova platform add android

plz tell me if you are still having problem.

[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: ]

You just need to install the Latest version of Android i.e 4.3

Go to SDK Manager and install the latest SDK Platform.

And try run the command again.

enter image description here

Hope this will help you.

Amit Gupta
  • 8,914
  • 1
  • 25
  • 33
0

Here it solved my issue:

into the terminal.

  1. touch ~/.bash_profile (create a bash profile)
  2. open ~/.bash_profile (opening a bash profile)
  3. in your opened file, please type the following, Make sure that you have given the correct path, in case you find it difficult to find your directory in which your Android SDK is installed , search into your terminal with ls -l.

PATH="/Users/System-Name/Documents/android-sdk-macosx/sdk/tools:/Development/android-sdk-macosx/sdk/platform-tools:$PATH"

Shashank Saxena
  • 2,014
  • 17
  • 11
-1

[Let me clarify first that, this is windows specific suggestion, answer]

For particular cordova version there corresponds particular android API

So, First check out version of cordova with following command:

$ npm cordova -v

In my case cordova version was 1.4.28 , which corresponds to Android API 19

So the bottom line is don't waste time in downloading all "SDK Platforms" instead just download corresponding Android API for concerned cordova version...

Hope this help....!!!

greatwolf
  • 20,287
  • 13
  • 71
  • 105