chenxiaolong / DualBootPatcher

Patches Android ROMs for dual boot support
https://dbp.noobdev.io
Other
527 stars 466 forks source link

Docker build error: JAVA_HOME is not set and no 'java' command could be found in your PATH. #1370

Closed klorinczi closed 5 years ago

klorinczi commented 5 years ago

I executed:

git pull
# Already up-to-date.
git status
# On branch master
# Your branch is up-to-date with 'origin/master'.
# nothing to commit, working directory clean
./docker/generate.sh
./docker/build.sh

However I get the following error at the end of build:

Step 6/8 : RUN dnf -y install java-1.8.0-openjdk-devel glibc.i686 libstdc++.i686     && dnf clean all
 ---> Using cache
 ---> 9529e6c27ac6
Step 7/8 : ENV PATH ${PATH}:${ANDROID_NDK_HOME}:${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin:${ANDROID_HOME}/platform-tools
 ---> Using cache
 ---> 580933923ed9
Step 8/8 : RUN yes | sdkmanager     'build-tools;28.0.3'     'extras;android;m2repository'     'extras;google;m2repository'     'platforms;android-28'     'platform-tools'     'tools'
 ---> Running in 43ff03ed5480

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.

Removing intermediate container 43ff03ed5480
The command '/bin/sh -c yes | sdkmanager     'build-tools;28.0.3'     'extras;android;m2repository'     'extras;google;m2repository'     'platforms;android-28'     'platform-tools'     'tools'' returned a non-zero code: 1
chenxiaolong commented 5 years ago
Step 6/8 : RUN dnf -y install java-1.8.0-openjdk-devel glibc.i686 libstdc++.i686     && dnf clean all
 ---> Using cache
 ---> 9529e6c27ac6

Hmm, I wonder if something was cached from an earlier build of the docker images. Can you try running docker image prune -a to clear previously built images? (Note that this will delete other docker images you might have in docker images)

klorinczi commented 5 years ago

I pruned the images, but I got the same error:

...
Installed:
  glibc-2.28-26.fc29.i686
  java-1.8.0-openjdk-devel-1:1.8.0.191.b13-0.fc29.x86_64
  libstdc++-8.2.1-6.fc29.i686
  gtk2-2.24.32-3.fc29.x86_64
  java-1.8.0-openjdk-1:1.8.0.191.b13-0.fc29.x86_64
  jbigkit-libs-2.1-15.fc29.x86_64
  libgcc-8.2.1-6.fc29.i686
  libtiff-4.0.10-1.fc29.x86_64
  shared-mime-info-1.12-1.fc29.x86_64
  atk-2.30.0-1.fc29.x86_64
  gdk-pixbuf2-2.38.0-4.fc29.x86_64
  gdk-pixbuf2-modules-2.38.0-4.fc29.x86_64
  giflib-5.1.4-2.fc29.x86_64
  gtk-update-icon-cache-3.24.1-1.fc29.x86_64
  hicolor-icon-theme-0.17-3.fc29.noarch
  jasper-libs-2.0.14-7.fc29.x86_64
  libXcomposite-0.4.4-15.fc29.x86_64
  libXcursor-1.1.15-4.fc29.x86_64
  libXinerama-1.1.4-2.fc29.x86_64
  libXrandr-1.5.1-8.fc29.x86_64
  libfontenc-1.1.3-9.fc29.x86_64
  ttmkfdir-3.0.9-55.fc29.x86_64
  xorg-x11-font-utils-1:7.5-40.fc29.x86_64
  xorg-x11-fonts-Type1-7.5-20.fc29.noarch

Complete!
33 files removed
Removing intermediate container 48eb2593187e
 ---> 051d61aaccb2
Step 7/8 : ENV PATH ${PATH}:${ANDROID_NDK_HOME}:${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin:${ANDROID_HOME}/platform-tools
 ---> Running in 44d2babeca6d
Removing intermediate container 44d2babeca6d
 ---> 5667805dbf59
Step 8/8 : RUN yes | sdkmanager     'build-tools;28.0.3'     'extras;android;m2repository'     'extras;google;m2repository'     'platforms;android-28'     'platform-tools'     'tools'
 ---> Running in f398dcdfc51e

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.

Removing intermediate container f398dcdfc51e
The command '/bin/sh -c yes | sdkmanager     'build-tools;28.0.3'     'extras;android;m2repository'     'extras;google;m2repository'     'platforms;android-28'     'platform-tools'     'tools'' returned a non-zero code: 1

I added the following code to "./docker/template/Dockerfile.android.in" file to fix this, then built successfully:

# Set up JAVA_HOME
ENV JAVA_HOME /usr/lib/jvm/java
ENV PATH $JAVA_HOME/bin:$PATH

# added before following line
# Set up path

Then executed the following commands in terminal:

git pull
# Already up-to-date.

git status
# On branch master
# Your branch is up-to-date with 'origin/master'.
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
# 
#         modified:   docker/template/Dockerfile.android.in
# 
# no changes added to commit (use "git add" and/or "git commit -a")

git diff
# diff --git a/docker/template/Dockerfile.android.in b/docker/template/Dockerfile.android.in
# index 5e0c87a..881cad9 100644
# --- a/docker/template/Dockerfile.android.in
# +++ b/docker/template/Dockerfile.android.in
# @@ -34,6 +34,10 @@ RUN mkdir ${ANDROID_HOME} \
#  RUN dnf -y install java-1.8.0-openjdk-devel glibc.i686 libstdc++.i686 \
#      && dnf clean all
# 
# +# Set up JAVA_HOME
# +ENV JAVA_HOME /usr/lib/jvm/java
# +ENV PATH $JAVA_HOME/bin:$PATH
# +
#  # Set up path
#  ENV PATH  ${PATH}:${ANDROID_NDK_HOME}:${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin:${ANDROID_HOME}/platform-tools

./docker/generate.sh

./docker/build.sh
klorinczi commented 5 years ago

I got the following error now:

Installing weak dependencies:
 mesa-dri-drivers          x86_64      18.2.8-1.fc29         updates       13 M

Transaction Summary
================================================================================
Install  44 Packages

Total download size: 44 M
Installed size: 160 M
Downloading Packages:

The downloaded packages were saved in cache until the next successful transaction.
You can remove cached packages by executing 'dnf clean packages'.
Error: Error downloading packages:
  Status code: 503 for https://mirrors.fedoraproject.org/metalink?repo=fedora-29&arch=x86_64
Removing intermediate container 4d9e230e34b4
The command '/bin/sh -c dnf -y install         libarchive-devel         lz4-devel         gtest-devel         qt5-qtbase-devel         xz-devel     && dnf clean all' returned a non-zero code: 1

Executing again the

./docker/build.sh

fixed the problem:

Complete!
33 files removed
Removing intermediate container 055d380d8e39
 ---> d97c8c5b34e4
Successfully built d97c8c5b34e4
Successfully tagged chenxiaolong/dualbootpatcher:9.3.0-12-linux
chenxiaolong commented 5 years ago

I think I know why. Inside the docker image, /opt/android-sdk/tools/bin/sdkmanager uses the following code to find where java is installed:

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

If JAVA_HOME is unset, then it uses which java and which isn't installed:

[builder@27ff50a73901 ~]$ which
bash: which: command not found
[builder@27ff50a73901 ~]$

I'll update the Dockerfile to install which.

klorinczi commented 5 years ago

I used these lines to find the correct path:

RUN whereis java
RUN find /usr/lib/jvm/java*