lvlzyro
lvlzyro

Reputation: 15

React Native Fails When I Try To Run on Emulator

today I just created my first React Native project but when I tried to run it on my avd just like;

react-native run-android

but it always gives this:

info JS server already running.
info Building and installing the app on the device (cd android && ./gradlew app:installDebug)...
Starting a Gradle Daemon, 1 incompatible and 2 stopped Daemons could not be reused, use --status for details
> Task :app:preBuild UP-TO-DATE
> Task :app:preDebugBuild UP-TO-DATE
> Task :app:compileDebugAidl NO-SOURCE
> Task :app:compileDebugRenderscript NO-SOURCE
> Task :app:checkDebugManifest UP-TO-DATE
> Task :app:generateDebugBuildConfig UP-TO-DATE
> Task :app:bundleDebugJsAndAssets SKIPPED
> Task :app:prepareLintJar UP-TO-DATE
> Task :app:generateDebugSources UP-TO-DATE
> Task :app:javaPreCompileDebug
> Task :app:mainApkListPersistenceDebug UP-TO-DATE
> Task :app:generateDebugResValues
> Task :app:generateDebugResources
> Task :app:mergeDebugResources
> Task :app:createDebugCompatibleScreenManifests UP-TO-DATE
> Task :app:processDebugManifest UP-TO-DATE
> Task :app:processDebugResources
> Task :app:compileDebugJavaWithJavac FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Could not find tools.jar. Please check that /usr/lib/jvm/java-8-openjdk/jre contains a valid JDK installation.

* 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 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.1.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 26s
12 actionable tasks: 5 executed, 7 up-to-date
error 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/getting-started.html
error Command failed: ./gradlew app:installDebug. Run CLI with --verbose flag for more details.

I don't know what should I do and I totally need your help.

Thanks for your attention.

Upvotes: 1

Views: 24008

Answers (2)

abhinandan sharma
abhinandan sharma

Reputation: 883

It was a problem with system looking at the JRE folder i.e. /usr/lib/jvm/java-8-openjdk/jre. If we look in there, there is no Tools.jar, hence the error.

You can create environment variables JAVA_HOME :

enter image description here

Inside Variable value add your JDK in place of jdk1.8.0_11

Now edit yout PATH variable to add JAVA_HOME : enter image description here

Now try to run the command again .

OR



Check this path C:\Program Files\Android\Android Studio\jre\lib if you find tools.jar there then try setting JAVA_HOME=C:\Program Files\Android\Android Studio\jre in above enviroment variable.

For Linux Users -

Edit the system Path file /etc/profile

sudo gedit /etc/profile

Add following lines in end

JAVA_HOME=/usr/lib/jvm/jdk1.7.0
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH

In place of jdk1.7.0 add your JDK version.
Then Log out and Log in ubuntu for setting up the paths...

Hope it works !

Upvotes: 1

Afroze Kabeer Khan
Afroze Kabeer Khan

Reputation: 45

Hi. You need to check if JDK is properly installed and verify that you have added the environment variables JAVA_HOME & JDK_HOME.

Upvotes: 0

Related Questions