[英]Execution failed for task ':app:compileDebugJavaWithJavac' react native
I am trying to run react native app on my android device like this in cmd我正在尝试在我的 android 设备上像这样在 cmd 中运行本机应用程序
cd C:\Users\User\Desktop\js
react-native run-android
FAILURE: Build failed with an exception.
FAILURE:构建失败,出现异常。
What went wrong: Execution failed for task ':app:compileDebugJavaWithJavac'.
出了什么问题:任务 ':app:compileDebugJavaWithJavac' 执行失败。
Could not find tools.jar
找不到 tools.jar
Try: Run with --stacktrace option to get the stack trace.
尝试:使用 --stacktrace 选项运行以获取堆栈跟踪。 Run with --info or --debug option to get more log output.
使用 --info 或 --debug 选项运行以获得更多日志输出。
BUILD FAILED
构建失败
Total time: 5.243 secs Could not install the app on the device, read the error above for details.
总时间:5.243 秒 无法在设备上安装应用程序,请阅读上面的错误了解详情。 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
确保您有一个正在运行的 Android 模拟器或已连接的设备并已设置您的 Android 开发环境:https ://facebook.github.io/react-native/docs/android-setup.html
Can anyone please tell me how to fix this problem?谁能告诉我如何解决这个问题?
Use the following step once, it may help you:使用以下步骤一次,它可能会对您有所帮助:
step 1: open cmd through administrator第一步:通过管理员打开cmd
step 2: navigate to your application by cd <path to your project>
第 2 步:通过
cd <path to your project>
导航到您的应用程序
step 3: run this command: ./gradlew clean
第 3 步:运行此命令:
./gradlew clean
step 4: react-native run-android第 4 步: react-native run-android
Have you installed JDK and Android SDK properly?您是否正确安装了 JDK 和 Android SDK? Are the
JAVA_HOME
and ANDROID_HOME
properly placed in your environment variables? JAVA_HOME
和ANDROID_HOME
是否正确放置在您的环境变量中?
I faced this issue while working on react-native project on Linux.我在 Linux 上进行 react-native 项目时遇到了这个问题。 In my case issue occured because I linked some external plugin and then removed it without unlink.
在我的情况下,出现问题是因为我链接了一些外部插件,然后在没有取消链接的情况下将其删除。 In that case you can attentively read your console error message.
在这种情况下,您可以仔细阅读控制台错误消息。 It should point to place that source an error.
它应该指出该来源是一个错误。
try this:试试这个:
If you are working with react native, just make sure you set up environment variables correctly for java compiler.如果您正在使用 react native,只需确保为 java 编译器正确设置环境变量。 after this goto package.json file in your project:
在项目中的 goto package.json 文件之后:
change this:改变这个:
"react-native": " https://github.com/expo/react-native/archive/sdk-31.0.0.tar.gz ", "react-native": " https://github.com/expo/react-native/archive/sdk-31.0.0.tar.gz ",
to: "react-native": "0.57.5",到:“反应原生”:“0.57.5”,
save and run npm install保存并运行 npm install
this works for me.这对我有用。
source: https://github.com/facebook/react-native/issues/21722来源: https : //github.com/facebook/react-native/issues/21722
thanks and happy coding!!感谢和快乐编码!!
The solution if ur version of react-native >= 0.61.0.如果您的 react-native >= 0.61.0 版本,则解决方案。 It shows error as when we add any plugin and use link command then it makes changes in android and ios folder.
它显示错误,因为当我们添加任何插件并使用链接命令时,它会在 android 和 ios 文件夹中进行更改。 But when we remove plugin, it gets removed from package.json but inside android changes are not reverted and it gives error.
但是当我们删除插件时,它会从 package.json 中删除,但在 android 内部的更改不会恢复,并且会出错。 So use below command to generate android folder again.
所以使用下面的命令再次生成android文件夹。 I hope it will solve the error-
我希望它会解决错误-
sudo rm -rf android/ ios/
yarn add react-native-eject
npx react-native eject
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.