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.
`
Related
Maybe it can help you on build error with ionic/cordova error with android platform on windows
After install ant/ionic with :
%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools;%ANDROID_HOME%\build-tools
start a new projet : ionic start hello blank ->ok
ionic platform add android -> ok
ionic build android - Error:
BUILD FAILED
C:\SDK\android-sdk\tools\ant\build.xml:954: The following error occurred while executing this line:
C:\SDK\android-sdk\tools\ant\build.xml:971: null returned: -1073741819
Total time: 2 seconds
D:\PROD\myapp\platforms\android\cordova\node_modules\q\q.js:126
throw e;
^
Error code 1 for command: cmd with args: /s,/c,ant,debug,-f,D:\PROD\myapp\platforms\android\build.xml,-Dout.dir=ant-build,-Dgen.absolute.dir=ant-gen
ERROR building one of the platforms: Error: D:\PROD\myapp\platforms\android\cordova\build.bat: Command failed with exit code 8
You may not have the required environment or OS to build this project
Paths are OK and if I start a new cordova projet (not ionic) build is a success.
If I check problem on c:\android-sdk\build.xml and I add
<echo>aapt: ${aapt}</echo>
I can see aapt.exe path is on android-21 (target is android-19)
For me, problem is I have two android sdk : android 19 and android 21. If I use CLI on windows, ionic/cordova choose android-21\aapt.exe by default and no android-19\aapt.exe
I tried to force Path with android version : %ANDROID_HOME%\build-tools\19.0.0 with no success.
To resolve this problem I changed paths to force on aapt executable path to point on android 19:
File c:\android-sdk\tools\ant\build.xml :
<aapt executable="C:\android-sdk\build-tools\19.0.0\aapt.exe" ...
</aapt>
This is not the best way, but I have not found another.
Instruction 1:
After adding your ANDROID_HOME, make sure you do the below:
Restart your System or run source ~/.bash_profile
Remove Android platform from your project ionic cordova platform rm android or ionic platform rm android
Add Android platform ionic cordova platform add android
Then ionic cordova run android or ionic run android
Instruction 2:
To set your ANDROID_HOME and JAVA_HOME, follow the below steps:
Run command open ~/.bash_profile
Paste the below in the file that opens on your Text editor
export ANDROID_HOME=/usr/local/Cellar/android-sdk/24.4.1_1
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
Save - "Command S" or "Ctrl S"
Then Follow the "Instruction 1:" above
NOTE: Make sure you have **24.4.1_1 SDK**
Hope this helps.
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.
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.
I have installed Cordova along with Phonegap and installed node.js in my system(ubuntu)
by using following commands:
Install Nodejs http://nodejs.org/
Install Cordova 3.0.x
$ sudo npm install -g cordova
Install Phone Gap 3.0.x
$ sudo npm install -g phonegap
Then i created project using phonegap command:
$ phonegap create hello
Trying to run into my local by using following command:
$ phonegap local run andriod
Now at first i am getting following error:
shoaib#shoaib:~/Documents/hello$ phonegap local run android
[phonegap] adding the Android platform...
[error] An error occured during creation of android sub-project. /home/shoaib/.cordova/lib/android/cordova/3.0.0/bin/create: line 54: jar: command not found
This i solved by running following command:
ls -la /home/shoaib/.cordova/lib/android/cordova/3.0.0/bin
Now when i again run
$ phonegap local run andriod
I am getting below error:
root#shoaib:/home/shoaib/Documents/hello# phonegap local run android
[phonegap] compiling Android...
[error] An error occurred while building the android project. /bin/sh: 1: /home/shoaib/Documents/hello/platforms/android/cordova/build: not found
I am using Android SDK 17
and version as 4.2.2 .
Any solution for this issue?
I had a similar problem. build and run were missing along with a few other files and lib was an empty directory. Downloaded cordova-android from here extracted and copied everything from its /bin/templates/cordova/ to the project (/platforms/android/cordova/). Then I could build and install the app.
Still had to start the emulator, check the running emulator with platforms/android/cordova/lib/list-started-emulators and then pass it when installing or it would take forever to install it on an emulator.
$ platforms/android/cordova/lib/list-started-emulators
emulator-5554
$ phonegap install --emulator=emulator-5554 android
I had already installed the JDK but the same error.
To fix this I just removed the phone test project and make sure that:
Java, javac and jar where in the path
(both should work)
java -version
javac -version
jar -version
Android sdk path was properly set and JAVA_HOME environment variable was properly set.
Then I remake the project and everything worked.
Hey got the solution.
I install open jdk 6.0 and problem is resolved.
Hello. I've installed the following prerequisites for PhoneGap:
Java JDK
Android SDK + ADT Plugin
Eclipse
Ruby 1.9.2
Apache ant
I also added the path to the environment variable. However, when I try to launch with the command:
ruby ./droidgap "[android_sdk_path]" [name] [package_name] "[www]" "[path]"
I receive this error:
Ruby: No such file or directory -- ./droidgap (LoadError)
It looks like you need to run that command in the directory where the droidgap script lives.
Or checkout the Eclipse plugin here to avoid the need for droidgap or ruby to get started with PhoneGap on Android