“Could not find an installed version of Gradle” in ionic 3 [duplicate] - android

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.

Related

Could not compile settings gradle React Native

The app worked for me from another machine, now that downloading the files from the repository on another computer gives me this problem
FAILURE: Build failed with an exception.
Where:
Settings file 'C:\Users\samue\Desktop\MCGPS\TeachAll\android\settings.gradle'
What went wrong:
Could not compile settings file 'C:\Users\samue\Desktop\MCGPS\TeachAll\android\settings.gradle'.
startup failed:
General error during semantic analysis: Unsupported class file major version 57
This is an issue with how Gradle is automating the build and the current version of the JDK installed on your machine, follow these steps to fix it, the react native documentation states you need adoptopenjdk8, however you may have other conflicting JDK versions in the same directory.
Blog post: https://ashirazee.medium.com/react-native-android-failure-build-failed-with-an-exception-908934c3a32b
Step one:
open up your terminal and navigate to /Library/Java/JavaVirtualMachines by typing the following command:
cd /Library/Java/JavaVirtualMachines
after you have done that type ls to see what files are included and take note of the versions.
incase you have one or multiple JDK files present like such:
adoptopenjdk-8.jdk jdk-16.jdk jdk-8.jdk
then go head and delete them with the following command line :
sudo rm -rf /Library/Java/JavaVirtualMachines/jdk-16.jdk
sudo rm -rf /Library/Java/JavaVirtualMachines/jdk-8.jdk
the only dependency you need is adoptopenjdk-8.jdk as mentioned in the react native docs
however delete that aswell and reinstall it after you have completed these steps:
sudo rm -rf /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk
after you have done so you can check if the files still exist by typing ls
if the files are deleted.
Step 2:
then run the following commands to insure all other links, plugins and files are deleted as-well from your Library:
run the following :
sudo rm -rf /Library/PreferencePanes/JavaControlPanel.prefPane
sudo rm -rf /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo rm -rf ~/Library/Application\ Support/Oracle/Java
Step 3:
once you have done the following, reinstall the correct jdk as mentioned in the react native docs like so:
brew install --cask adoptopenjdk/openjdk/adoptopenjdk8
https://reactnative.dev/docs/_getting-started-macos-android
this may say adoptopenjdk-8.jdk is already installed, but go ahead and reinstall install it with:
brew reinstall adoptopenjdk8
At this point the error should be resolved and your build should work.
It is important to note that this is a build error, since react native uses Gradle to build automations, the conflicting of multiple jdk versions can cause your build to fail.
please refer to the following documentation:
https://docs.gradle.org/current/userguide/userguide.html
This is due to the jdk version intalled on your system.
If you're using the latest version of Java Development Kit, you'll need to change the Gradle version of your project so it can recognize the JDK. You can do that by going to {project root folder}\android\gradle\wrapper\gradle-wrapper.properties and changing the distributionUrl value to upgrade the Gradle version. You can check out latest releases of gradle and note the latest version of gradle and edit in gradle-wrapper.properties and change the distributionUrl
I have solved issue by just opening project in Android studio
react native version 0.60.5
Open the android folder using Android Studio. Then all dependencies will start downloading(as shown in the picture). Let them complete. After completely downloaded and loaded you can run the project.
this issue seems to be with the java version, pls check for correct version. also even if two or more jdk are installed we can specify during runtime which jdk has to be used by specifying this gradlew.bat build -Dorg.gradle.java.home=---path-to-jdk---
Solved it by downgrading Java and upgrading Gradle version.
I had the same problem, I came here looking for a solution. I selected JDK 11 instead of 16, but it didn't work, I remembered that I didn't point the way for the new JDK version in ~/.bashrc, now it finally worked.

Cordova Android build error "Cannot read property 'length' of undefined"

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.

Cordova gradle installed but not found

I'm trying to get an environment for android and cordova, but I don't know why cordova doesn't link with gradle.
I've tried to re install gradle for command line, then tried to get it from npm but whatever i do, the "cordova requirements" command tells me that gradle is not installed.
Does anyone know how to solve this?
I had the exact same problem !
I changed "path" (https://www.computerhope.com/issues/ch000549.htm) and added the path to my gradle's binary file : C:\Program Files\Android\Android Studio\gradle\gradle-3.2\bin

Ionic 2 platform add android error

Im trying to build an android app with ionic 2. When I try to run ionic platform add android I get this error: Failed to find 'ANDROID_HOME' environment variable. Try setting setting it manually. Failed to find 'android' command in your 'PATH'.
Im using linux mint and already set the environment variables like this:
export ANDROID_HOME=/home/mauro/Android/Sdk
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
When I type android in the console, the sdk manager gets started.
My ionic version is: 2.1.7
and cordova: 6.4.0
Hope anybody can help me with this issue.
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
Hope this helps.....
I have the same issue. It seems to be an issue of the combination of cordova, the installed Android SDK version and the profile settings.
This is what worked for me on ubuntu 16.10:
get an older cordova that is known to work:
npm install -g cordova#4.2
(I was on 6.4.0 and 5.0.0)
in .profile:
PATH="~/Android/Sdk/platform-tools:~/Android/Sdk/tools:$PATH"
export ANDROID_HOME=~/Android/Sdk
(Seems you are good there)
I needed the latter to stop the complaining about it even while android was in my path and it also gave me meaningfull errors, which was that API 22 was missing.
Load the profile in current bash:
source ~/.profile
Type android and install SDK 22.
Exit when done and type
ionic build android
and it should work.

Cordova run android : ANDROID_HOME not set and android not in my path

When i run for android, i see this error :
ERROR: Error: ANDROID_HOME is not set and "android" command not in your PATH. You must fulfill at least one of these conditions.
But this "variable" are ok. "Android" launch SDK manager and ANDROID_HOME redirect to my sdk folder.
I don't understand this error.
FYI my export :
export ANDROID_HOME=`brew --prefix android`
export PATH=${PATH}:$ANDROID_HOME/bin
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
I answer me !
My solution :
sudo chown -R your-user /usr/local/lib/node_modules/cordova
Remove and add platform
Ubuntu 14.04
gedit /root/.bashrc
add line
export JAVA_HOME=/usr/lib/jvm/java-8-oracle/
ANDROID_HOME=/root/android/sdk/
export ANDROID_HOME=$ANDROID_HOME
PATH=$PATH:$ANDROID_HOME/tools
PATH=$PATH:$ANDROID_HOME/platform-tools
PATH=$PATH:$ANDROID_HOME/build-tools
IN TERMINAL
source ~/.bashrc
Resolveu pra mim/Solved for me!
When my environment is OK (which means that running 'android' via CLI will open the android sdk manager), but I still get this error...
I do the follow:
1 - Remove the platform Android from your project cordova platform remove android
2 - Then I just run again phonegap run android (it'll add the platform Android automatically)
Took me longer than I care to admit to solve this problem, so I thought I'd share how I got this working on Mac for the more novice users such as myself and also those who have not installed with Homebrew:
1) Open your bash profile file (the path to finding this file is 'User/.bash_profile', the name of your file may be .profile or something similar).
2) Add a path to wherever you have saved the Android SDK (you may add something like this: 'export PATH=${PATH}:/Applications/adt-bundle/sdk/platform-tools:/Applications/adt-bundle/sdk/tools' or you may add something like this: 'export PATH=${PATH}:/Desktop/adt-bundle/sdk/platform-tools:/Desktop/adt-bundle/sdk/tools').
Make sure the file name 'adt-bundle' shown in the path above is the name you have saved for the folder! If it isn't, either save the folder with this name, or alter the path to reflect what you have saved the folder as.
3) Try again. You might encounter some further errors, I resolved mine by visiting this page: Cordova 3.5.0 Install Error- Please Install Android Target 19 I typed 'Android' in the terminal to head straight to the package manager in Eclipse. After installing the required version the command worked and installed the Android package to my Cordova application.
I found the following pages very helpful in coming to the above conclusions:
-Understanding the path (needed a refresher on using path! Last time I had to bother with this was ages ago when installing the rbenv Ruby environment): http://help.exercism.io/understanding-path.html
-Setting up for Android (where I found the path): http://docs.phonegap.com/en/edge/guide_platforms_android_index.md.html#Using%20Plugman%20to%20Manage%0APlugins
No 'sudo' required.
I had to close and re-open my windows console (or open a new console), and then open the SDK manager (ran android), after which a bunch of updates and installs had to complete.
For me following steps work :
sudo chown -R your-user /usr/local/lib/node_modules/cordova
export PATH=$PATH:/users/your-user/android-sdks/tools
and then update your android if it is not updated to latest version.
http://blog.codersight.com/2015/05/error-androidhome-is-not-set-and.html
For anybody like me who has tried everything in the answers and have all the environmental variables set up but still gets an error. You might need to remove and add the android platform to your project with the cordova CLI.
cordova platform rm android
cordova platform add android

Categories

Resources