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.
I'm configuring my build pipeline for an Android project. So far, all of my steps are working perfectly on Hosted VS2017 agent, including fetching the code, building with gradlew, publishing the artifact and deploying it to AppCenter.
However, on Hosted Ubuntu 1604, there are a few problems with gradlew step.
On VS2017 agent, this works with just: .\gradlew assembleDebug
On Ubuntu 1604, this is what I'm having right now:
chmod 775 gradlew
chmod 775 /usr/local/lib/android/sdk --> The fix I'm working on
./gradlew assembleDebug
Running the build without the 2nd line, agent will throw this exception:
What went wrong: A problem occurred configuring project ':app'.
Failed to install the following SDK components: build-tools;28.0.3 Android SDK Build-Tools 28.0.3
The SDK directory is not writable (/usr/local/lib/android/sdk)
I'm a beginner with Ubuntu... why is it not writable? I tried to chmod but I got the exception while doing so: chmod: changing permissions of '/usr/local/lib/android/sdk': Operation not permitted.
Which direction should I look at to solve this problem now... ? Thank you all in advance!
Change the ownership of Android SDK:
sudo chown -R $(whoami) $ANDROID_HOME
I had the same problem on a standard Ubuntu install.
The solution: install the Android SDK in your home directory.
The problem is, building a project with Gradle fails to work with a read-only SDK. Installing the Android SDK with apt leaves it read-only.
More precisely, everything in /usr/ is supposed to be read-only data, so it's owned by root with permissions set to 755. Your user doesn't have write access to it, only the owner does. Installing the SDK in your home directory (and making sure your user owns it) should solve the issue.
Installing the SDK
I haven't seen a good way to install just the SDK. There's another SO question addressing this; one of the ways listed there ought to work.
However, you may find it easier to just install Android Studio, and pick a custom location for the SDK.
Hope it helps!
there is no need to reinstall something at all...
giving the write privilege to the currently logged in user solves the problem.
I have an older cordova project that I am updating. As a part of this process, I removed the android platform and readded it.
Now when I try to build the project I get the following error:
C:\App>cordova build android --verbose
No scripts found for hook "before_build".
No scripts found for hook "before_prepare".
Checking config.xml and package.json for saved platforms that haven't been added to the project
Config.xml and package.json platforms are the same. No pkg.json modification.
Package.json and config.xml platforms are different. Updating config.xml with most current list of platforms.
PlatformApi successfully found for platform android
Checking config.xml for saved plugins that haven't been added to the project
Checking for any plugins added to the project that have not been installed in android platform
No differences found between plugins added to project and installed in android platform. Continuing...
Generating platform-specific config.xml from defaults for android at C:\App\platforms\android\res\xml\config.xml
Merging project's config.xml into platform-specific android config.xml
Found "merges/android" folder. Copying its contents into the android project.
Merging and updating files from [www, platforms\android\platform_www, merges\android] to platforms\android\assets\www
Wrote out android application name "App" to C:\App\platforms\android\res\values\strings.xml
android-versionCode not found in config.xml. Generating a code based on version in config.xml (1.0.20): 10020
Wrote out Android package name "com.nge.app" to C:\App\platforms\android\src\com\nge\bca\MainActivity.java
Updating icons at platforms\android\res
Updating splash screens at platforms\android\res
This app does not have additional resource files defined
Prepared android project successfully
No scripts found for hook "after_prepare".
No scripts found for hook "before_compile".
ANDROID_HOME=C:\Android\sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_40
Error: Cannot read property 'length' of undefined
This did work before I removed the platform so I am guessing it is a bug or a config file that changed.
There is a similar issue here: https://pt.stackoverflow.com/questions/219442/cordova-build-android-error-cannot-read-property-length-of-undefined
I found another solution by downgrading Android to version 6.1.2, since the suggestions here (and many other suggestions on various forums, like reinstalling plugins, etc.) didn't work for me:
cordova platform update android#6.1.2 --save
If that doesn't work at first hand, try the following:
First remove android platform:
cordova platform remove android
Add Android version 6.1.2:
cordova platform add android#6.1.2
Build Android:
cordova build android
Here are some additional steps I took prior to above (on Mac), just to make sure:
Download the latest JDK and install.
Add JAVA_HOME this way:
echo export "JAVA_HOME=\$(/usr/libexec/java_home)" >> ~/.bash_profile
Restart shell (CMD+Q and open again)
Make sure echo $JAVA_HOME equals to Android Studio -> File -> Project Structure -> JDK Location
For me, this is the following path and version:
/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home
Update Android Studio and all of the SDK packages
Update npm
npm update -g
Note: On OS X 10.11 El Capitan or greater, run:
sudo npm update -g --unsafe-perm=true
Update Cordova
npm update -g cordova
If all of this didn't work for you and you are left with no other choice, I suggest you try downgrading Cordova to version 6.4.0:
npm update -g cordova#6.4.0
You can downgrade cordova cli using
npm install -g cordova#6.4.0
and build the project with give command
ionic cordova build android
no need to add platform, it'll automatically add.
If it ask to update cordova cli, then choose no
Resolved an error by following:
Hi all,
Resolved problem to run cordova run android via command prompt for cordova project attached problem screenshot.
To resolve this problem removed all environment variables under Advanced System settings.
Uninstalled java and installed again, downloaded old sdk tools to avoid prompt for eclipse now.
Under user variable added
JAVA_HOME = C:\Program Files\Java\jdk1.8.0_131
Under System variable
ANDROD_HOME = C:\cordova\android-sdk
Path = C:\Program Files\Android\Android Studio2\gradle\gradle-3.2\bin\;%JAVA_HOME%\bin to avoid error:
No installed build tools found. Install the Android build tools version 19.1.0 or higher.
Problem resolved now 😊
The problem was that my gradle version was 2.1 where Cordova wanted 3.2. Updating Android Studio (It was at 2.1) and making sure the environment variables are upto date was the main trick to get it to work again.
Please how can I use the Gradle shipped with android studio out of android studio? I tried running gradle -v on my ubuntu command line but it says the command is not recognized.
For running gradle:
Download gradle
Unzip the zip file
add GRADLE_HOME/bin to your PATH environment variable
Somenthing like:
wget https://services.gradle.org/distributions/gradle-2.5-bin.zip
unzip gradle-2.5-bin.zip
export GRADLE_HOME="$HOME/yourGradleFolder"
PATH="$PATH:$GRADLE_HOME/bin"
More info here.
AndroidStudio donwloads the gradle distributions in this folder:
/home/xxxx/.gradle/wrapper/dists
If you would like to use the gradle wrapper inside the projects, it is enough to run
./gradlew xxxxxx
May you can install grade from
Gradel download link
Building and Running from the Command Line
then Follow this link Building and Running from the Command Line
please let me know if any issue.Thanks for asking.
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.