Android Studio 电鳗:javaHome 似乎无效

Ama*_*man 11 android android-studio react-native

我正在开发一个 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
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

AVE*_*imi 19

对于Windows

问题是因为旧 Android Studio java 文件夹的痕迹,只需删除该文件夹即可开始工作:

C:\Program Files\Android\Android Studio\jre

新的 Android Studio Electric Eel 使用的是 jbr,而不是 jre。


对于macOS,如 @Jayanth 上面回复的:如果您使用的是 macOS,请替换 .bash_profile 或 .zshrc 中的路径

export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/Contents/Home"
Run Code Online (Sandbox Code Playgroud)

export JAVA_HOME="/Applications/Android Studio.app/Contents/jbr/Contents/Home"
Run Code Online (Sandbox Code Playgroud)


Alp*_*a 1 8

更新 android studio 后,我的 Kotlin Android 项目也遇到了同样的问题。这似乎是一个错误。以下步骤对我有用:

  1. 更新JAVA_HOMEC:\Program Files\Android\Android Studio\jbr

  2. 打开文件资源管理器并导航到C:\Program Files\Android\Android Studio\jbr并复制所有内容并将其粘贴到C:\Program Files\Android\Android Studio\jre

  3. 重新启动您的电脑并尝试再次运行该项目。


Jay*_*nth 5

如果您使用 MAC,请替换 .bash_profile 或 .zshrc 中的路径

export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/Contents/Home"
Run Code Online (Sandbox Code Playgroud)

export JAVA_HOME="/Applications/Android Studio.app/Contents/jbr/Contents/Home"
Run Code Online (Sandbox Code Playgroud)