Phonegap - Setting up Phonegap - android

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.

Related

How to set up Android for React-Native without Android Studio but only using the SDK tools?

I've read pretty much read every article from google search, watched all the YouTube tutorials and checked out all the StackOverflow questions relating to this but cannot find my answer.
The official (but outdated) docs is not all that useful at all.
https://facebook.github.io/react-native/releases/0.23/docs/android-setup.html
http://facebook.github.io/react-native/releases/0.40/docs/getting-started.html
I am using Windows 10.
So far I have,
User Variables:
PATH
C:\Users\RickyDam\AppData\Local\Android\android-sdk\tools
C:\Users\RickyDam\AppData\Local\Android\android-sdk\platform-tools
System Variables:
ANDROID_HOME
C:\Users\RickyDam\AppData\Local\Android\android-sdk
ANDROID_SDK_HOME
C:\Users\RickyDam\AppData\Local\Android\android-sdk
JAVA_HOME
C:\Program Files\Java\jdk1.8.0_144
PATH
C:\Users\RickyDam\AppData\Local\Android\android-sdk\tools
C:\Users\RickyDam\AppData\Local\Android\android-sdk\platform-tools
My git bash just keeps showing
bash: android: command not found
And if I try to type in android.bat, it returns
The "android" command is deprecated.
For manual SDK, AVD, and project management, please use Android Studio.
For command-line tools, use tools\bin\sdkmanager.bat
and tools\bin\avdmanager.bat
And then if I try to type in sdkmanager.bat, I get
bash: sdkmanager.bat: command not found
EDIT:
I found out about the official SDK Manager installer made by Google Inc. and now my folder C:\Users\RickyDam\AppData\Local\Android\android-sdk looks like this
But I still get
android: command not found
even though my environment variables seem to all be in place...
Windows 10
Install Java SE Development Kit 8
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Install Android SDK Manager
http://filehippo.com/download_android_sdk/
Install the options that are already selected when you open the SDK Manager
• Android SDK Tools
• Android SDK Platform-tools
• Android SDK Build-tools
• Android 8.0.0 (API 26)
• Extras > Google USB Driver
Navigate to Control Panel \ System and Security \ System \ Advanced System Settings \ Environment Variables
For User Variables select Path and click Edit....
Click New and add these:
• C:\Users\PC-NAME\AppData\Local\Android\android-sdk\tools
• C:\Users\PC-NAME\AppData\Local\Android\android-sdk\platform-tools
• C:\Program Files\Java\jdk1.8.0_144
Now to confirm that it works, open cmd and type in android, the Android SDK Manager should open up.
NOTE: I suggest using the default command prompt over a third party one such as Git Bash. With cmd, when you run commands such as npm install, you actually get a loading bar where as in Git bash, you don't get one. Some commands that work properly in cmd such as android will not be recognized by Git bash.
Now in the command prompt, cd to the Desktop.
Run these commands:
• npm install -g create-react-native-app
• create-react-native-app my-app
• cd my-app/
• npm start
Mac Users
Assuming you already have:
Java JDK 8
nodejs and react-native cli
Now let's download only command line tools (which is bottom of ) this link
Follow these steps wisely:
unzip the folder in /opt/andriod directory
export ANDROID_HOME=/opt/android
echo "export ANDROID_HOME=/opt/android" >> ~/.bashrc
/opt/android/tools/bin/sdkmanager "platforms;android-23" "build-tools;23.0.1" "add-ons;addon-google_apis-google-23"
You are all done.Congrats! if you made it all.Now from RN proj. folder run:
react-native run-android

How to create Android App with Cordova 3.4

Since yesterday, I have some problems with Cordova and Android. I can not create an functional Android App. iOS works.
In detail: I use a Mac (MacOS X 10.8.5) and have installed ADT 22.6.2 (with API 17/18/19) and added the sdk-tools to my PATH.
$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Applications/adt/sdk/tools:/Applications /adt/sdk/platform-tools:/usr/local/MacGPG2/bin
My configuration:
$ node -v
v0.10.26
$ cordova -v
3.4.1-0.1.0
$ ant -version
Apache Ant(TM) version 1.8.2 compiled on June 20 2012
My attempt to create an Cordova App:
$ cordova create XY com.wb.XY XY
Creating a new cordova project with name "XY" and id "com.wb.XY" at location "/.../XY"
$ cd XY
XY wb$ cordova platform add ios
Creating ios project...
XY wb$ cordova platform add android
Creating android project...
Creating Cordova project for the Android platform:
Path: platforms/android
Package: com.wb.XY
Name: XY
Android target: android-19
Copying template files...
Running: android update project --subprojects --path "platforms/android" --target android-19 --library "CordovaLib"
Resolved location of library project to: /.../XY/platforms/android/CordovaLib
Updated and renamed default.properties to project.properties
Updated local.properties
No project name specified, using Activity name 'XY'.
If you wish to change it, edit the first line of build.xml.
Added file platforms/android/build.xml
Added file platforms/android/proguard-project.txt
Updated project.properties
Updated local.properties
No project name specified, using project folder name 'CordovaLib'.
If you wish to change it, edit the first line of build.xml.
Added file platforms/android/CordovaLib/build.xml
Added file platforms/android/CordovaLib/proguard-project.txt
Project successfully created.
XY wb$ cordova platform list
Installed platforms: android 3.4.0, ios 3.4.1
Available platforms: amazon-fireos, blackberry10, firefoxos
XY wb$ cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git
Fetching plugin "https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git" via git clone
Installing "org.apache.cordova.inappbrowser" for android
Installing "org.apache.cordova.inappbrowser" for ios
XY wb$
What is going wrong? There is no directory „gen“.
If I try to import the project into ADT/Eclipse, I got the message:
Errors occurred during the build.
Errors running builder 'Android Resource Manager' on project 'XY'.
Errors running builder 'Android Pre Compiler' on project 'XY'.
Path must include project and resource name: /XY
and
/XY/gen already exists but is not a source folder. Convert to a source folder or rename it.
Eclipse generates a folder called „gen“, but it is empty.
EDIT: Here is what I tried based on the input given in answers and comments:
I have installed Node.js and Cordova 3.4:
$ node -v
v0.10.26
$ cordova -v
3.4.1-0.1.0
$ ant -version
Apache Ant(TM) version 1.8.2 compiled on June 20 2012
I have done this as you described with CLI.
The Android SDK is in the system path:
$ echo $PATH /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Applications/adt/sdk/tools:/Applications/adt/sdk/platform-tools:/usr/local/MacGPG2/bin
Everything seems to be all right. Do you see any mistake? Do I need Apache Ant?
If I try to add android (without sudo), I have got the output shown in my question. Trying this as admin (with sudo), the result is the same.
With
$ cordova emulate android
I get:
...
BUILD SUCCESSFUL
Total time: 5 seconds
WARNING : no emulator specified, defaulting to Android_Tablet
Waiting for emulator...
2014-04-26 14:16:53.848 emulator64-arm[84081:f07] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found. Did find:
/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper
emulator64-arm: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.
Booting up emulator (this may take a while)........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
It takes a very long time . . . after 15 minutes I broke off. The log at Eclipse shows always returning the same messages.
But with
$ cordova run android
I am able to install and launch the app on my Android-device. But if I try to import the project into Eclipse, the file XY.java is shown with many errors.
Do you have any idea what could be the problem?
I am still able to work with my existing apps (iOS and Android), but I can not create a new one for Android.
I am sharing with you the steps to create android PhoneGap app with cordova 3.4 version :-
1) Download and install Node.js.
2) Run this command on your terminal :-
$ sudo npm install -g cordova
3) Then create your project using following command :-
$ cordova create hello com.example.hello HelloWorld
4) Then before adding any platform , run the following command....Replace the path of android sdk with your system path :-
$ export PATH=${PATH}:/Users/taruna/Documents/adt-bundle-mac-x86_64-20131030/sdk/platform-tools:/Users/taruna/Documents/adt-bundle-mac-x86_64-20131030/sdk/tools
5) Now add your platform using following command :-
$ sudo cordova platform add android
6) Now you can successfully run your project on emulator using following command :-
$ cordova emulate android
And its done now.
`

An error occured During creation of phonegap android sub project

I am trying to build a phonegap android,At that time i got a message that
[phonegap] detecting Android SDK environment...
[phonegap] using the local environment
[phonegap] adding the Android platform...
[error] An error occured during craetion of android sub-projesct. creating cordova project for the android platform
Please help me.
Thanks in advance.
Seems ant binary missing in your path!
In you install ant with npm like:
sudo npm install -g ant
Then just make symlink to bin folder what found in your $PATH like
sudo ln -s /usr/local/lib/node_modules/ant/ant/bin/ant /usr/local/bin/ant
There may be one of following two reasons-
1) .cordova directory already exists on your machine in your user folder. Delete it and try your command.
2)You have xcopy.exe somewhere on your machine. You should be able to add %SystemRoot%\System32 to your PATH.
or You can find it by running 'where xcopy' in your terminal window. XCOPY on the path is a requirement for setting up and installing Android
You need to define XCOPY on your path as it is used by the internal node.js scripts to move things around.
One of these should solve your problem.
I had same problem with cordova 3.3.1 and phonegap 3.3.0. Finally, I opened Android SDK manager and found out Platform tools were outdated, though I had the latest version from here. After update, this error was gone
Run the "android" command from your adt\sdk\tools folder and install the latest Tools and SDK. Also make sure your PATH has the right variables.
For this you will need ANT to be installed , a JAVA JDK and an Android SDK installed
JAVA_HOME (C:\Program Files\Java\jdk)
ANT_HOME ({ant location}\apache\apache-ant)
ANDROID_HOME ({android sdk location}\android-sdk)
Add these to your PATH variable like %ANT_HOME%/bin;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools;%JAVA_HOME%\bin
Close and re-open your cmd and run your command again.
Similiar to PhoneGap/Cordova Android Development

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....!!!

Installing Phonegap on Windows 7 : The command 'android' failed

I followed the documentation and some tutorials on Phonegap to install it on Windows 7, but I'm stuck.
So far, I've installed Java 1.7.0_06, Ant-Apache 1.9.2, Eclipse, Android SDK with Android 4.3 (API 18), all Tools and all Extras in the SDK Manager), NodeJS 0.10.18 and Git.
I wrote all paths in the PATH variables in Windows it's look like this (decomposed) :
F:\nodejs;
F:\android-sdk\sdk\platform-tools;
F:\android-sdk\sdk\tools;
%JAVA_HOME%\bin;
%ANT_HOME%\bin;
C:\Program Files (x86)\Git\bin
Where %JAVA_HOME% and %ANT_HOME% have the right path, they give me the their version when I type java -version or ant -version in the CLI
So I went in the CLI, I installed Phonegap with the following command :
npm install -g phonegap
It give me the 3.0.0-0.14.3 version when I type phonegap -v.
Now, I went to my folder F:\apps and I created a new project with the following command :
phonegap create hello com.example.hello HelloWorld
Everything goes well, the files are created.
I went in the 'hello' folder, and I typed this command :
phonegap local build android
And there come the problem, I get this error :
[phonegap] adding the Android platform...
[error] The command `android` failed. Make sure you have the latest AndroidSDK installed, and the `android` command (inside the tools/ folder) added to your path. Output:
I tried this command too :
phonegap build android
But it get stuck at this, nothing happen next :
[phonegap] detecting Android SDK environment...
[phonegap] using the remote environment
[phonegap] compressing the app...
After lot's of research, I don't know what I can do anymore to find the problem, and I'm quiet new with all this CLI... So yeah, do you have any idea why the command 'android' failed ?
Thanks
Open environment variables, on the first part 'user variables' add new variable with this name android and the variable F:\android-sdk\sdk\tools;
Then edit the user variables PATH and add this at end of the line %android%;
close your CMD and try again.

Categories

Resources