Ionic Build 在 JAVA_HOME 中找不到 JDK 集,即使它是唯一的 Java 安装

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30497071/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 17:13:41  来源:igfitidea点击:

Ionic Build can't find JDK set in JAVA_HOME even though it is the only Java install

javaandroidcordovaionic-framework

提问by mtpultz

When I installed Java JDK 1.8.x it initially was working, when I rebooted the next day after shutting down over night I get this when I build:

当我安装 Java JDK 1.8.x 时,它最初可以正常工作,当我隔夜关闭后第二天重新启动时,我在构建时得到了这个:

$ ionic build android
Updated the hooks directory to have execute permissions
Running command: d:\installs\nodejs\node.exe d:\htdocs\publicworks\mobile\hooks\after_prepare0_add_platform_class.js d:/htdocs/publicworks/mobile
add to body class: platform-android
Running command: d:\htdocs\publicworks\mobile\platforms\android\cordova\build.bat
ANDROID_HOME=c:\Users\mtpultz\AppData\Local\Android\android-sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_45\bin
Running: d:\htdocs\publicworks\mobile\platforms\android\gradlew cdvBuildDebug -b d:\htdocs\publicworks\mobile\platforms\android\build.gradle -Dorg.gradle.daemon=true

ERROR: JAVA_HOME is set to an invalid directory: C:\Program Files\Java\jdk1.8.0_45\bin

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

d:\htdocs\publicworks\mobile\platforms\android\cordova\node_modules\q\q.js:126
                    throw e;
                          ^
Error code 1 for command: cmd with args: /s /c "d:\htdocs\publicworks\mobile\platforms\android\gradlew cdvBuildDebug -b d:\htdocs\publicworks\mobile\platforms\android\build.gradle -Dorg.gradle.daemon=true"

But Java is most definitely installed in this directory and nowhere else??? In my terminal:

但是Java绝对安装在这个目录中而不是其他地方???在我的终端中:

java -version

Produces the proper output for my JDK:

为我的 JDK 生成正确的输出:

java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

The environment variables are set to:

环境变量设置为:

JAVA_HOME =

JAVA_HOME =

C:\Program Files\Java\jdk1.8.0_45\bin

and the path contains:

并且路径包含:

D:\installs\nodejs;
C:\Users\mtpultz\AppData\Roaming\npm;
D:\installs\apache-ant\bin;
C:\Users\mtpultz\AppData\Local\Android\android-sdk\tools;
C:\Users\mtpultz\AppData\Local\Android\android-sdk\platform-tools;

Any suggestions?

有什么建议?

回答by Juned Ahsan

JAVA_HOMEshould be set to the home directory of java and not to bin. So replace this:

JAVA_HOME应该设置为java的主目录而不是bin。所以替换这个:

C:\Program Files\Java\jdk1.8.0_45\bin

with

C:\Program Files\Java\jdk1.8.0_45

java/bindir is added to PATHsystem variable to run java from anywhere.

java/bindir 被添加到PATH系统变量以从任何地方运行 java。

回答by Rishi Paul

Do one thing. This will Help You

做一件事。这会帮助你

Remove "\bin" from your JAVA_HOME path. Mean give path only till.

从您的 JAVA_HOME 路径中删除“\bin”。意思是只给路径直到。

C:\Program Files\Java\jdk1.8.0_45

It will work with you.

它会和你一起工作。

回答by pruthwiraj.kadam

For Linux user:

对于 Linux 用户:



$sudo gedit $HOME/.bashrc

$sudo gedit $HOME/.bashrc

write at end

写在最后

#Android Path
export ANDROID_HOME=${HOME}/Android/Sdk
export PATH=${PATH}:${ANDROID_HOME}/platform-tools:${ANDROID_HOME}/tools
export PATH
#JAVA
export JAVA_HOME=/usr/lib/jvm/java-8-oracle/
export JAVA_HOME


$source ~/.bashrc

$source ~/.bashrc

after that open

打开之后



$sudo gedit /etc/environment

$sudo gedit /etc/environment

and add at end

并在最后添加

JAVA_HOME="/usr/lib/jvm/java-8-oracle/"


$source /etc/environment

$source /etc/environment

回答by Akash Kumar

after wasting 3 days finally i got some solutions. these are definitely works when you found these errors.

浪费了 3 天后,我终于找到了一些解决方案。当您发现这些错误时,这些绝对有效。

1.Error: JAVA_HOME is set to an invalid directory

1.错误:JAVA_HOME设置为无效目录

JAVA_HOME should be set to the home directory of java and not to bin. So replace this:

JAVA_HOME 应该设置为 java 的主目录,而不是 bin。所以替换这个:

C:\Program Files\Java\jdk1.8.0_45\bin with

C:\Program Files\Java\jdk1.8.0_45\bin 与

C:\Program Files\Java\jdk1.8.0_45 java/bin dir is added to PATH system variable to run java from anywhere

C:\Program Files\Java\jdk1.8.0_45 java/bin 目录被添加到PATH系统变量中以从任何地方运行java

  1. Failed to install 'cordova-plugin-whitelist': Error using forcedroid command line
  1. 无法安装“cordova-plugin-whitelist”:使用forcedroid命令行时出错

check your environments variables 1. android platforms tools 2. android tools 3. sdk location 4. git location

检查您的环境变量 1. android 平台工具 2. android 工具 3. sdk 位置 4. git 位置

  1. cordova - Error: Failed to fetch platform android
  1. cordova - 错误:无法获取平台 android

the only solution is

唯一的解决办法是

cordova platform add android --nofetch

科尔多瓦平台添加 android --nofetch

回答by Vaibhav B

Make sure that your JAVA_HOMEis having the following path and install JDK SE.

确保您的JAVA_HOME具有以下路径并安装 JDK SE。

C:\Program Files\Java\jdk1.8.0_131

C:\Program Files\Java\jdk1.8.0_131

回答by Chepaki

Make sure you use the Java SE SDK and not the Java EE SDK, that solved the problem for me.

确保您使用的是 Java SE SDK 而不是 Java EE SDK,它为我解决了这个问题。