I installed PhoneGap 3.0 with Node.js and configured all the environment variables so that javac, java, and ant all work but when I do a basic app create and try to build it for Android, I get the following error:
An error occurred during creation of android sub-project. Creating Cordova project for the Android platform: Command failed to execute : ant jar
Any ideas?
Make sure you have the Android Build Tools installed for your Android SDK version. In the Android SDK manager under Tools>Android SDK Build-tools you should see that the Build tools for your SDK version are not installed.
Detail on how I uncovered this:
To identify this as the root cause I ran the Cordova command with -d for verbosity:
cordova -d platform add android
The output of this command shows the error:
Running bin/create for platform "android" with command: ""C:\Users\---\.cordova\lib\android\cordova\3.1.0\bin\create" "C:\Users\---\workspace_android\FleetView\platforms\android" "com.---.fleetview" "Fleet View"" (output to follow)
Running the offending command directly:
"C:\Users\---\.cordova\lib\android\cordova\3.1.0\bin\create" "C:\Users\---\workspace_android\FleetView\platforms\android" "com.---.fleetview" "Fleet View"
produces this output:
BUILD FAILED
C:\tools\adt-bundle-windows-x86_64-20130219\sdk\tools\ant\build.xml:479: SDK does not have any Build Tools installed.
Total time: 1 second
Command failed to execute : ant jar
I am on Windows 7.
This is due to ANT tools could not find tools.jar in JRE lib directory. When I copied tools.jar from JDK lib directory to JRE lib directory, the problem was absolutely solved and the build was successful when I ran the command "cordova -d platform add android". Hope this helps you.
Posted the answer to similar question: Android Platform Guide trouble with adding a platform through the command line
A combination of 2 things worked for me:
include the JDK in your path (path\to\jdk\bin of course)
exclude the JRE from your path (or at least have it come after the JDK)
I faced the same issue,
I was having jdk-6 and I updated to jdk-7,
that fixed the issue,
Also I didn't installed ant in the first place,
in your case ant PATH might be missing.
See if that helps.
Related
I'm new on cordova, so if my question is not relevant, forgive me.
i have a cordova project in my Windows 7 x64 machine.
Yesterday i was build my cordova app via cordova build android --release.
But i need to add new plugin cordova-plugin-zip to update my cordova project.
What i did to add this plugin to my cordova app;
I installed a git application to my win7 x64 env.
npm install -g git i wrote this command on cmd.
I Opened Windows Environment Variables/Path Window and added ;C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\Git\cmd
add plugin via this command cordova plugin add https://github.com/apache/cordova-plugin-file.git
then added other plugin cordova plugin add https://github.com/MobileChromeApps/zip.git
(Everything fine till this step)
Then i run on cmd cordova build android --release
Unfourtunately it throws following error;
BUILD FAILED C:\android\sdk\tools\ant\build.xml:720: The following
error occurred while execu ting this line:
C:\android\sdk\tools\ant\build.xml:734: Compile failed; see the
compiler error o utput for details.
Total time: 7 seconds
C:\hascevher\platforms\android\cordova\node_modules\q\q.js:126
throw e;
^ Error code 1 for command: cmd with args: /s,/c,ant,release,-f,C:\hascevher\platf
orms\android\build.xml,-Dout.dir=ant-build,-Dgen.absolute.dir=ant-gen
ERROR building one of the platforms: Error: cmd: Command failed with
exit code 1
You may not have the required environment or OS to build this project
Error: cmd: Command failed with exit code 1
at ChildProcess.whenDone (C:\Users\Hddn\AppData\Roaming\npm\node_modules\cor
dova\node_modules\cordova-lib\src\cordova\superspawn.js:134:23)
at ChildProcess.emit (events.js:110:17)
at maybeClose (child_process.js:1015:16)
at Process.ChildProcess._handle.onexit (child_process.js:1087:5)
When i try to create a new helloworld cordova project and adding android platform then from cmd cordova build android it creates sample app?
So what is wrong with my other application?
Any help greatly appricated.
OS: Windows 7 x64
Cordova v 5.1.1
Ant version 1.9.4
Plugins On Cordova Project:
cordova-plugin-file
cordova-plugin-zip
org.apache.cordova.console
org.apache.cordova.device
org.apache.cordova.inappbrowser
Full Windows Environment Variables/Path:
C:\ProgramData\Oracle\Java\javapath;C:\Program Files\Common
Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common
Files\Microsoft Shared\Windows
Live;%C_EM64T_REDIST11%bin\Intel64;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program
Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files
(x86)\Windows Live\Shared;C:\Program Files
(x86)\QuickTime\QTSystem\;C:\Program Files
(x86)\Java\jdk1.7.0_75\bin;C:\cordova\apache-ant-1.9.4\bin;C:\android\sdk\tools;C:\android\sdk\platform-tools;C:\Program
Files\nodejs\;C:\Program Files (x86)\Git\bin;C:\Program Files
(x86)\Git\cmd
I removed android platforms and installed again then worked. I wrote these lines in command window:
cordova platform remove android
then
cordova platform add android
Delete platforms/android folder and try to rebuild. That helped me a lot.
(Visual Studio Tools for Apache Cordova)
Delete all the apk files from platfroms >> android >> build >> generated >> outputs >> apk
and run command cordova run android
I found answer myself; and if someone will face same issue, i hope my solution will work for them as well.
Downgrade NodeJs to 0.10.36
Upgrade Android SDK 22
I have had this problem several times and it can be usually resolved with a clean and rebuild as answered by many before me. But this time this would not fix it.
I use my cordova app to build 2 seperate apps that share majority of the same codebase and it drives off the config.xml. I could not build in end up because i had a space in my id.
com.company AppName
instead of:
com.company.AppName
If anyone is in there config as regular as me. This could be your problem, I also have 3 versions of each app. Live / Demo / Test - These all have different ids.
com.company.AppName.Test
Easy mistake to make, but even easier to overlook. Spent loads of time rebuilding, checking plugins, versioning etc. Where I should have checked my config. First Stop Next Time!
I had the same error code but different issue
Error: /Users/danieloram/desktop/CordovaProject/platforms/android/gradlew: Command failed with exit code 1 Error output:
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/android/dx/command/Main : Unsupported major.minor version 52.0
To resolve this issue I opened the Android SDK Manager, uninstalled the latest Android SDK build-tools that I had (24.0.3) and installed version 23.0.3 of the build-tools.
My cordova app then proceeded to build successfully for android.
In my case it was the file size restriction which was put on proxy server. Zip file of gradle was not able to download due this restriction. I was getting 401 error while downloading gradle zip file. If you are getting 401 or 403 error in log, make sure you are able to download those files manually.
Faced same problem. Problem lies in required version not installed.
Hack is simple Goto Platforms>platforms.json
Edit platforms.json in front of android modify the version to the one which is installed on system.
I'm using Visual Studio 2015, and I've found that the first thing to do is look in the build output.
I found this error reported there:
Reading build config file: \build.json... SyntaxError: Unexpected
token
The solution for that was to remove the bom from the build.json file
Then I hit a second problem - with this message in the build output:
FAILURE: Build failed with an exception. * What went wrong: A
problem was found with the configuration of task ':packageRelease'.
File 'C:\Users\Colin\etc' specified for property
'signingConfig.storeFile' is not a file.
Easily solved by putting the correct filename into the keystore property
I've had this problem when build a android app with cordova command:
cordova build android
D:\Desenvolvimento\ionicapps\AppBelle>cordova build android Running command: "C:\Program Files\nodejs\node.exe"
D:\Desenvolvimento\ionicapps \AppBelle\hooks\after_prepare\010_add_platform_class.js D:\Desenvolvimento\ionic apps\AppBelle add to body class: platform-android
Running command: "C:\Program Files\nodejs\node.exe" D:\Desenvolvimento\ionicapps \AppBelle\hooks\after_prepare\020_remove_sass_from_platforms.js D:\Desenvolvimen to\ionicapps\AppBelle
Running command: D:\Desenvolvimento\ionicapps\AppBelle\platforms\android\cordova \build.bat [Error: Android SDK not found. Make sure that it is installed. If it is not at t he default location, set the ANDROID_HOME environment variable.]
ERROR building one of the platforms:
Error: D:\Desenvolvimento\ionicapps\AppBell e\platforms\android\cordova\build.bat: Command failed with exit code 2 You may not have the required environment or OS to build this project
Error: D:\Desenvolvimento\ionicapps\AppBelle\platforms\android\cordova\build.bat : Command failed with exit code 2 at ChildProcess.whenDone (C:\Users\Victor\AppData\Roaming\npm\node_modules\c ordova\node_modules\cordova-lib\src\cordova\superspawn.js:131:23) at ChildProcess.emit (events.js:98:17) at maybeClose (child_process.js:756:16) at Process.ChildProcess._handle.onexit (child_process.js:823:5)
D:\Desenvolvimento\ionicapps\AppBelle>echo %ANDROID_HOME% C:\Users\Victor\AppData\Local\Android\sdk\
Above I show location of env var ANDROID_HOME . I don't know what to do.
Help me, please.
Thanks
I'm learning Ionic (based on Cordova) these days, and I came to this similar problems in Mac os too when execute ionic build android, with similar error msg below:
Running command:/Users/ngloom/code/workspace/myWork/platforms/android/cordova/build
[Error: Android SDK not found. Make sure that it is installed. If it is not at the default location, set the ANDROID_HOME environment variable.]
and the msg still exist after i setting the ANDROID_HOME environment, upgrade the sdk tools, finally i have to look into the check_reqs.js which throw the error and i found that the js is based on the cmd output by android list targets, and finally I found the android is owned by root (very likely that the android is installed by sudo brew before) and only error returned when executing by my user.
So I change the owner of android and everything works !
I post my solution here as a solution backup, hoping to help the guys in case like me :)
Unfortunately this can be a bug caused by upgrading android SDK versions. In general look for for different reasons:
First if you have to set the ANDROID_HOME environment variable. (according to your OS - In windows , right click your PC icon "MY PC", --> properties -> Advanced system settings -> Environment Variables" and set ANDROID_HOME variable and edit PATH variable to your path to your android SDK, tools & platform tools.
Secound try the "android" command in command tool, if android sdk couldn't open it cause a problem to build your app. I got this error:
The "android" command is no longer available.
For manual SDK and AVD management, please use Android Studio.
For command-line tools, use
tools\bin\sdkmanager.bat and tools\bin\avdmanager.bat
to solve it, you should downgrade your sdk using this links:
(Mac) https://dl.google.com/android/repository/tools_r25.2.3-macosx.zip
(Windows) https://dl.google.com/android/repository/tools_r25.2.3-windows.zip
and replace the zip file with your "tools" folder in your android SDK, It will work fine after trying "android" command and building app command in cordova and ionic frameworks.
Digging the reason: (In my case)
Why failing android command is causing this problem?
part of the cordova or ionic configuration in js files are using android command to "VERIFY" your "ANDROID_HOME" and "PATH" environment variables to operate building your app, and in case of any failure accessing to Android sdk via command access, system tells you "Android SDK" is not found. Recently, in new version android command is no longer accessible and is causing issues for any operation whom used this command. :/
Hope it works for you, It took a time for me to figure out solving this issue and don't forget to (+1) if it helped you!
Setting environmental variables use this to set up the path to tools and platform tools and update SDK for the android version that you are trying to build and make sure weather its Ionic or cordova application and then try once
When calling cordova platform add android in the Windows 8 cmd, the error message ERROR : executing command 'ant', make sure you have ant installed and added to your path is thrown. I have looked through quite a few other StackOverflow posts related to this problem, but continue to receive the same error message. I have installed node.js and GIT as specified in the documentation here: http://cordova.apache.org/docs/en/3.5.0//guide_cli_index.md.html#The%20Command-Line%20Interface. I have also installed ant and added ant, Android tools, and Android platform tools to the user PATH system variable. Here is the current PATH variable:
%ANT_HOME%\bin;%JAVA_HOME%\bin;C:\apache-ant-1.9.4\bin;C:\apache-ant.1.9.4;%ANDROID_HOME%;C:\Users\t-alboul\Desktop\adt-bundle-windows-x86_64-20140702\sdk\tools;C:\Users\t-alboul\Desktop\adt-bundle-windows-x86_64-20140702\sdk\platform-tools;C:\Users\t-alboul\Desktop\adt-bundle-windows-x86_64-20140702\sdk\tools\ant;C:\Users\t-alboul\AppData\Roaming\npm
ANT_HOME: C:\apache-ant-1.9.4
JAVA_HOME: C:\Progra~1\Java\jdk1.8.0_05
ANDROID_HOME: C:\Users\t-alboul\Desktop\Eclipse\adt-bundle-windows-x86_64-20140702\sdk
What else could I try to solve this problem? Is there anything else that I should add to the PATH variable?
Try installing ant with npm instead
npm install -g ant
and add C:\Users\ (your user name)\AppData\Roaming\npm\node_modules\ant\ant\bin to the PATH
I see in your path you have
C:\apache-ant-1.9.4\bin
C:\apache-ant.1.9.4 as well as
%ANT_HOME%\bin and %ANT_HOME% is set to C:\apache-ant-1.9.4
So where is actually tour ant package?
C:\apache-ant-1.9.4 or C:\apache-ant.1.9.4 becase in case it's the second, nothing in your path points to the bin folder.
I strongly suggest you clean up your path and make sure your env vars point to the good folders.
What you need in your path for cordova android is
%ANDROID_HOME%\platform-tools;%ANDROID_HOME%\tools;%JAVA_HOME%\bin;%ANT_HOME%\bin
To check if ant is accessible from the path, open a cmd and run ant -version which should display Apache Ant(TM) version 1.9.4 compiled ...
I'm trying to build a project but when I type: cordova build android the following error occurred:
Generating config.xml from defaults
for platform "android"
Preparing android project
Compiling app on platform "android"
via command "../platforms/android/cordova/build"
Error: An error occurred
while building the android project.Error executing "ant debug -f "../platforms/android/build.xml"":BUILD FAILED /usr/local/Cellar/android-sdk/22.3/tools/ant/build.xml:932:The following error occurred
while executing this line: /usr/local/Cellar/android-sdk/22.3/tools/ant/build.xml:950:null returned: 1
Total time: 18 seconds
at ChildProcess. < anonymous > (/usr/local/lib/node_modules/cordova/src/compile.js:65:22)
at ChildProcess.EventEmitter.emit(events.js: 98: 17)
at maybeClose(child_process.js: 735: 16)
at Socket. < anonymous > (child_process.js: 948: 11)
at Socket.EventEmitter.emit(events.js: 95: 17)
at Pipe.close(net.js: 466: 12)
Is there a fix for this problem?
EDIT
I used brew to install Android-SDK and installed all possible build-tools:
And my android manifest looks like:
EDIT2
As requested here is the responce for cordova build android --verbose: http://pastebin.com/rqdkVKYG
I found the bug.
While testing, reinstalling android-sdk and ant. I tried to create a new project. Than typed in the terminal cordova build and it build flawlessly. After this I copied my existing WWW folder in to the new project. Typed cordova build again, it gave an error. Now I knew that the bug was in my WWW folder and not in the project itself. Scanning my folders I noticed a file with no extension(hidden files). I deleted the file and tried again. Success!
SUMMARY:
Scan your folders for files without extensions and delete or move them. Cordova doesn't like those.
EDIT
If this doesn't work try:
cordova platform rm android
then reinstall android using :
cordova platform add android
Now try to build.
try to run the command $home/.cordova/lib/android/cordova/3.3.0/bin/check_reqs to check if you have all the required components installed for android.
¿Did you add to windows path the sdk?
You can also try:
cordova platform add android
cordova build
try ant -v in your terminal and make sure it's above 1.8. Cordova requires that.
Also check path is given correct for Ant, Android-SDK/tools, and Android-SDK/platformtools
To debug exact issue try $Cordova build android --verbose
Let me know.
I'm trying add the android platform to my cordova project, though I get the error:
$ cordova platform add android -d
cordova library for "android" already exists. No need to download. Continuing.
Checking if platform "android" passes minimum requirements...
Checking Android requirements...
cordova library for "android" already exists. No need to download. Continuing.
Error: An error occurred while listing Android targets
at /home/jasonshark/.cordova/lib/android/cordova/3.2.0/bin/lib/check_reqs.js:83:29
at _rejected (/home/jasonshark/.cordova/lib/android/cordova/3.2.0/bin/node_modules/q/q.js:808:24)
at /home/jasonshark/.cordova/lib/android/cordova/3.2.0/bin/node_modules/q/q.js:834:30
at Promise.when (/home/jasonshark/.cordova/lib/android/cordova/3.2.0/bin/node_modules/q/q.js:1079:31)
at Promise.promise.promiseDispatch (/home/jasonshark/.cordova/lib/android/cordova/3.2.0/bin/node_modules/q/q.js:752:41)
at /home/jasonshark/.cordova/lib/android/cordova/3.2.0/bin/node_modules/q/q.js:574:44
at flush (/home/jasonshark/.cordova/lib/android/cordova/3.2.0/bin/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:415:13)
Without the -d it will be:
Checking Android requirements...
[Error: An error occurred while listing Android targets]
I'm not sure what configuration I am missing. In my ~/.bashrc file I have:
### Java
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386
export ANDROID_HOME=~/Code/adt-bundle-linux-x86-20131030/sdk/tools
export ANDROID_PLATFORM_TOOLS=~/Code/adt-bundle-linux-x86-20131030/sdk/platform-tools
export PATH=$ANDROID_HOME:$ANDROID_PLATFORM_TOOLS:$PATH
and I have ant installed:
$ ant -version
Apache Ant(TM) version 1.8.2 compiled on December 3 2011
What's missing? Why do i get the error An error occurred while listing Android targets when trying to add the android platform to the cordova project?
Cordova has a script to check if all dependencies are present. Is is called when you run cordova platform add android but unfortunatly it's output is not displayed when it fails.
You can try to run it manually, it should be $home/.cordova/lib/android/cordova/3.5.0/bin/check_reqs
The normal output when everything's fine is "Looks like your environment fully supports cordova-android development!", oterwise it should display a clear message about what's missing.
Maybe your issue is that you havent't installed SDK platform for API 19 in android sdk manager (cordova 3.3 or 3.5 uses target sdk 19).
Update: Cordova 3.3 or 3.5 works on SDK 19 only (Android 4.4.2). The error logs does not mention clearly what platform version it is looking for. Typically error messages are:
Unable to add platform android. Please see console for more info.
or
[Error: An error occurred while listing Android targets]
This can also happen when android (sdk/tools) is not in path. I would have loved if the check-script have printed correct error message. BTW, created a PR for them.
in .bashrc try adding
export ANT_HOME="/usr/bin/ant"
export PATH="$PATH:$ANT_HOME/bin"
export HOME="/home/username"
export ANDROID_HOME="$HOME/android-bundle/sdk/tools"
export ANDROID_PLATFORM_TOOLS="$HOME/android-bundle/sdk/platform-tools"
export PATH="$ANDROID_HOME:$ANDROID_PLATFORM_TOOLS:$PATH"
or try explicitly define the paths globally.
from the terminal I type:
export PATH=${PATH}:~/dev/adt-bundle-linux-x86_64-20140321/sdk/tools
export PATH=${PATH}:~/dev/adt-bundle-linux-x86_64-20140321/sdk/platform-tools
(rememebr to replace with your own sdk path)
If this doesn't work, try updating the sdk
Please Refer the Question
An error occurred while listing Android targets
and the Link
developer.android.com/tools/devices/managing-avds-cmdline.html
Most probably the path variable pointing to this android was wrong. I had used %ANDROID_HOME% as variable and scaled the same to path variables %ANDROID_HOME%\SDK\TOOLS. This method doesn't work. Experimentally resolved by directly pointing to the Tools and Platform Tools.
Just based on what I did and it worked for me. Hope You get the Issue resolved
I had faced the Issue even after the Cordova check_reqs was working correctly without providing any error.But on adding a new platform this error was still being raised. The above method personaly resolved my issue.
I solved the problem giving full permission for my app folder
$ sudo chmod -R 777 myApp
After that, try again
$ cd myApp
$ ionic platform android