gpt4 book ai didi

java - Flutter/Dart 找不到 java 和 $JAVA_HOME

转载 作者:行者123 更新时间:2023-12-03 03:19:41 25 4
gpt4 key购买 nike

我正在关注 official tutorial on flutter.dev但是在 IntelliJ IDEA 中单击“运行”时出现以下错误:

Launching lib/main.dart on sdk gphone x86 arm in debug mode...
Running Gradle task 'assembleDebug'...

ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

Exception: Gradle task assembleDebug failed with exit code 1

如果我运行 flutter doctor -v,您可以看到它已安装:

$ flutter doctor -v
[✓] Flutter (Channel stable, 1.22.1, on Linux, locale en_US.UTF-8)
• Flutter version 1.22.1 at /home/forest/snap/flutter/common/flutter
• Framework revision f30b7f4db9 (11 days ago), 2020-10-08 10:06:30 -0700
• Engine revision 75bef9f6c8
• Dart version 2.10.1


[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at /home/forest/Android/Sdk
• Platform android-30, build-tools 30.0.2
• ANDROID_HOME = /home/forest/Android/Sdk
• Java binary at: /home/forest/.jdks/jdk1.8.0_261/bin/java
• Java version Java(TM) SE Runtime Environment (build 1.8.0_261-b12)
• All Android licenses accepted.

[!] Android Studio (not installed)
• Android Studio not found; download from https://developer.android.com/studio/index.html
(or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).

(虽然我已经从 IDEA 工具箱安装了 android studio。)

我可以从 shell 运行这两个命令:

forest@forest-PC:~$ echo $JAVA_HOME
/home/forest/.jdks/jdk1.8.0_261
forest@forest-PC:~$ java -version
java version "1.8.0_261"
Java(TM) SE Runtime Environment (build 1.8.0_261-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.261-b12, mixed mode)
forest@forest-PC:~$

它也在配置文件中:

$ cat /etc/profile
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

if [ "${PS1-}" ]; then
if [ "${BASH-}" ] && [ "$BASH" != "/bin/sh" ]; then
# The file bash.bashrc already sets the default PS1.
# PS1='\h:\w\$ '
if [ -f /etc/bash.bashrc ]; then
. /etc/bash.bashrc
fi
else
if [ "`id -u`" -eq 0 ]; then
PS1='# '
else
PS1='$ '
fi
fi
fi

if [ -d /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if [ -r $i ]; then
. $i
fi
done
unset i
fi

export JAVA_HOME="/home/forest/.jdks/jdk1.8.0_261"
export PATH=$JAVA_HOME/bin:$PATH

在 IntelliJ IDEA 中,它还设置了: enter image description here enter image description here

对于 Android Studio,存在完全相同的问题。

IntelliJ 控制台 env 也设置了 $JAVA_HOME。

forest@forest-PC:~/projects/fluttertanulas/myapp$ echo $JAVA_HOME
/home/forest/.jdks/jdk1.8.0_261
forest@forest-PC:~/projects/fluttertanulas/myapp$ echo $PATH
/home/forest/.jdks/jdk1.8.0_261/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/forest/Android/Sdk/tools:/home/forest/Android/Sdk/platform-tools
forest@forest-PC:~/projects/fluttertanulas/myapp$
forest@forest-PC:~/projects/fluttertanulas/myapp$ java -version
java version "1.8.0_261"
Java(TM) SE Runtime Environment (build 1.8.0_261-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.261-b12, mixed mode)

最佳答案

因为我刚刚安装了所有东西,从 javaandroidflutterdart 等等,我只是设置我的 .bashrc/etc/profile,我只需要在系统上重新启动即可使其正常工作。可能与 IDEA 如何获取 env 变量有关。

关于java - Flutter/Dart 找不到 java 和 $JAVA_HOME,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64424071/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com