3

Im trying do build an android app made with ionic angular inside a docker image built and im getting the following error The image is build correctly however when i try to run the command

./gradlew bundle

i get the bellow error

BUILD FAILED in 6s
38 actionable tasks: 1 executed, 37 up-to-date
root@docker-desktop:/app/android# ./gradlew bundle --no-daemon
To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon: https://docs.gradle.org/6.7.1/userguide/gradle_daemon.html.
Daemon will be stopped at the end of the build stopping after processing

> Configure project :app
google-services.json not found, google-services plugin not applied. Push Notifications won't work
WARNING:: Using flatDirs should be avoided because it doesn't support any meta-data formats.
Currently detected usages:
- repository flatDir used in: project ':app', project ':capacitor-cordova-android-plugins'
WARNING:: Please remove usages of `jcenter()` Maven repository from your build scripts and migrate your build to other Maven repositories.
This repository is deprecated and it will be shut down in the future.
See http://developer.android.com/r/tools/jcenter-end-of-service for more information.
Currently detected usages in: root project 'android', project ':app', project ':capacitor-android', ...
AAPT2 aapt2-4.2.1-7147631-linux Daemon #0: Unexpected error output: qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory
AAPT2 aapt2-4.2.1-7147631-linux Daemon #1: Unexpected error output: qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory

> Task :app:bundleDebugResources FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:bundleDebugResources'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Failed to transform appcompat-1.3.0.aar (androidx.appcompat:appcompat:1.3.0) to match attributes {artifactType=android-compiled-dependencies-resources, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-runtime}.
      > Execution failed for AarResourcesCompilerTransform: /root/.gradle/caches/transforms-2/files-2.1/cbe7026f0b6e48e8d36fabe06ed90cb5/appcompat-1.3.0.
         > AAPT2 aapt2-4.2.1-7147631-linux Daemon #1: Daemon startup failed
           This should not happen under normal circumstances, please file an issue if it does.
   > Failed to transform core-1.5.0.aar (androidx.core:core:1.5.0) to match attributes {artifactType=android-compiled-dependencies-resources, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-runtime}.
      > Execution failed for AarResourcesCompilerTransform: /root/.gradle/caches/transforms-2/files-2.1/916c05b3a76c5123063b127fcd657ead/core-1.5.0.
         > AAPT2 aapt2-4.2.1-7147631-linux Daemon #0: Daemon startup failed
           This should not happen under normal circumstances, please file an issue if it does.
   > Failed to transform core-1.5.0.aar (androidx.core:core:1.5.0) to match attributes {artifactType=android-compiled-dependencies-resources, org.gradle.status=release}.
      > Execution failed for AarResourcesCompilerTransform: /root/.gradle/caches/transforms-2/files-2.1/916c05b3a76c5123063b127fcd657ead/core-1.5.0.
         > AAPT2 aapt2-4.2.1-7147631-linux Daemon #0: Daemon startup failed
           This should not happen under normal circumstances, please file an issue if it does.
   > Failed to transform core-1.5.0.aar (androidx.core:core:1.5.0) to match attributes {artifactType=android-compiled-dependencies-resources, org.gradle.status=release}.
      > Execution failed for AarResourcesCompilerTransform: /root/.gradle/caches/transforms-2/files-2.1/916c05b3a76c5123063b127fcd657ead/core-1.5.0.
         > AAPT2 aapt2-4.2.1-7147631-linux Daemon #0: Daemon startup failed
           This should not happen under normal circumstances, please file an issue if it does.
   > Failed to transform core-1.5.0.aar (androidx.core:core:1.5.0) to match attributes {artifactType=android-compiled-dependencies-resources, org.gradle.status=release}.
      > Execution failed for AarResourcesCompilerTransform: /root/.gradle/caches/transforms-2/files-2.1/916c05b3a76c5123063b127fcd657ead/core-1.5.0.
         > AAPT2 aapt2-4.2.1-7147631-linux Daemon #0: Daemon startup failed
           This should not happen under normal circumstances, please file an issue if it does.
   > Failed to transform core-1.5.0.aar (androidx.core:core:1.5.0) to match attributes {artifactType=android-compiled-dependencies-resources, org.gradle.status=release}.
      > Execution failed for AarResourcesCompilerTransform: /root/.gradle/caches/transforms-2/files-2.1/916c05b3a76c5123063b127fcd657ead/core-1.5.0.
         > AAPT2 aapt2-4.2.1-7147631-linux Daemon #0: Daemon startup failed
           This should not happen under normal circumstances, please file an issue if it does.
   > Failed to transform core-1.5.0.aar (androidx.core:core:1.5.0) to match attributes {artifactType=android-compiled-dependencies-resources, org.gradle.status=release}.
      > Execution failed for AarResourcesCompilerTransform: /root/.gradle/caches/transforms-2/files-2.1/916c05b3a76c5123063b127fcd657ead/core-1.5.0.
         > AAPT2 aapt2-4.2.1-7147631-linux Daemon #0: Daemon startup failed
           This should not happen under normal circumstances, please file an issue if it does.
   > Failed to transform core-1.5.0.aar (androidx.core:core:1.5.0) to match attributes {artifactType=android-compiled-dependencies-resources, org.gradle.status=release}.
      > Execution failed for AarResourcesCompilerTransform: /root/.gradle/caches/transforms-2/files-2.1/916c05b3a76c5123063b127fcd657ead/core-1.5.0.
         > AAPT2 aapt2-4.2.1-7147631-linux Daemon #0: Daemon startup failed
           This should not happen under normal circumstances, please file an issue if it does.
enter code here

Docker image build

FROM adoptopenjdk/openjdk8

USER root
# Configure base folders.

# set default build arguments
ARG SDK_VERSION=platform-tools_r29.0.4-linux.zip
ARG ANDROID_BUILD_VERSION=29
ARG ANDROID_TOOLS_VERSION=29.0.2
ARG NDK_VERSION=20
ARG NODE_VERSION=14.x
ARG BUCK_VERSION=2019.10.17.01
ARG DEBIAN_FRONTEND=noninteractive

# Update the base image with the required components.
RUN mkdir -p /usr/share/man/man1 \
    && apt-get update -qq && apt-get install -qq -y --no-install-recommends \
    apt-transport-https \
    curl \
    nano \
    build-essential \
    file \
    wget \
    tar \
    zip \
    net-tools \
    # lib32stdc++6 \
    # lib32z1 \
    git \
    gnupg2 \
    python \
    openssh-client \
    gradle \
    unzip \
    optipng \
    imagemagick \
    python \
    # python2 \
    # python2.7 \
    # python-pip -y \
    && apt-get upgrade -y \
    && apt-get clean

RUN apt-get install openjdk-8-jdk openjdk-8-jre -y

# RUN dpkg --add-architecture i386
RUN apt-get update -qq
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y openjdk-8-jdk
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash
RUN apt-get install nodejs -y

# set default environment variables
ENV ADB_INSTALL_TIMEOUT=10
ENV ANDROID_SDK_VERSION 3859397
ENV ANDROID_HOME=/opt/android
ENV ANDROID_SDK_HOME=${ANDROID_HOME}
ENV ANDROID_NDK_HOME /opt/android-ndk

# ENV JAVA_HOME=/opt/java/openjdk
ENV PATH=$PATH:$ANDROID_HOME/tools
ENV PATH=$PATH:$ANDROID_HOME/platform-tools
ENV PATH ${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin:${ANDROID_HOME}/platform-tools
ENV PATH=$PATH:$ANDROID_SDK_HOME/tools
ENV PATH=$PATH:$ANDROID_SDK_HOME/platform-tools
ENV PATH ${PATH}:${ANDROID_SDK_HOME}/tools:${ANDROID_SDK_HOME}/tools/bin:${ANDROID_SDK_HOME}/platform-tools
ENV PATH=$PATH:$HOME/.npm-global/bin
ENV ANDROID_NDK_VERSION r20

RUN cd /opt \
    && wget -q https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip -O android-sdk-tools.zip \
    && unzip -q android-sdk-tools.zip -d /opt/android \
    && rm android-sdk-tools.zip \
    && cd /opt \
    && wget -q https://dl.google.com/android/repository/commandlinetools-linux-6609375_latest.zip -O android-commandline-tools.zip \
    && mkdir -p /opt/android/cmdline-tools \
    && unzip -q android-commandline-tools.zip -d /opt/android/cmdline-tools \
    && rm android-commandline-tools.zip \
    && cd /opt \
    && wget -q https://dl.google.com/android/maven2/com/android/tools/build/aapt2/4.2.1-7147631/aapt2-4.2.1-7147631-linux.jar -O aapt2.zip \
    && unzip -q aapt2.zip -d /opt/android/ \
    && rm aapt2.zip

ENV PATH ${PATH}:/opt/android/platform-tools:/opt/android/cmdline-tools/tools/bin

RUN yes | sdkmanager  --licenses

RUN touch /opt/android/.android/repositories.cfg

RUN sdkmanager "tools" "platform-tools"

RUN yes | sdkmanager --update --channel=3

RUN yes | sdkmanager \
    "platforms;android-31" \
    "platforms;android-30" \
    "platforms;android-29" \
    "platforms;android-28" \
    "build-tools;31.0.0" \
    "build-tools;30.0.3" \
    "build-tools;29.0.3" \
    "build-tools;29.0.2" \
    "build-tools;28.0.3" \
    "build-tools;28.0.0" \
    "extras;android;m2repository" \
    "extras;google;m2repository" \
    "extras;google;google_play_services" \
    "extras;m2repository;com;android;support;constraint;constraint-layout;1.0.2" \
    "extras;m2repository;com;android;support;constraint;constraint-layout;1.0.1" \
    "add-ons;addon-google_apis-google-24" \
    "add-ons;addon-google_apis-google-23" \
    "add-ons;addon-google_apis-google-22" \
    "ndk;23.0.7599858"

RUN yes | sdkmanager --update --include_obsolete

RUN apt-get purge maven maven2 \
    && apt-get update \
    && apt-get -y install maven \
    && mvn --version

RUN mkdir /opt/android-ndk-tmp && \
    cd /opt/android-ndk-tmp && \
    wget -q https://dl.google.com/android/repository/android-ndk-${ANDROID_NDK_VERSION}-linux-x86_64.zip && \
    # uncompress
    unzip -q android-ndk-${ANDROID_NDK_VERSION}-linux-x86_64.zip && \
    # move to its final location
    mv ./android-ndk-${ANDROID_NDK_VERSION} ${ANDROID_NDK_HOME} && \
    # remove temp dir
    cd ${ANDROID_NDK_HOME} && \
    rm -rf /opt/android-ndk-tmp

ENV PATH ${PATH}:${ANDROID_NDK_HOME}

RUN npm install -g npm && npm install -g app-icon yarn react-native-cli expo-cli create-react-app ionic cordova cordova-res @ionic/cli && npm update -g

RUN apt-get clean

EXPOSE 3000 5000 8100 8200 8080 9876 35729 53703 8081 5037 80 19000 19001

VOLUME ["/app"]
WORKDIR /app
CMD ["bash"]

If any other file form the project is needed just ask and i will update the question.

  • Did you ever resolve or work around this? I'm running into the same issue with Docker/gradle. – Marcel Ray May 15 '22 at 14:22
  • Not really, i gave up trying building my own image and went after someone that did it for me. in this case was this service: https://codemagic.io/start/ There are others like AppFlow from Ionic itself – Gabriel Gonçalves May 27 '22 at 17:26
  • 3
    I was finally able to get it working by using Ubuntu instead of Alpine. My main machine is an M1 Mac which I noticed also causes some weird behaviors, so I switched to a spare Intel Mac that I have. – Marcel Ray May 27 '22 at 22:22
  • 1
    I was also using mac m1 at the time this problem ocurred, dont know if this is fixed yet i stopped using mac – Gabriel Gonçalves Dec 19 '22 at 14:09

1 Answers1

2

I was able to add the below commands to my Dockerfile to add two dependencies which gets AAPT2 to run successfully during build of a very simple Android app.

My Docker container is built from ubuntu:22.04 built and run on my M1 MacBook Pro using the default (arm64) platform.

# Install libs so Android's AAPT2 will run on an arm64 arch
RUN apt-get update && apt-get install -y libc6-amd64-cross libgcc1-amd64-cross && ln -s /usr/x86_64-linux-gnu/lib64/ /lib64
ENV LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/lib64:/usr/x86_64-linux-gnu/lib"

I am using the below Android SDK tools:

root@0b6ca8b95f33:/# sdkmanager --list_installed
[=======================================] 100% Fetch remote repository...       
Installed packages:
  Path                 | Version | Description                    | Location            
  -------              | ------- | -------                        | -------             
  build-tools;33.0.2   | 33.0.2  | Android SDK Build-Tools 33.0.2 | build-tools/33.0.2  
  platform-tools       | 34.0.1  | Android SDK Platform-Tools     | platform-tools      
  platforms;android-33 | 2       | Android SDK Platform 33        | platforms/android-33

Inspired by this answer.

PRIZ3
  • 96
  • 5