5

I try to run android build on docker container.

My dockerfile's contents is here:

FROM openjdk:8-jre-alpine

RUN mkdir -p /myapp
WORKDIR /myapp
COPY . .

RUN apk add --update nodejs nodejs-npm
RUN apk add git
RUN apk add zip
RUN apk --no-cache add curl

I create a docker image and run it. I run below commands on docker terminal.

wget https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip
unzip -q sdk-tools-linux-4333796.zip -d Android-sdk
export ANDROID_HOME=/path-to-sdk/Android-sdk
export PATH=${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin:${ANDROID_HOME}/platform-tools
yes | sdkmanager  --licenses
cd MyApplication && chmod +x gradlew && ./gradlew :app:assembledebug

MyApplication is a default empty activity project of Android Studio.

Error log is here:

/gradlew :app:assembledebug

Task :app:preBuild UP-TO-DATE Task :app:preDebugBuild UP-TO-DATE Task :app:compileDebugAidl NO-SOURCE Task :app:compileDebugRenderscript UP-TO-DATE Task :app:checkDebugManifest UP-TO-DATE Task :app:generateDebugBuildConfig UP-TO-DATE Task :app:prepareLintJar UP-TO-DATE Task :app:mainApkListPersistenceDebug UP-TO-DATE Task :app:generateDebugResValues UP-TO-DATE Task :app:generateDebugResources UP-TO-DATE Task :app:mergeDebugResources FAILED

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:mergeDebugResources'.

    java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2InternalException: AAPT2 aapt2-3.3.0-alpha12-5013011-linux Daemon #0: Daemon startup failed
    This should not happen under normal circumstances, please file an issue if it does.

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

EDIT

This project works fine on my mac laptop. Local machine build is ok but it doesn't work on docker container.

EDIT

I run --stacktrace parameter. aapt2 not found

Caused by: java.io.IOException: Cannot run program "/root/.gradle/caches/transforms-1/files-1.1/aapt2-3.2.0-4818971-linux.jar/6f8af69a2b8f839763b018ee3b5c1d41/aapt2-3.2.0-4818971-linux/aapt2": error=2, No such file or directory at com.android.builder.internal.aapt.v2.Aapt2DaemonImpl.startProcess(Aapt2DaemonImpl.kt:80) at com.android.builder.internal.aapt.v2.Aapt2Daemon.checkStarted(Aapt2Daemon.kt:53) ... 8 more Caused by: java.io.IOException: error=2, No such file or directory ... 10 more

zakjma
  • 2,030
  • 12
  • 40
  • 81
  • Hey there, did you find a good solution to this? I am having a silimar issue ("NO-SOURCE") when trying to compile an Android app on a debian buster container. Locally, it runs smooth, however in docker... – jlee7 Apr 14 '21 at 11:47
  • Inside my task, I ran a script which did not execute correctly. So, in the logs gradle was complaining about NO-SOURCE, but the script actually failed, which uses the appcenter cli and something went wrong with the authentication. As said, on the development machine it works perfectly. – jlee7 Apr 14 '21 at 14:46

2 Answers2

2

Faced the same issue in openjdk:8-jre-alpine docker image.

The issue was resolved when I used oracle/openjdk:8 as the base image

Change your Dockerfile like this and try again:

FROM oracle/openjdk:8
RUN mkdir -p /myapp
WORKDIR /myapp
COPY . .

RUN yum install -y nodejs nodejs-npm
RUN yum install -y git zip curl
pipegrepper
  • 324
  • 3
  • 11
0

Try this one, very useful and straightforward. it comes with appium and latest SDK, also has a feature to open emulator in headed mode

https://hub.docker.com/repository/docker/amrka/ultimate-android

Amr Salem
  • 237
  • 1
  • 6
  • 19
  • Github repo for this docker image appears to be https://github.com/amrsa1/Android-Emulator-Docker . However it doesn't show the Dockerfile of the base image, so it is unclear how it was created. It'd be good if the Dockerfile was added to the repo, so people can decide whether or not to use it. – Manfred Mar 20 '22 at 21:52
  • Sorry, will not use an image without source. Also it says "The image is updated regulary every month", but as of now it's not been updated in three months. – tplive Dec 02 '22 at 11:05