mindrunner / docker-android-sdk

GNU General Public License v3.0
277 stars 169 forks source link

Add linux/arm64 Support (Apple MacOS m1+) #83

Closed violen closed 1 year ago

violen commented 2 years ago

Hi if I get it correctly you are behind https://hub.docker.com/r/runmymind/docker-android-sdk?

Would be awesome if you support linux/arm64 architectures. The baseimages from alpine and ubuntu does support it.

So it should be possible or do you see any pitfalls here?

Where I am unsure about is if gitlab.com is supporting Dockers buildx.

mindrunner commented 2 years ago

We can have a look. Are you able to ARM build the Dockerfile on your macbook?

violen commented 2 years ago

Nope no luck out of the box.

I get the Error that bionic is not available but so far the ubuntu arm64 and amd64 images are loaded as expected.

=> ERROR [linux/arm64 2/7] RUN dpkg --add-architecture i386 && apt-get update -yqq && apt-get install -y   curl  42.0s
 => CANCELED [linux/amd64 2/7] RUN dpkg --add-architecture i386 && apt-get update -yqq && apt-get install -y   c  42.1s
------
 > [linux/arm64 2/7] RUN dpkg --add-architecture i386 && apt-get update -yqq && apt-get install -y   curl   expect   git   make   libc6:i386   libgcc1:i386   libncurses5:i386   libstdc++6:i386   zlib1g:i386   openjdk-11-jdk   wget   unzip   vim   openssh-client   locales   bsdtar   && apt-get clean   && rm -rf /var/lib/apt/lists/*   && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8:
#0 41.95 E: Failed to fetch http://ports.ubuntu.com/ubuntu-ports/dists/bionic/multiverse/binary-i386/Packages  404  Not Found [IP: 185.125.190.39 80]
#0 41.95 E: Failed to fetch http://ports.ubuntu.com/ubuntu-ports/dists/bionic-updates/universe/binary-i386/Packages  404  Not Found [IP: 185.125.190.36 80]
#0 41.95 E: Failed to fetch http://ports.ubuntu.com/ubuntu-ports/dists/bionic-backports/main/binary-i386/Packages  404  Not Found [IP: 185.125.190.36 80]
#0 41.95 E: Failed to fetch http://ports.ubuntu.com/ubuntu-ports/dists/bionic-security/universe/binary-i386/Packages  404  Not Found [IP: 185.125.190.36 80]
#0 41.95 E: Some index files failed to download. They have been ignored, or old ones used instead.
------
Dockerfile:15
--------------------
  14 |
  15 | >>> RUN dpkg --add-architecture i386 && apt-get update -yqq && apt-get install -y \
  16 | >>>   curl \
  17 | >>>   expect \
  18 | >>>   git \
  19 | >>>   make \
  20 | >>>   libc6:i386 \
  21 | >>>   libgcc1:i386 \
  22 | >>>   libncurses5:i386 \
  23 | >>>   libstdc++6:i386 \
  24 | >>>   zlib1g:i386 \
  25 | >>>   openjdk-11-jdk \
  26 | >>>   wget \
  27 | >>>   unzip \
  28 | >>>   vim \
  29 | >>>   openssh-client \
  30 | >>>   locales \
  31 | >>>   bsdtar \
  32 | >>>   && apt-get clean \
  33 | >>>   && rm -rf /var/lib/apt/lists/* \
  34 | >>>   && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
  35 |
--------------------
ERROR: failed to solve: process "/bin/sh -c dpkg --add-architecture i386 && apt-get update -yqq && apt-get install -y   curl   expect   git   make   libc6:i386   libgcc1:i386   libncurses5:i386   libstdc++6:i386   zlib1g:i386   openjdk-11-jdk   wget   unzip   vim   openssh-client   locales   bsdtar   && apt-get clean   && rm -rf /var/lib/apt/lists/*   && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8" did not complete successfully: exit code: 100

The Alpine standalone runs much further but fails with:

 => CANCELED [linux/amd64 2/7] RUN apk -U update && apk -U add   bash   libarchive-tools   ca-certificates   cu  161.4s
 => [linux/arm64 2/7] RUN apk -U update && apk -U add   bash   libarchive-tools   ca-certificates   curl   expe  159.5s
 => [linux/arm64 3/7] RUN mkdir -p /opt/android-sdk-linux   && addgroup android   && adduser android -D -G androi  0.3s
 => [linux/arm64 4/7] COPY tools /opt/tools                                                                        0.1s
 => [linux/arm64 5/7] COPY licenses /opt/licenses                                                                  0.1s
 => [linux/arm64 6/7] WORKDIR /opt/android-sdk-linux                                                               0.1s
 => ERROR [linux/arm64 7/7] RUN /opt/tools/entrypoint.sh built-in                                                  0.4s
------
 > [linux/arm64 7/7] RUN /opt/tools/entrypoint.sh built-in:
#0 0.309 _=/bin/printenv
#0 0.309 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
#0 0.309 ANDROID_SDK_ROOT=/opt/android-sdk-linux
#0 0.309 SHLVL=2
#0 0.309 GLIBC_VERSION=2.28-r0
#0 0.309 ANDROID_HOME=/opt/android-sdk-linux
#0 0.309 HOME=/root
#0 0.309 PWD=/opt/android-sdk-linux
#0 0.309 ANDROID_SDK_HOME=/opt/android-sdk-linux
#0 0.309 ANDROID_SDK=/opt/android-sdk-linux
#0 0.309 JAVA_HOME=/usr/lib/jvm/java-11-openjdk
#0 0.313 /sbin/su-exec
#0 0.327 su-exec: /opt/tools/android-sdk-update.sh: Permission denied
------
Dockerfile:54
--------------------
  52 |     WORKDIR /opt/android-sdk-linux
  53 |
  54 | >>> RUN /opt/tools/entrypoint.sh built-in
  55 |     CMD /opt/tools/entrypoint.sh built-in
  56 |
--------------------
ERROR: failed to solve: process "/bin/sh -c /opt/tools/entrypoint.sh built-in" did not complete successfully: exit code: 1

How has the permission have to look like for the scripts? My underlying system has a umask of 022 so those files are rwxr--r-- on the host system.

FYI: I used buildx with the ubuntu and alpine standalone Dockerfile

amd64 Windows and arm64 MacOS m1 were prepared with binfmt_misc modules via

WIndows (WSL2):

docker run --rm --privileged multiarch/qemu-user-static --reset -p yes

MacOS:

docker run --rm --privileged aptman/qus -- -r
docker run --rm --privileged aptman/qus -s -- -p

I then created a buildx builder via

docker buildx create --name multiarch-builder --use --bootstrap

And building via:

docker buildx build --platform linux/amd64,linux/arm64 -f ubuntu/standalone/Dockerfile -t runmymind/android-ubu-standalone .

Hope this helps and you can try this by yourself with buildx

mindrunner commented 2 years ago

Thanks for the insight! There seem to be some issues with buildx, as you can see here: https://github.com/docker/buildx/issues/495

I was able to cross-build build the ubuntu image on an amd64 host by following those instructions: https://github.com/docker/buildx/issues/495#issuecomment-761562905

The alpine image is somewhat unsupported. I think everything works except the emulator which needs some work due to missing glibc on Alpine.

How has the permission have to look like for the scripts?

You should not change the permissions of the files. Scripts need to be executable for non-owner. I never tested this on non-linux (ext4) filesystems. If you are using NTFS or macos filesystems for checking out the repository, your mileage might vary. Not sure why you end up with a different umask after cloning the repo.

Anyhow, I could try building the images on CI and you can check if they suit you. How's that sound to you?

Edit: There is one more issue. i386 multiarch is not available for arm i suppose, so the Dockerfiles would probably need some work.

mindrunner commented 1 year ago

I am closing this due to 1) OP not responding and 2) me not having hardware to proper fix this.

I need either a working PR, or someone who can provide me with a macbook or similar in order to find a proper solution.