我正在开发一个React Native - TypeScript移动的应用程序。我更新了Android Studio,这破坏了我的应用程序的构建。我花了几个小时,但我无法解决我一直得到的JAVA_HOME错误。需要帮助。
已安装的Android Studio:
Android Studio Electric Eel | 2022.1.1
Build #AI-221.6008.13.2211.9477386, built on January 11, 2023
Runtime version: 11.0.15+0-b2043.56-8887301 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 10 10.0
GC: G1 Young Generation, G1 Old Generation
Memory: 1280M
Cores: 8
Registry:
external.system.auto.import.disabled=true
ide.text.editor.with.preview.show.floating.toolbar=false
JAVA_HOME
设置为C:\Program Files\Java\jdk-19
。我可以更改为C:\Program Files\Android\Android Studio\jbr
,它具有\bin\java.exe
。
运行react-native run-android
时出错:
info Starting JS server...
info Installing the app...
FAILURE: Build failed with an exception.
* What went wrong:
The supplied javaHome seems to be invalid. I cannot find the java executable. Tried location: C:\Program Files\Android\Android Studio\jre\bin\java.exe
* 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
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
* What went wrong:
The supplied javaHome seems to be invalid. I cannot find the java executable. Tried location: C:\Program Files\Android\Android Studio\jre\bin\java.exe
* 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
2条答案
按热度按时间xienkqul1#
错误消息表明JAVA_HOME环境变量设置为无效位置,具体为“C:\Program Files\Android\Android Studio\jre\bin\java.exe”,该位置不包含Java可执行文件。
更新Android Studio后,JDK的位置似乎已更改。您可以尝试以下步骤来解决此问题:
另一个解决方案是检查您的Android Studio设置,并确保JDK位置在“外观和行为〉系统设置〉Android SDK”设置下正确。
还要确保在系统环境变量中设置了JAVA_HOME环境变量,而不仅仅是在用户变量中。
i5desfxk2#
在更新Android Studio后,我的KotlinAndroid项目也遇到了同样的问题。这似乎是一个bug。下面的步骤对我很有效:
1.将
JAVA_HOME
更新为C:\Program Files\Android\Android Studio\jbr
1.打开文件资源管理器并导航到
C:\Program Files\Android\Android Studio\jbr
,然后复制所有内容并粘贴到C:\Program Files\Android\Android Studio\jre
1.重新启动电脑并尝试再次运行该项目。