$ 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! :)
I have created a fresh app from react-native-cli.
The generated boilerplate had the following versions.
React-native: 0.57.8
React: 16.6.3
Gradle Version: 4.4
Java Version (JDK): 1.8.0_191-b12
I am unable to execute react-native run-android
I get the following error
What went wrong:
A problem occurred configuring project ':app'.
Could not generate a proxy class for class com.android.build.gradle.tasks.BuildArtifactReportTask.
I want to know whether the error is due to react version or gradlew
P.S. Application builds and installs on device / emulator when running through Android Studio but not when running via react-native-cli
https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Please update the JDK version after that go to the inside android folder and use this cmd
./gradlew clean
after cleaning gradle try to build again.
I have just started with ReactNative and created a project using this tutorial. The project got built and a android application got installed on my phone.
Then I used #shoutem/ui library for UI components. According to the documentation, I tried
npm install #shoutem/ui --save
react-native link
and then run the project using
react-native run-android
But then I got this error
PS D:\SK\Study\ReactNative\DemoRN> react-native run-android
Scanning folders for symlinks in D:\SK\Study\ReactNative\DemoRN\node_modules (38ms)
JS server already running.
Building and installing the app on the device (cd android && gradlew.bat installDebug)...
File C:\Users\sukumar\.android\repositories.cfg could not be loaded.
Failed to download any source lists!
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugApk'.
> A problem occurred configuring project ':react-native-photo-view'.
> Failed to find Build Tools revision 25.0.0
* 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: 11.028 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
And then I unlinked the #shoutem/ui
react-native unlink #shoutem/ui
and tried to run the project, but still, I am facing the same issue?
Please ignore if it is too basic to ask, But I am not able to understand what is the issue?
Update
I am not using Android Studio, So I downloaded the build-tools 25.0.0 and placed in sdk/build-tools folder. But now I am facing
> A problem occurred configuring project ':react-native-photo-view'. > Failed to find Platform SDK with path: platforms;android-23
This seems to be an issue with the available SDK Tools in your installation of Android Studio:
> Failed to find Build Tools revision 25.0.0
Installing these should resolve the issue. To install this, start up Android studio, go to the SDK Manager and select the SDK Tools tab, check the Show Package Details option in the bottom right corner and then check the 25.0.0 SDK Tools and click Apply to download and install them.
Here's a screenshot of the SDK Tools I use for my local environment for reference:
Furthermore, I'd just like to elaborate on the react-native (un)link command. This is used to link native dependencies into your React Native project. Unlinking it is not the same as uninstalling it, you should still be able to use all non-native components of the Shoutem UI Toolkit after unlinking the package.
I am not using Android Studio, So I downloaded the build-tools 25.0.0 and placed in SDK/build-tools folder. This solved the build tools issue but then there was a new issue
A problem occurred configuring project ':react-native-photo-view'. > Failed to find Platform SDK with path: platforms;android-23
The network I was using has configured some firewalls rules that were not allowing the required dependencies get downloaded. When you run react-native run-android it downloads all the dependencies automatically to create the build.
So In my case, I changed my network settings and this worked.
when i Run the command phonegap build android it gives me the the error execution failed for task 'mergeDebugResources' I am implementing the plugin cordova-background-geolocation-lt and following the same as explained there and install the same SDK's.
complete error
Here is some more info about DEBUG after running the command gradlew.bat --info build clean
I think this is a clash with some other plugin. I have tried adding the diagnostic plugin to a brand new project and tried building. That worked fine.
I can run my ionic project on android device perfectly until now but now this error is happens. I did not change anything in project structure.
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'android'.
> Could not resolve all dependencies for configuration ':_armv7DebugCompile'.
> Could not find any version that matches org.xwalk:xwalk_core_library_beta:13+.
Searched in the following locations:
https://repo1.maven.org/maven2/org/xwalk/xwalk_core_library_beta/maven-metadata.xml
https://repo1.maven.org/maven2/org/xwalk/xwalk_core_library_beta/
https://download.01.org/crosswalk/releases/crosswalk/android/maven2/org/xwalk/xwalk_core_library_beta/maven-metadata.xml
file:/Applications/android-sdk/extras/android/m2repository/org/xwalk/xwalk_core_library_beta/maven-metadata.xml
file:/Applications/android-sdk/extras/android/m2repository/org/xwalk/xwalk_core_library_beta/
file:/Applications/android-sdk/extras/google/m2repository/org/xwalk/xwalk_core_library_beta/maven-metadata.xml
file:/Applications/android-sdk/extras/google/m2repository/org/xwalk/xwalk_core_library_beta/
Required by:
:android: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: 20.525 secs
/Users/myuser/Projects/appname/platforms/android/cordova/node_modules/q/q.js:126
throw e;
^
Error code 1 for command: /Users/myuser/Projects/appname/platforms/android/gradlew with args: cdvBuildDebug,-b,/Users/myuser/Projects/appname/platforms/android/build.gradle,-PcdvBuildArch=x86,-Dorg.gradle.daemon=true
I removed android platform and all node_modules and added them again but still i see this error.
i can serve my app and run on IOS simulator perfectly.
I had the same problem!
I solved it with the following steps:
Remove browser with ionic browser revert android
Install crosswalk again ionic browser add crosswalk
Deploy aplication ionic run android
I had same problem, on run time I used VPN in ionic build android and Ionic run android command. this will help to reach the website to download components.
Also about the maven
I run CMD command with "Run as Administrator" it started to download maven and after that it works fine for me.
Before this I used to upgrade JDK and JRE but has not change in result.
I have upgraded Windows 7 to Windows 10 directly and some times applications needs to start by using "Run As administrator"
I have found the solution for the problem using the google play service and Google Repository in android SDK
Please install the following dependency using android SDK manager Google Play services and Google Repository
Once the installation is completed then you create your project and run.
Now it should work fine