Kotlin could not find the require JDK tools in the Java installtion ‘/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home’ used by Gradle. Make sure is running on a JDK, not JRE.
最近在Android开发中使用gradle打包时遇到了上面的问题,排查很久,总算找到了原因:没有配置JAVA_HOME环境变量
首先先安装好jdk。
获取JAVA的安装路径:/usr/libexec/java_home -V
Matching Java Virtual Machines (2):
1.8.261.12 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
1.8.0_261 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home
mac下编辑profile:
vim ~/.bash_profile,如果找不到bash_profile文件,执行 touch .bash_profile
export ANDROID_HOME=/Users/didi/Library/Android/sdk
export PATH=
P
A
T
H
:
{PATH}:
PATH:{ANDROID_HOME}/tools
export PATH=
P
A
T
H
:
{PATH}:
PATH:{ANDROID_HOME}/platform-tools
export NDK_ROOT=
A
N
D
R
O
I
D
H
O
M
E
/
n
d
k
/
21.0.6113669
e
x
p
o
r
t
P
A
T
H
=
{ANDROID_HOME}/ndk/21.0.6113669 export PATH=
ANDROIDHOME/ndk/21.0.6113669exportPATH={PATH}😒{ANDROID_HOME}/cmake/3.10.2.4988404/bin
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home
export CLASSPAHT=.:
J
A
V
A
H
O
M
E
/
l
i
b
/
d
t
.
j
a
r
:
JAVA_HOME/lib/dt.jar:
JAVAHOME/lib/dt.jar:JAVA_HOME/lib/tools.jar
export PATH=
J
A
V
A
H
O
M
E
/
b
i
n
:
JAVA_HOME/bin:
JAVAHOME/bin:PATH:
HomeBrew
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles
export PATH="/usr/local/bin:
P
A
T
H
"
e
x
p
o
r
t
P
A
T
H
=
"
/
u
s
r
/
l
o
c
a
l
/
s
b
i
n
:
PATH" export PATH="/usr/local/sbin:
PATH"exportPATH="/usr/local/sbin:PATH"
HomeBrew END
注意:HomeBrew不是必须的。
编辑完成后,按esc退出插入模式,然后shift + :输入wq!退出编辑模式。
执行下面命令使之生效
source ~/.bash_profile
验证下:
输入 echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home