Update:
I tried removing every trace of java openjdk, installing Oracle Java 8, and setting up my environment variables again but still no bueno. So after I did source ~/.bashrc
I closed all terminals, logged out, and viola, all fixed. What a hassle though.
OP:
I came across this SO question that seems to deal with the same issue I am having. Unfortunately, I didn't have the line export JAVA_HOME=/usr/lib/jvm/default-java
in my usr/bin/gradle
file.
My error says JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/jre
But echo $JAVA_HOME
returns /usr/lib/jvm/java-8-openjdk-amd64/jre
I tried creating a symlink between the real JAVA_HOME and the one gradle keeps trying to use but the one gradle is trying to use isn't real so I get the error ln: failed to create symbolic link '/usr/lib/jvm/java-7-openjdk-amd64/jre': No such file or directory
I tried digging around the gradlew file and found what I think may be the offending code but I'm not 100% sure how it works and any time I edit the file and then execute cordova run android
all my changes are wiped away.
This is the bit of code I found in gradlew:
# 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
My full error report:
Running command: /home/grant/Development/Projects/ACA/hooks/after_prepare/icons_and_splashscreens.js /home/grant/Development/Projects/ACA
Running command: /home/grant/Development/Projects/ACA/hooks/after_prepare/update_platform_config.js /home/grant/Development/Projects/ACA
ANDROID_HOME=/home/grant/Development/Android
JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/jre
No target specified, deploying to device '05157df5a3d39408'.
ERROR: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java-7-openjdk-amd64/jre
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
ERROR running one or more of the platforms: Error code 1 for command: /home/grant/Development/Projects/ACA/platforms/android/gradlew with args: cdvBuildDebug,-b,/home/grant/Development/Projects/ACA/platforms/android/build.gradle,-PcdvBuildArch=arm,-Dorg.gradle.daemon=true,-Pandroid.useDeprecatedNdk=true
You may not have the required environment or OS to run this project