ERROR: is set to an invalid dir

2021-12-09  本文已影响0人  逆水寒Stephen

今天一个项目里面执行“./gradlew assembleRelease --stacktrace --info”命令打包,结果报错:

ERROR:  is set to an invalid directory: $

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

也是郁闷至极,看报错是说我JAVA_HOME环境变量的问题,但是我各种java,javac执行都ok,检查了环境变量配置处/etc/profile,~/.bashrc都是ok的,也没有重复配置JAVA_HOME变量,这就神奇了,根据网上文章:https://blog.csdn.net/weixin_42365334/article/details/114078331 也是无用,在StackOverflow上找到句命令可查看自己的javahome路径:

java -XshowSettings:properties -version 2>&1 > /dev/null | grep 'java.home'

如果设置了会输出:java.home = /home/xxxxxxxxx/jre
这些我都是ok的,后来发现另外个项目可以执行gradlew命令,我觉得既然环境变量没问题,那就是项目本身的问题了,最大的问题肯定出在gradlew命令上来,果然翻开项目下的gradlew脚本文件两个项目对比,搜索报错文字“your Java installation”,发现

能跑脚本的为:

# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
        # IBM's JDK on AIX uses strange locations for the executables
        JAVACMD="$JAVA_HOME/jre/sh/java"
    else
        JAVACMD="$JAVA_HOME/bin/java"
    fi
    if [ ! -x "$JAVACMD" ] ; then
        die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
    fi
else
    JAVACMD="java"
    which java >/dev/null 2>&1 || die "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."
fi

不能跑的脚本为:

# Determine the Java command to use to start the JVM.
if [ -n "$" ] ; then
    if [ -x "$/jre/sh/java" ] ; then
        # IBM's JDK on AIX uses strange locations for the executables
        JAVACMD="$/jre/sh/java"
    else
        JAVACMD="$/bin/java"
    fi
    if [ ! -x "$JAVACMD" ] ; then
        die "ERROR:  is set to an invalid directory: $

Please set the  variable in your environment to match the
location of your Java installation."
    fi
else
    JAVACMD="java"
    which java >/dev/null 2>&1 || die "ERROR:  is not set and no 'java' command could be found in your PATH.

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

差异就出在$JAVA_HOME这个变量上,解决办法就是直接将可以的这段脚本替换掉不可以的脚本即可,顺利打包,猜测是因为我们把gradle升级到7.0以上变化导致的

上一篇下一篇

猜你喜欢

热点阅读