I create ionic 2 project and add diagnostic cordova plugin like this :
ionic plugin add cordova.plugins.diagnostic
npm install --save #ionic-native/diagnostic
and add android platform like this :
ionic platform add android#latest
but when build with ionic build android console give me this error :
Error: Could not find an installed version of Gradle either in Android Studio,
or on your system to install the gradle wrapper. Please include gradle
in your path, or install Android Studio
and I try to download manualy gradle.3.3-all.zip and change this distributionUrl var in platform/android/cordova/lib/builders/GradleBuilder.js
var distributionUrl = process.env['CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL'] || 'https\\://services.gradle.org/distributions/gradle-3.3-all.zip'
to:
var distributionUrl = process.env['CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL'] || 'file:///E:/gradles/gradle-3.3-all.zip';
but not working and console give me last error.
I dont know how to add gradle for android#latest version
Life is too short to spend it on messing with paths, etc.
Since I had Homebrew installed on the iMac, I just ran this command:
brew install gradle
The Ionic3 project started to build successfully.
Try installing gradle and include it into your path. Click the link below to get manual.
https://gradle.org/install
Just install gradle on linux, Even if Android Studio is installed,
sudo apt install gradle
For windows users:
Download gradle binary from the link in the answer Gradle Download
Extract the zip file to 'C:\Gradle' or somewhere else
open Edit Environment variable dialog from start menu > Search
Click 'New' under system variables and add as below
Variable Name GRADLE_HOME Variable Value C:\Gradle\gradle-4.0.1
Then choose PATH variable from system variable list
append the gradle path to variable value like this C:\Gradle\gradle-4.0.1\bin
then press win Key+R type cmd then enter > in command terminal type gradle -v
if the setup is correct you will see the gradle installation details
I was already installed Android Studio and it's just need to add gradle PATH to ~/.bash_profile on my MacOSX Mojave.
Also if gradle is upgraded then path might need to update again.
Example .bash_profile :
export ANDROID_SDK_ROOT="~/Library/Android/sdk"
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
export JAVA_HOME=$(/usr/libexec/java_home)
export GRADLE_PATH="~/.gradle/wrapper/dists/gradle-4.10.1-all/455itskqi2qtf0v2sja68alqd/gradle-4.10.1/bin"
export ANDROID_STUDIO="/Applications/Android Studio.app/Contents/MacOS"
export PATH="$PATH:$GRADLE_PATH:$ANDROID_STUDIO"
When edited your .bash_profile then run a command below to read it again.
source ~/.bash_profile
For Windows you can try below solution
Copy your gradle-->bin path and add it to system environment variable path.
In my case gradle path is
C:\Users\username\.gradle\wrapper\dists\gradle-3.3-all\55gk2rcmfc6p2dg9u9ohc3hw9\gradle-3.3\bin
This solution worked for me.
In Ubuntu, Installing latest version of gradle solved the issue for me.
Try these steps to install the latest version,
sudo add-apt-repository ppa:cwchien/gradle
sudo apt-get update
sudo apt-get install gradle
then build using,
cordova build android or ionic cordova build android
Note: If you install gradle from ubuntu repo, it will install the old version 1.4 and will not help, so sudo apt-get install gradle alone will not help most times, if you did not add the repo ppa:cwchien/gradle earlier
There is a problem with cordova version 6.4.0 and android 6.2.1 .so,please try with below compatible versions
cordova version must be 6.4.0
sudo npm install -g cordova#6.4.0
Install android in your project
sudo cordova platform add android#6.1.2
or
sudo ionic platform add android#6.1.2
brew install gradle
In short that will save time :) Ionic team please fix this
On Ubuntu 18.04, I intalled gradle with:
sudo add-apt-repository ppa:cwchien/gradle
sudo apt-get update
sudo apt-get install gradle
And Ready.
If you dont want to install gradle explicitly just to address this issue, you can overcome this by following the workaround as mentioned below:
Look for check_reqs.js file under platforms\android\cordova\lib folder
Edit the else part of androidStudioPath variable null check in get_gradle_wrapper function as below:
Existing code:
else {
//OK, let's try to check for Gradle!
return forgivingWhichSync('gradle');
}
Modified code:
else {
//OK, let's try to check for Gradle!
var sdkDir = process.env['ANDROID_HOME'];
return path.join(sdkDir, 'tools', 'templates', 'gradle', 'wrapper', 'gradlew');
}
NOTE: This change needs to be done everytime when the android platform is removed and re-added
UPDATE: The above workaround will work fine till Cordova Android version 6.3.0. For Cordova Android 6.4.0 and above, Gradle needs to be installed as a standalone dependency. Please find Cordova Android 6.4.0 release notes for more info on this.
For Windows users:
Set-ExecutionPolicy RemoteSigned -scope CurrentUser
iex (new-object net.webclient).downloadstring('https://get.scoop.sh')
scoop install gradle
Just install the Gradle through the command line
If you are using Mac try
brew install gradle
I am on Microsoft Windows:
I encountered this error after upgrading Android Studio from 2.3.3 to 3.0. I solved it by changing the path to gradle in the PATH environment variable, which is now "gradle-4.1" for Android Studio 3.0 (previously it was "gradle-3.2" for Android Studio 2.3.3)
I moved Android folder path to another path and taked this error.
I resolved to this problem in below.
I was changed to Gradle path in system variables. But not path in user variables. You must change to path in system variables
Screenshot this
Alternative Screenshot this
I would like to add my two cents to this conversation. If you are a Windows user, you would like to take advantage of Chocolatey
Per https://community.chocolatey.org/packages/gradle, you need to run
in your console (it assumes you already have Chocolatey installed).
choco install gradle
If you haven't installed Chocolatey, follow the instructions at https://chocolatey.org/install
I solve this problem
Download gradle.zip from this site https://gradle.org/install. And follow the instructions indicated in the site.
Then open another terminal cmd and execute the command:
Cordova build android --prod --release
End
First of all uninstall ionic and cordova, later set your variables envarionment JAVA_HOME, ANDROID_HOME and PATH then reinstall ionic cordova and add platform like follow:
$ sudo npm install -g ionic cordova
$ ionic platform add android
The ionic will setup gradle packages properly.
In Arch Linux/Manjaro:
sudo pacman -S gradle
just install android studio and select your sdk folder as a android studio's sdk default folder and then android studio repair all the damage area and download needed files.
Download the latest gradle from https://gradle.org/install and set the gradle path upto bin in your PATH variable and export path in the directory you are working in
example : export PATH=/home/abc/android-sdk-linux/tools:/home/abc/android-sdk-linux/platform-tools:/home/abc/android-sdk-linux/tools:/home/abc/android-sdk-linux/platform-tools:/home/abc/Downloads/gradle-4.4.1/bin
I spent my whole day resolve this and ultimately this solution worked for me,
If your gradle was working normally before and this came up (probably after you upgraded or reinstalled ionic or cordova - as was my case), you might want to leave the environment variable as is, and check if the folder listed there actually exists.
If it doesn't, rather than reinstalling gradle as mentioned above and changing the value of the environment variable, I had to recreate the old missing folder and copy the gradle files into them.
It seems the value of the gradle location is saved somewhere in Android Studio, and updating the PATH in system variables doesn't affect Android Studio checking for that same location after something triggers a change.
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 have installed netbeans 7.4 and like to test cordova. For this i first need to run cordova from command line. I was able to creat the files. I am following http://cordova.apache.org/docs/en/edge/guide_cli_index.md.html#The%20Command-line%20Interface.
But when i try to build from the command line i am getting the error
The command android failed.......make sure.....Android SDK
installed...to your path
I have add this to my enviroment variables as path
C:\Program Files (x86)\Android\android-sdk
Within netbeans creating a cordova project doesn't work am getting the message
Netbeans cannot find cordova or git on your path
Any tips, suggestions
Don’t do that,try this instead
Enviroment variables should be like this:
C:\Program Files (x86)\Android\android-sdk\platform-tools
C:\Program Files (x86)\Android\android-sdk\tools
then restart your cmd .
The second question I think maybe you should config cordova and git in Netbeans.
Copy the location of the Android SDK:
If you have installed Android Studio:
(Ctrl+Alt+S) File->Settings->Appearance&Behavior->System Settings->Android SDK> Android SDK Location
In Windows 10, you have to point to the sdk folder in the AppData:
C:\Users\\AppData\Local\Android\sdk
Sorry if it's a bit late... But for any others with this same issue (I spent hours on this myself), don't forget to install Apache Ant and set the ANT_HOME variable on your system also.
https://ant.apache.org/
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.
I'm trying to do phonegap build android and I have this message :
[phonegap] detecting Android SDK environment...
[phonegap] using the local environment
[phonegap] adding the Android platform...
[error] An error occured during creation of android sub-project. Path not found
Phonegap is looking for "C:\Documents and Settings\corbg\.cordova\lib\android\cordova\3.0.0\bin\create". There is nothing under the directory "3.0.0". I installed cordova like this npm install -g cordova.
I have the some problem when I run cordova platform add android.
Did I missing something?
In Windows machine you have to delete .cordova directory under
C:\Users\user_name\
I have face the same issue, then i corrected my application path, afterthat it is worked out for me.
If you are using win 7 then add the Android ADK path in
open the mycomputer -> Properties -> Change Settings-> Advanced -> Environment Variable -> User variable for ....-> path
add the Android ADK path here like as following
C:\AndroidDev\adt-bundle-windows-x86-20131030\sdk\tools; C:\AndroidDev\adt-bundle-windows-x86-20131030\sdk\platform-tools
also add JAVA_HOME and ANT_HOME.
- Abdul Jabbar
Did you set your PATH variable? Sometimes this error occurs in Windows when the PATH variable is not set correctly to access "java" and "ant" exes. If you want to test if they are correctly set, you can simply execute both (from any folder in your command line):
> java
or
> ant
and both programs should be found.
It was a problem with my proxy. Cordova create a .cordova directory and try to download something on the internet. The download did not work. Next time, it check if there is a .cordova directory. It don't try to redownload something because the directory exist and it show the error.
I removed the .cordova directory and I solved my problems with proxy. Now, everythings works.
What solved the issue for me was having 2 directories on my PATH, the android platform-tools and tools.
In my pc those folders were at
C:\Program Files (x86)\Android\android-sdk\tools
C:\Program Files (x86)\Android\android-sdk\platform-tools
Also make sure you have the following environment variables
JAVA_HOME (C:\Program Files\Java\jdk1.7.0_51)
ANT_HOME (C:\Program Files\apache\apache-ant-1.9.3)
ANDROID_HOME (C:\Program Files (x86)\Android\android-sdk\platform-tools)
I removed the .cordova folder under my user folder but I'm not quite sure if that helped as well.
These links may help you
An error occured during creation of android sub-project
android' is not recognized as an internal or external command
I had the exact same problem for a different reason. I had an old version of ant (1.7.1). At least version 1.8.2 is needed for the build to work.
its either due to improper installation or no installation of ANT or JAVA. But moreover we need to add Android SDk and prepare Android Targets via SDK manager before going through this.
This is because you haven't installed ANT!
download it from here and install it step by step
https://ant.apache.org/manual/install.html
Then running the last command it will install the dependencies needed.