我关注了getting started guide Android / Linux。
我尝试使用react-native run-android
在ubuntu下启动本机反应,但它失败并显示错误:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Could not find tools.jar
我该如何解决?
完整输出:
$ 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
正在运行echo $JAVA_HOME
会产生/usr/lib/jvm/java-8-openjdk-amd64
答案 0 :(得分:44)
再次安装openjdk解决了这个问题:
sudo apt-get install openjdk-8-jdk
答案 1 :(得分:2)
检查以确保Java编译器可用。我通常不会用Java开发,所以,在运行Java的时候,我还没有专门编译过Java项目。运行:
javac -version
如果你得到我收到的同样的东西,那么......你知道这个问题。我安装了最新的Oracle JDK( shiver ),现在我已经做好了本地反应。我遇到了一些环境变量的问题,这些问题通过以下方式解决:
unset $JAVA_HOME
source ~/.profile
注意:.profile脚本中包含我的SDK env vars。
希望这有帮助!
答案 2 :(得分:2)
如果您是从谷歌来到这里并且您正在开发RHEL,则需要
sudo yum install java-1.8.0-openjdk-javadoc
和
sudo yum install java-1.8.0-openjdk-devel
答案 3 :(得分:1)
使用突触软件包安装openjdk之后也遇到了同样的问题。
npx react-native run-android
无法在设备中安装该应用程序。直到我在这样的终端中安装了openjdk-8-jdk ...
sudo apt-get install openjdk-8-jdk
答案 4 :(得分:1)
在知道我只安装了openjdk-8- jre -headless而不是openjdk-8- jdk -headless后,出现了此错误。请注意 jre 与 jdk
之间的细微差别答案 5 :(得分:0)
在Ubuntu中
sudo apt-get install openjdk-8-jdk-headless