Karl Adler
Karl Adler

Reputation: 16836

Ubuntu, can not start react-native: Could not find tools.jar

I followed the getting started guide Android/Linux.

I try to start react native under ubuntu using react-native run-android, but it fails with the error:

FAILURE: Build failed with an exception.

    * What went wrong:
    Execution failed for task ':app:compileDebugJavaWithJavac'.
    > Could not find tools.jar  

How can I fix it?

Full output:

 $ react-native run-android
    Starting JS server...
    /bin/sh: 1: adb: not found
    Building and installing the app on the device (cd android && ./gradlew installDebug...
    :app:preBuild UP-TO-DATE
    :app:preDebugBuild UP-TO-DATE
    :app:checkDebugManifest
    :app:preReleaseBuild UP-TO-DATE
    :app:prepareComAndroidSupportAppcompatV72301Library UP-TO-DATE
    :app:prepareComAndroidSupportRecyclerviewV72301Library UP-TO-DATE
    :app:prepareComAndroidSupportSupportV42321Library UP-TO-DATE
    :app:prepareComFacebookFrescoDrawee0110Library UP-TO-DATE
    :app:prepareComFacebookFrescoFbcore0110Library UP-TO-DATE
    :app:prepareComFacebookFrescoFresco0110Library UP-TO-DATE
    :app:prepareComFacebookFrescoImagepipeline0110Library UP-TO-DATE
    :app:prepareComFacebookFrescoImagepipelineBase0110Library UP-TO-DATE
    :app:prepareComFacebookFrescoImagepipelineOkhttp30110Library UP-TO-DATE
    :app:prepareComFacebookReactReactNative0361Library UP-TO-DATE
    :app:prepareComFacebookSoloaderSoloader010Library UP-TO-DATE
    :app:prepareOrgWebkitAndroidJscR174650Library UP-TO-DATE
    :app:prepareDebugDependencies
    :app:compileDebugAidl UP-TO-DATE
    :app:compileDebugRenderscript UP-TO-DATE
    :app:generateDebugBuildConfig UP-TO-DATE
    :app:generateDebugAssets UP-TO-DATE
    :app:mergeDebugAssets UP-TO-DATE
    :app:generateDebugResValues UP-TO-DATE
    :app:generateDebugResources UP-TO-DATE
    :app:mergeDebugResources UP-TO-DATE
    :app:bundleDebugJsAndAssets SKIPPED
    :app:processDebugManifest UP-TO-DATE
    :app:processDebugResources UP-TO-DATE
    :app:generateDebugSources UP-TO-DATE
    :app:processDebugJavaRes UP-TO-DATE
    :app:compileDebugJavaWithJavac FAILED

    FAILURE: Build failed with an exception.

    * What went wrong:
    Execution failed for task ':app:compileDebugJavaWithJavac'.
    > Could not find tools.jar

Running echo $JAVA_HOME gives /usr/lib/jvm/java-8-openjdk-amd64

Upvotes: 28

Views: 22050

Answers (6)

jovani
jovani

Reputation: 849

got this error after knowing i only installed the openjdk-8-jre-headless instead of openjdk-8-jdk-headless. note the subtle difference between jre vs jdk

Upvotes: 2

solomon njobvu
solomon njobvu

Reputation: 589

Faced the same problem as well..... after installing openjdk using the synaptic package

npx react-native run-android

couldn't able to install the app in the device bring the same. Not until i installed openjdk-8-jdk in terminal like this...

sudo apt-get install openjdk-8-jdk

Upvotes: 2

sanister
sanister

Reputation: 430

In Ubuntu

sudo apt-get install openjdk-8-jdk-headless

Upvotes: 13

S. Pan
S. Pan

Reputation: 629

If you came here from google and you are developing on RHEL you need

sudo yum install java-1.8.0-openjdk-javadoc

and

sudo yum install java-1.8.0-openjdk-devel

Upvotes: 3

Daniel Mooney
Daniel Mooney

Reputation: 171

The culprit!

Check to make sure the Java compiler is available. I don't normally develop in Java, so, while there's Java stuff running, I haven't ever specifically compiled a Java project. Run:

javac -version

If you get the same thing I received, well... you know the issue. I installed the latest Oracle JDK (shiver), and I have react-native up and running now. I ran into some other issues with environment variables, which were solved by:

unset $JAVA_HOME
source ~/.profile

Note: the .profile script had my SDK env vars in it.

Hope this helps!

Upvotes: 4

Karl Adler
Karl Adler

Reputation: 16836

Solved it by installing openjdk again:

sudo apt-get install openjdk-8-jdk

Upvotes: 94

Related Questions