react-native-community / docker-android

Android Docker Image for React Native and common android development.
MIT License
476 stars 144 forks source link

Support arm64 Architecture #166

Open Legion2 opened 2 years ago

Legion2 commented 2 years ago

Please publish an arm64 compatible image to dockerhub.

kaloudis commented 2 years ago

Yes, please. Performance via emulation on M1 is terrible.

kaelite commented 2 years ago

Yes, please!

Legion2 commented 2 years ago

Here is my try on creating a new docker image based on ubuntu:

FROM ubuntu:20.04

ENV DEBIAN_FRONTEND=noninteractive

# set default build arguments
ARG SDK_VERSION=commandlinetools-linux-8092744_latest.zip
ARG ANDROID_BUILD_VERSION=31
ARG ANDROID_TOOLS_VERSION=31.0.0
ARG NDK_VERSION=21.4.7075529
ARG NODE_VERSION=16.x
ARG WATCHMAN_VERSION=4.9.0
ARG CMAKE_VERSION=3.18.1
ARG AVD_PACKAGE=system-images;android-30;google_apis;x86_64

# set default environment variables, please don't remove old env for compatibilty issue
ENV ADB_INSTALL_TIMEOUT=10
ENV ANDROID_HOME=/opt/android
ENV ANDROID_SDK_HOME=
ENV ANDROID_SDK_ROOT=${ANDROID_HOME}
ENV ANDROID_NDK=${ANDROID_HOME}/ndk/$NDK_VERSION
ENV AVD_PACKAGE=${AVD_PACKAGE}
ENV JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
ENV CMAKE_BIN_PATH=${ANDROID_HOME}/cmake/$CMAKE_VERSION/bin

ENV PATH=${ANDROID_NDK}:${CMAKE_BIN_PATH}:${ANDROID_HOME}/cmdline-tools/latest/bin:${ANDROID_HOME}/emulator:${ANDROID_HOME}/platform-tools:${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin:${PATH}

# Install system dependencies
RUN apt update -qq && apt install -qq -y --no-install-recommends \
        apt-transport-https \
        curl \
        file \
        gcc \
        git \
        g++ \
        gnupg2 \
        libc++1-10 \
        libgl1 \
        libtcmalloc-minimal4 \
        make \
        openjdk-11-jdk-headless \
        openssh-client \
        patch \
        python3 \
        python3-distutils \
        rsync \
        ruby \
        ruby-dev \
        tzdata \
        unzip \
        sudo \
        ninja-build \
        zip \
        # Dev libraries requested by Hermes
        libicu-dev \
        # Emulator & video bridge dependencies
        libc6 \
        libdbus-1-3 \
        libfontconfig1 \
        libgcc1 \
        libpulse0 \
        libtinfo5 \
        libx11-6 \
        libxcb1 \
        libxdamage1 \
        libnss3 \
        libxcomposite1 \
        libxcursor1 \
        libxi6 \
        libxext6 \
        libxfixes3 \
        zlib1g \
        libgl1 \
        pulseaudio \
        socat \
    && gem install bundler \
    && rm -rf /var/lib/apt/lists/*;

# fix java home env var
RUN ln -s $(dirname -- $(dirname -- $(readlink -f /usr/bin/java))) /usr/lib/jvm/default-java
ENV JAVA_HOME=/usr/lib/jvm/default-java

# install nodejs and yarn packages from nodesource
RUN curl -sL https://deb.nodesource.com/setup_${NODE_VERSION} | bash - \
    && apt-get update -qq \
    && apt-get install -qq -y --no-install-recommends nodejs \
    && npm i -g yarn \
    && rm -rf /var/lib/apt/lists/*

# Full reference at https://dl.google.com/android/repository/repository2-1.xml
# download and unpack android
# workaround buck clang version detection by symlinking
RUN curl -sS https://dl.google.com/android/repository/${SDK_VERSION} -o /tmp/sdk.zip \
    && mkdir -p ${ANDROID_HOME}/cmdline-tools \
    && unzip -q -d ${ANDROID_HOME}/cmdline-tools /tmp/sdk.zip \
    && mv ${ANDROID_HOME}/cmdline-tools/cmdline-tools ${ANDROID_HOME}/cmdline-tools/latest \
    && rm /tmp/sdk.zip \
    && yes | sdkmanager --licenses > /dev/null \
    && yes | sdkmanager "platform-tools" \
        "emulator" \
        "platforms;android-$ANDROID_BUILD_VERSION" \
        "build-tools;$ANDROID_TOOLS_VERSION" \
        "cmake;$CMAKE_VERSION" \
        "$AVD_PACKAGE" \
        "ndk;$NDK_VERSION" \
    && rm -rf ${ANDROID_HOME}/.android \
    && ln -s ${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.9 ${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.8

However the problem is, that the Android AVD emulator is not available for arm64 architecture and fails to install

cortinico commented 2 years ago

that the Android AVD emulator is not available for arm64 architecture and fails to install

What's the failure message?

Legion2 commented 2 years ago

I do not remember what the exact failure was, but I know it was some android tooling which did not work on arm64 and there were no workarounds, so I stopped working on it.

Legion2 commented 2 years ago

@cortinico I searched my google history and found Warning: Failed to find package 'emulator' arm64 which should be the error I had back in march. It seems there are now workarounds for the problem https://stackoverflow.com/questions/71545278/install-build-tools-on-arm64-doesnt-work, if somebody wants to give it a shot.

EyMaddis commented 1 year ago

Did somebody achieve this?

cortinico commented 1 year ago

This is still unsolved upstream. Please go and star this issue on Google Issues' Tracker: https://issuetracker.google.com/issues/225541805

hamzafer commented 1 year ago

Any updates on this?

Alaa-Ben commented 1 year ago

I'm interested in news about this too :D

dgrezza commented 1 year ago

any update guys ? seem it will be helpful to speedup the build time