Android Build in docker container

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

Source: StackOverflow