previously I can compile but after I updated my cordova something happended. I got this error.
FAILURE: Build failed with an exception.
* Where:
Script 'C:\Users\Jay\testproject\platforms\android\CordovaLib\cordova.grad
le' line: 64
* What went wrong:
A problem occurred evaluating root project 'android'.
> No installed build tools found. Please install the Android build tools version
19.1.0 or higher.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug
option to get more log output.
I downloaded all the required SDK, what is the problem here?
I had the same problem and this is how I fixed it. I had the build-tools version 20 installed but still was getting this error:
No installed build tools found. Please install the Android build tools
version 19.1.0 or higher.
So I created a directory named 20 within build-tools directory, and copied all the files from sdk\build-tools\android-4.4W\* to sdk\build-tools\20. The problem was fixed!
You will need to do two main things:
Install android build tools
Make them available in your shell, when run the ionic run command.
Installing the build tools (ver 19.1.0)
Open android development studio
Goto: Configure --> SDK Manager --> select "Android SDK Build-Tools
select the checkbox "Show Package details" (bottom right)
review the versions of this package, make sure the 19.1 is selected - u may use newer, but 19.1.0 works.
Click Apply to make the changes / install it
Make the build tools available in your shell environment
Edit ~/.bash_profile by using vi or other shell editor
vi ~/.bash_profile
Add the following lines:
export ANDROID_HOME=~/Library/Android/sdk
export PATH=${PATH}:~/Software/android-sdk-macosx/tools:~/Software/android-sdk-macosx/platform-tools"
(save the file, and exit)
Editing the file, makes sure that for each login those variables will be available, but as we are already in active session, you need to make it available for the current shell env, run the following:
. ~/.bash_profile
I was stuck with this error for several days, I didn't find any clear explanation
Till I find this link, https://tomspencer.dev/blog/2017/05/30/a-guide-to-installing-cordova-on-windows-10
uninstall gradle, cordova, ionic, and anything related then use the steps in the link above to install them all correctly. that worked with me
Related
I'm trying to build an hybrid app using the cordova cli using command
cordova build android
But it fails with error (complete log) :
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=undefined (recommended setting)
ANDROID_HOME=undefined (DEPRECATED)
Using Android SDK: /usr/lib/android-sdk
Subproject Path: CordovaLib
Subproject Path: app
FAILURE: Build failed with an exception.
* Where:
Script '/home/iam/Projects/lave/platforms/android/CordovaLib/cordova.gradle' line: 75
* What went wrong:
A problem occurred evaluating script.
> No usable Android build tools found. Highest 30.x installed version is 27.0.1; Recommended version is 30.0.3.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/7.1.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 1s
I have followed this step thinking it would solve the issue but problem remain and I get same error even after installing the packages.
Actual image from my Android SDK Settings :
It's worth mentioning that I have installed Android-SDK using apt and afterwards I have set up environment path with this command :
export ANDROID_HOME="/usr/lib/android-sdk/"
export PATH="${PATH}:${ANDROID_HOME}tools/:${ANDROID_HOME}platform-tools/"
After installing the packages in Android-SDK,I restarted Ubuntu thinking it would fix the problem. But still receives same error message when trying to build. Am I missing something?
From the error logs I think it cannot find your ANDROID_SDK_ROOT, please check if it is set like this in your environment variables:
export ANDROID_SDK_ROOT=/Users/[USERNAME]/Library/Android/sdk
export PATH=$ANDROID_SDK_ROOT/tools:$PATH
I believe you should also set the path to your build- and platform tools like so (for your versions/paths of course):
export PATH=${PATH}:/Users/[USERNAME]/Library/Android/sdk/build-tools/33.0.0uild-tools/30.0.3
export PATH=${PATH}:/Users/[USERNAME]/Library/Android/sdk/platform-tools
Can you check that you have set al of these, or something similar? Also be aware that you may have to fix something in your build tools (this is the case for several versions, I don't know of the top of my head which ones, so it's worth to check): Android Studio error "Installed Build Tools revision 31.0.0 is corrupted"
I want to offer the solution that worked for me for Ubuntu. I suddenly remembered I had written a tutorial for mac here on SO. Remembering this made me realize I forgot to set the JAVA_HOME which Cordova looks for while Checking Java JDK and Android SDK versions. Also, ANDROID_HOME is completely obsolete and deprecated. Set the same path for ANDROID_HOME to ANDROID_SDK_ROOT (same thing).
export PATH=$PATH:$ANDROID_HOME/platform-tools
export ANDROID_SDK_ROOT=/home/iam/Android/Sdk
export JAVA_HOME=/opt/android-studio-2021.3.1/android-studio/jre
Create a bash profile and paste the above codes then save
sudo gedit ~/.bash_profile
Run this
source ~/.bash_profile
Now when running
cordova build android --prod
Gradle should be able to configure for the first time and do the necessary tasks and then boom
BUILD SUCCESSFUL in 7m 4s
48 actionable tasks: 48 executed
$ npx react-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 864 file(s) to forward-jetify. Using 4 workers...
info Starting JS server...
info Launching emulator...
error Failed to launch the emulator. Reason: Could not start an emulator within 30 seconds.
warn Please launch an emulator manually or connect a device. Otherwise, the app may fail to launch.
info Installing the app...
FAILURE: Build failed with an exception.
What went wrong:
Could not initialize class org.codehaus.groovy.runtime.InvokerHelper
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 1m 23s
error Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
What went wrong:
Could not initialize class org.codehaus.groovy.runtime.InvokerHelper
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 1m 23s
at checkExecSyncError (child_process.js:629:11)
at execFileSync (child_process.js:647:13)
at runOnAllDevices (E:\work\react-native\AwesomeProject1\node_modules\#react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:94:39)
I think I had the same issue. After installing RN (May 20th, 2020), I bumped into this error. I found this solution on https://github.com/gradle/gradle/issues/10248.
In short:
Go to /android/gradle/wrapper/gradle-wrapper.properties file in your RN project
Find this line that starts with distributionUrl. Change the gradle version into gradle-6.3-all.zip.
In my project, it was:
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip
and I changed it into:
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip
That's it.
I had the same error on Mac OS and React Native v0.62.
Apply these instructions correctly: React native environment setup
Adding this variable solved my problem:
export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home"
In the React Native version 0.62.x even the initialized application is not ready for a development build.
I change the Gradle version to the latest and I could to have a clean build, so change this file:
// this file => /android/gradle/wrapper/gradle-wrapper.properties
from:
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip
to:
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
Pay Attention: The latest version of the Gradle for my time is 6.5. when you are reading this answer please check this link to see the latest version number of the Gradle.
Update Jan 24, 2023
7.6
I fixed this by these steps:
install android studio 3.5 (or later)
install java 1.8
if you have java JDE 14.x.x you have to remove its folder from library/java/JavaVirtualMachines/jdk-14.x.x.jdk (on mac os)
install an older version of JDE (I installed 11.0.6)
npm run android!
Just follow these 2 steps only and take your coffee.
Navigate to 'android' > gradle > wrapper > gradle-wrapper.properties
Change 'distributionUrl' from old to >
distributionUrl=https://services.gradle.org/distributions/gradle-6.3-all.zip
This Error occurs when the gradle version you used is not compatible on your environment, so you just need to update your gradle version to latest Gradle Versions, just go to: /android/gradle/wrapper/gradle-wrapper.properties to your project file.
Auguest 2021
I was using JDK 16.0.1 and faced this issue. So, for JDK 16.0.1 you need 7.0 version of gradle.
I fixed it by going to /android/gradle/wrapper/gradle-wrapper.properties and changing
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-all.zip
to
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-all.zip
If you are a macOS user then you should install
brew cask install adoptopenjdk/openjdk/adoptopenjdk8
brew cask install android-platform-tools
update your .bash_profile
nano ~/.bash_profile
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
This would resolve your problem. If you are working on a legacy codebase then changing the distribution URL would lead to other problems. It usually happens because of mismatching java versions.
It's probably because you use Gradle as the build system and JDK14
and the Gradle version is old. Reference:
If you use Gradle Wrapper then refer to
$PROJECT_ROOT/gradle/wrapper/gradle-wrapper.properties
Property distributionUrl should be:
distributionUrl=https://services.gradle.org/distributions/gradle-6.3-bin.zip
If it's an older version then change it, run ./gradlew clean build
and try again.
It is because your Gradle version is not supported by the Java JDK. If you use the JDK version 15.0.2 then you need to Gradle version change 6.6.1 or 6.7
To Change the Gradle Version in Android Studio.
android[project_name]/gradle/wrapper/gradle-wrapper.properties
Open this file and set this
distributionUrl=https://services.gradle.org/distributions/gradle-6.6.1-all.zip
then this problem will be solved.
To check the java JDK version.
open cmd.
run echo %JAVA_HOME%
Then you can also search on google to check the supported version of Gradle to the JDK.
updating JAVA_HOME works for me in mac OS
export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home"
This issue is caused by incorrect version of graddle. so to fix this follow these steps
Make sure you have Android studio installed and SDK is setuped from Android studio menu Tool-> SDK Manager you can setup SDK, install latest SDK if you are using latest version of React Native .
From Android Studio menu Tools > AVD Manager Setup one device and download the image. and test it to see that emulator is running OK.
Make Sure JDK is installed for latest react native install latest JDK : https://www.oracle.com/java/technologies/javase-downloads.html
Next from Android Studio menu File > New > new project create one dummy project aka Hello world and build make sure all android studio issues resolved and your Android studio hello world app is running on emulator.
Now time to fix your react native app. Stop your Android studio hello world app and keep the emulator running.
Locate your Android studio hello world app on your system and go to gradle\wrapper folder and copy the gradle-wrapper.properties file
example in windows case my hello world app is located in my documents:
C:\Users\Superman\Documents\android\hello world\gradle\wrapper
Next go to your react native app folder like : myReactApp\android\gradle\wrapper and paste the gradle-wrapper.properties file you copied from your Android studio hello world app.
finally in your terminal execute : npx react-native run-android
I have the same issue with new project and windows. I try all these way but it doesn'. Ridiculously, I move java/jdk folder from C:\Program Files to another dir in D:\ and it works like a charm.
May be it's useful.
December 2021
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 here the lastest releases of Gradle.
If you're looking for a solution for a Java/Kotlin Core Android project and not a React Project because i was also facing this problem in my core android project so here you go...
None of the above solutions worked for me. So basically the idea is to Change the version of gradle. How to do that you ask? Follow these steps:
File>Project Structure
Select SDK Location
You will find something written as "JDK was moved to Gradle Settings". Click on Gradle Settings.
Use Gradle Version 11.0
Sync the project again.
And there you go! A successfully built project! :)
My React-Native application suddenly stopped working when I installed and tried to import react-native-vector-icons module (even though I do not make any connection with the problem).
It seems that my AVD failed miserably. I had problems with ADB seemingly not working anymore but I guess I solved them. Afterwards, I started getting errors from SDK licenses, being informed that I did not accept them. I used sdkmanager.bat, and accepted all of them. On running npm run android I was receiving the same error. Seemingly, even though the licenses were accepted, the folder containing them was not where it was searched for (Android\Sdk\platform-tools\licenses). So I copied it there.
Next time, the licenses were accepted, but I get this error that says the SDKs cannot be downloaded because the folders already exist (I do not understand why I have to download the SDK AGAIN, anyway). I go on and delete all conflicting folders just to run the command again, the CLI starts downloading (I guess) and making the folders I have deleted just so that immediately after I am again informed that the folders exist.
My best guess (and I'm probably wrong) is that while resolving ADB / license conflicts, somehow I messed up the Path Variables. I changed them 100 times anyway, one step away from backtracking the shit out of them.
I deleted all Android folders, Android Studio, SDK's, started everything all over again just to get back to this point. I've wasted 8 hours. Please, give me a hand.
Running on Marshmallow 23.0.1 ofc.
Thank you in advance!
npm run android
ReactNNN#0.1.0 android D:\Work\reactn-naturist react-native
run-android
Scanning folders for symlinks in D:\Work\reactn-naturist\node_modules
(20ms) JS server already running. Building and installing the app on
the device (cd android && gradlew.bat installDebug)... Observed
package id 'platform-tools' in inconsistent location
'C:\Users\alexandru.andronache\AppData\Local\Android\Sdk\platform-tools'
(Expected
'C:\Users\alexandru.andronache\AppData\Local\Android\Sdk\platform-tools\platform-tools')
Observed package id 'platform-tools' in inconsistent location
'C:\Users\alexandru.andronache\AppData\Local\Android\Sdk\platform-tools'
(Expected
'C:\Users\alexandru.andronache\AppData\Local\Android\Sdk\platform-tools\platform-tools')
Observed package id 'platform-tools' in inconsistent location
'C:\Users\alexandru.andronache\AppData\Local\Android\Sdk\platform-tools'
(Expected
'C:\Users\alexandru.andronache\AppData\Local\Android\Sdk\platform-tools\platform-tools')
File C:\Users\alexandru.andronache\.android\repositories.cfg could not
be loaded. Checking the license for package Android SDK Build-Tools
23.0.1 in C:\Users\alexandru.andronache\AppData\Local\Android\Sdk\platform-tools\licenses
License for package Android SDK Build-Tools 23.0.1 accepted. Preparing
"Install Android SDK Build-Tools 23.0.1". Warning: Trying to install
into
C:\Users\alexandru.andronache\AppData\Local\Android\sdk\platform-tools\build-tools\23.0.1\
but package "Android SDK Platform-Tools" already exists at
C:\Users\alexandru.andronache\AppData\Local\Android\sdk\platform-tools\.
It must be deleted or moved away before installing into a child
directory. Checking the license for package Android SDK Platform 23 in
C:\Users\alexandru.andronache\AppData\Local\Android\Sdk\platform-tools\licenses
License for package Android SDK Platform 23 accepted. Preparing
"Install Android SDK Platform 23". Warning: Trying to install into
C:\Users\alexandru.andronache\AppData\Local\Android\sdk\platform-tools\platforms\android-23\
but package "Android SDK Platform-Tools" already exists at
C:\Users\alexandru.andronache\AppData\Local\Android\sdk\platform-tools\.
It must be deleted or moved away before installing into a child
directory.
FAILURE: Build failed with an exception.
* What went wrong: A problem occurred configuring project ':app'.
Failed to install the following SDK components: [Android SDK Platform 23, Android SDK Build-Tools 23.0.1] Please install the
missing components using the SDK manager in Android Studio.
* Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 4.505 secs Could not install the app on the device, read
the error above for details. Make sure you have an Android emulator
running or a device connected and have set up your Android development
environment:
https://facebook.github.io/react-native/docs/android-setup.html
My PATH variables:
P.S. I read all other similar posts and couldn't manage anything. Just getting from error to error.
in your Android Studio go to the SDK manager and then click the Show Package Details.
Try to install these sdk packages:
These worked for me.
If still not work add to the path variable the /platform-tools (same path as /tools)
I'm trying to use Cordova to build a hello world app and after adding ANDROID_HOME variable (You'd be shocked how long that took to figure out) all I keep seeing when building is this:
BUILD FAILED
Total time: 1 mins 6.679 secs Error:
/Users/vladdy/Desktop/laboratory/cordovaBackgroundApp/platforms/android/gradlew:
Command failed with exit code 1 Error output:
FAILURE: Build failed
with an exception.
What went wrong: A problem occurred configuring root project 'android'.
Failed to find target with hash string 'android-25' in: /Users/vladdy/Library/Android/sdk
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Ok fair enough so let's go install it:
Waiting patiently for the install, and same error running cordova build.
I wonder what else we need to install? But look, it seems that Android Studio still has Nougat and 25 available:
Why is Android Studio not installing anything?
I can see why PhoneGap Build is so popular...
Edit:
cordova requirements is now broken reporting the following:
My ~/.bash_profile:
export ANDROID_HOME=/Users/vladdy/Library/Android/sdk/
Requirements?
If you don't need Android Studio, I recommend not downloading it, instead, as #Tom-Esendam also suggest, go for the command-line tool.
Android Studio and Command Line Tool
Direct download link of Command Line Tool for OSX (2017-03-21)
Proxy?
And if your behind a proxy server, don't forget to add it to the settings in the SDK Manager Settings.
What does the different programs and commands?
cordova build doesn't download any SDK's.
cordova prepare appends the necessary SDK files to the cordova build folders.
After download of Command Line Tool:
After unzipping it, set ANDROID_HOME to it's root, so you have:
build-tools
extras
platforms
platform-tools
system-images
tools
catalogs under the root.
Adding SDK's:
Then install SDK's with ./tools/android.
Android SDK Manager downloads the SDK's, so you check what you need and hit OK to download it.
Preparing the build
Make sure all proxy settings are set if your behind a proxy.
Before running cordova build run cordova prepare. This shouldn't be necessary, but least I need to run that even thou cordova build should include that.
I don't know about the mac version. But on windows you have a standalone sdk manager. If there is one on mac try that?
I'm manually installing an Android-Gradle build server which means that I'm not using Android Studio SDK but instead using the android update sdk command to install the required tools.
I was able to install most of the packages which are required for the build to finish successfully but there are some tools which I'm unable to find:
com.android.support.constraint:constraint-layout:1.0.0-alpha(1-4)
com.android.support.constraint:constraint-layout-solver:1.0.0-alpha(1-4)
Following #CommonsWare comment, here's the output of the build (which shows that the tools are being looked for at the repositories automatically but not found:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':Company'.
> Could not resolve all dependencies for configuration ':Company:_productionDebugCompile'.
> Could not find com.android.support.constraint:constraint-layout:1.0.0-alpha4.
Searched in the following locations:
https://jcenter.bintray.com/com/android/support/constraint/constraint-layout/1.0.0-alpha4/constraint-layout-1.0.0-alpha4.pom
https://jcenter.bintray.com/com/android/support/constraint/constraint-layout/1.0.0-alpha4/constraint-layout-1.0.0-alpha4.jar
http://dl.bintray.com/optimizely/optimizely/com/android/support/constraint/constraint-layout/1.0.0-alpha4/constraint-layout-1.0.0-alpha4.pom
http://dl.bintray.com/optimizely/optimizely/com/android/support/constraint/constraint-layout/1.0.0-alpha4/constraint-layout-1.0.0-alpha4.jar
file:/Users/itai/work_repos/Company-Android_fork/.gradle/android-sdk-linux/extras/android/m2repository/com/android/support/constraint/constraint-layout/1.0.0-alpha4/constraint-layout-1.0.0-alpha4.pom
file:/Users/itai/work_repos/Company-Android_fork/.gradle/android-sdk-linux/extras/android/m2repository/com/android/support/constraint/constraint-layout/1.0.0-alpha4/constraint-layout-1.0.0-alpha4.jar
file:/Users/itai/work_repos/Company-Android_fork/.gradle/android-sdk-linux/extras/google/m2repository/com/android/support/constraint/constraint-layout/1.0.0-alpha4/constraint-layout-1.0.0-alpha4.pom
file:/Users/itai/work_repos/Company-Android_fork/.gradle/android-sdk-linux/extras/google/m2repository/com/android/support/constraint/constraint-layout/1.0.0-alpha4/constraint-layout-1.0.0-alpha4.jar
Required by:
Company-Android_fork:Company:unspecified
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 15.163 secs
Any idea how they can be installed manually (not through Android Studio)?
Thanks in advance,
Now you can install it through command line:
your_sdk_location/tools/bin/sdkmanager "extras;m2repository;com;android;support;constraint;constraint-layout;1.0.2"
It is not possible without Android Studio 2.2 Beta yet, but if you have it somewhere, then you just need to copy the m2repository from your sdk/extras to your project sdk/extras folder.
So if you have your project built in an Android Studio:
check the project's sdk location (File/Project Structure : SDK location).
go to your_sdk_location/extras folder and copy m2repository
paste the folder to your existing project's sdk/extras folder.
rebuild your project.