PhoneGap: Unable to Create Android App using Terminal - android

I try to create an android app using PhoneGap on my Mac. But, I only can create the app (hello) and couldn't create the Android platform for it using $ cordova platform add android command.
The error message I get is: [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: ]
The screenshot:
I try to put the PATH in the bash profile file using touch ~/.bash_profile; open ~/.bash_profile method, but it still didn't work.
How to solve this problem?

try this one
install android sdk in /Applications then rename the andoid sdk folder's name to android_sdk
create .bash_profile in this directory, /Users/zulhilmizainudin
open .bash_profile then type this command
export PATH=/Applications/android_sdk/tools:$PATH
export ANDROID="/Applications/android_sdk/tools"
Save .bash_profile file
type android command in your terminal

Related

MAC - Cordova error after installing Android Studio

On Mac os - Cordova stoped working after installing Android Studio (4.4.1)
NOTE: it was working previous to the installation
With the following errors:
The command "android" failed. Make sure you have the latest Android SDK installed, and the "android" command (inside the tools/ folder) is added to your path.
And (After the first one was solved)
You may not have the required environment or OS to build this project
The android PATH changes and was not updated by the cordova, I had to do:
update PATH env var
touch ~/.bash_profile; open ~/.bash_profile
add the lines:
export ANDROID_SDK="/Users/%USR%/Library/Android/sdk"
export ANDROID_HOME="$ANDROID_SDK"
export ANDROID_PLATFORM_TOOLS="$ANDROID_SDK/platform-tools"
export PATH="${PATH}:$ANDROID_HOME/tools:$ANDROID_PLATFORM_TOOLS"
update local.properties under platforms/andorid and platforms/android/CordovaLib (line 10) to
sdk.dir=/Users/%USR%/Library/Android/sdk
where %USR% is your user name

Phonegap - Setting up Phonegap

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
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:
Open Terminal
a. Install Android Studios
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:
Open Command prompt
a. Put ANT [Downloaded folder] folder into “android ADT folder”/sdk
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
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.
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.
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.

Android Keyword Error when installing Phonegap

I am having the following error when running the command: cordova platform add android. I already have ant installed and node/npm installed.
My bash profile is this:
export PATH=/Users/chaitanyavaranasi/local/bin:$PATH
export PATH=${PATH}:/Users/chaitanyavaranasi/android-sdks/platform-tools:/Users/chaitanyavaranasi/android-sdks/tools
The overall error I get is:
Error: The command "android" failed. Make sure you have the latest Android SDK installed, and the "android" command (inside the tools/ folder) is added to your path.
Thanks for all the help!
You should exec the SDK Manager in the folder
/chaitanyavaranasi/android-sdks
and install the Android SDK
Most likely you need to close your shell and open a new one.

Cordova and setting Android using command line

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?
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,
touch ~/.bash_profile
open ~/.bash_profile
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 )
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
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.
9.open ~/.bash_profile. Add JAVA_HOME value
10.You can see your environment like STEP 7 set. You should be able see:
11.Successfully created environment now you can create Android project with Cordova or PhoneGap
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:
Click on the Start menu in the lower-left corner of the desktop,
right-click on Computer, then click Properties.
Click Advanced System Settings in the column on the left.
In the resulting dialog box, press Environment Variables.
Select the PATH variable and press Edit.
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
Save and close both dialogs.
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.
Hope this will help you.
Here it solved my issue:
into the terminal.
touch ~/.bash_profile (create a bash profile)
open ~/.bash_profile (opening a bash profile)
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"
[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....!!!

How do i run the Android command line tools?

I'm still pretty new to Android and programming in general, and I can't seem to get the command line tools packaged with the Android SDK to work. I'm running Mac OSX and each time I try to run layoutopt, for example, the terminal returns, *-bash: cmd: command not found
*
Also, is it okay to have my SDK located in the Developer directory and my android project in some unrelated directory when using these tools?
If you want you can put the path in your ~/.bash_profile so you can call it from anywhere:
export ANDROID_HOME=/Users/<username>/path/to/sdk/tools
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
You may want to include also the platform-tools into your ~./bash_profile
### Android dev tools
export ANDROID_HOME="/Users/myusername/DEV/tools/adt-bundle-mac-x86_64/sdk"
export PATH="$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$PATH"
You will need to start a new terminal session or run
source ~/.bash_profile
to loads the values immediately without having to open a new terminal session.
The current (2016-08-17) answer to this question is:
~/Library/Android/sdk
So my bash_profile contains:
export ANDROID_HOME=~/Library/Android/sdk
export PATH=${PATH}:$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools
I figured it out. I needed to go to the /tools directory in the SDK folder and type in:
./layoutopt <directorypath>
Problem is your command line tool is not seeing required programs from /path/to/sdk/tools.
One solution as user NKijak mentioned is to add those tools to your Home path and the other is to run command line from location where your sdk tools are stored. Here is a tutorial how to do just that http://hathaway.cc/2008/06/how-to-edit-your-path-environment-variables-on-mac-os-x/
Other way is, when opening command line just change your current dir to /path/to/sdk/tools and then run the tools. In windows you can just shift+right click in file explorer and pick open command windows here I am not sure is there equivalent on MacOS but there are some extensions you can install to add this option. Also total commander in windows has command line where you can start command line from current location there are similar programs on mac like Midnight Commander that have same option.
Here is a good description:
To connect to the console of any running emulator instance at any time, use this command:
telnet localhost <console-port>

Categories

Resources