title: Android SDK on Docker for ARM64 (Raspberry Pi 4) for building APK
body: <p><em>I am trying to create an <strong>ARM64 Docker image</strong> which is able to build an apk file of my React Native app.</em></p>
  <p><strong>Background:</strong></p>
  <p>For exercise purposes I built a Kubernetes cluster wiht 5 Raspberry Pi 4 boards. Everything is working fine, Jenkins is running on it and the backend part (Java Microservice, Maven) can be built, deployed and run on it.</p>
  <p>Now I am trying to create a Pipeline for the <strong>Android App part</strong>, which I build in <strong>React Native, Gradle</strong>. I'm just learning how everything fits together and am <strong>stuck with building the apk</strong> file on Jenkins. Locally building it (on Linux) is working fine but I'm not able to create a Docker container for the <strong>aarch64 architecture</strong> with the necessary Android SDK stuff installed to build it with Jenkins. Here is what I have by now (tell me, if I have to provide more information!):</p>
  <p>Dockerfile:</p>
  <pre><code>FROM openjdk:8-alpine3.9
  
  ENV ANDROID_SDK_ROOT /opt/android-sdk-linux
  
  RUN apk add --no-cache curl wget bash unzip \
      &amp;&amp; apk add --no-cache --update nodejs npm \
      &amp;&amp; npm install -g react-native-cli
  
  RUN cd /opt \
      &amp;&amp; wget -q https://dl.google.com/android/repository/commandlinetools-linux-6609375_latest.zip -O android-commandline-tools.zip \
      &amp;&amp; mkdir -p ${ANDROID_SDK_ROOT}/cmdline-tools \
      &amp;&amp; unzip -q android-commandline-tools.zip -d ${ANDROID_SDK_ROOT}/cmdline-tools \
      &amp;&amp; rm android-commandline-tools.zip
  
  ENV PATH ${PATH}:${ANDROID_SDK_ROOT}/platform-tools:${ANDROID_SDK_ROOT}/cmdline-tools/tools/bin
  
  RUN yes | sdkmanager --licenses
  
  RUN touch /root/.android/repositories.cfg
  
  # This part fails!
  # RUN yes | sdkmanager &quot;emulator&quot; &quot;platform-tools&quot;
  
  RUN yes | sdkmanager --update --channel=3
  RUN yes | sdkmanager \
      &quot;platforms;android-29&quot; \
      &quot;build-tools;29.0.3&quot; \
      &quot;build-tools;29.0.2&quot; \
      &quot;build-tools;29.0.1&quot; \
      &quot;build-tools;29.0.0&quot;
  </code></pre>
  <p>Jenkinsfile:</p>
  <pre><code>pipeline {
      agent {
          kubernetes {
              defaultContainer 'app-build'
              yamlFile 'kubernetes-pod.yaml'
          }
      }
      stages {
          stage ('print env vars') {
              steps {
                  sh 'printenv'
                  sh 'echo &quot;JAVA-VERSION: &quot;'
                  sh 'java -version'
                  sh 'echo &quot;NODE-VERSION:&quot;'
                  sh 'node --version'
                  sh 'echo &quot;NPM version:&quot; '
                  sh 'npm --version'
                  sh 'echo &quot;REACT-NATIVE-VERSION:&quot;'
                  sh 'react-native --version'
              }
          }
         stage ('Gradle Build') {
             steps {
                 sh ('react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res')
                 dir ('android') {
                     // this step fails (error message below)
                     gradlew('assembleRelease', '--scan')
                 }
             }
         }
  
         /* ... more steps ... */
      }
  }
  
  def gradlew(String... args) {
      sh &quot;./gradlew ${args.join(' ')} -s&quot;
  }
  </code></pre>
  <p>The error message I get on Jenkins is the following:</p>
  <pre><code>Starting a Gradle Daemon (subsequent builds will be faster)
  
  &gt; Configure project :react-native-reanimated
  Warning: Dependant package with key emulator not found!
  
  FAILURE: Build failed with an exception.
  
  * Where:
  Build file '/home/jenkins/agent/workspace/nches_CHEF-8-frontend-deployment/node_modules/react-native-reanimated/android/build.gradle' line: 89
  
  * What went wrong:
  A problem occurred configuring project ':react-native-reanimated'.
  &gt; Failed to install the following SDK components:
        build-tools;29.0.2 Android SDK Build-Tools 29.0.2
    Install the missing components using the SDK manager in Android Studio.
  </code></pre>
  <p>kubernetes-pod.yaml</p>
  <pre><code>apiVersion: v1
  kind: Pod
  metadata:
    labels:
      label: jenkins-agent
      job: build-services
    namespace: build-services
  spec:
    containers:
      - name: jnlp
        image: franzbuholzer/jenkins-jnlp-arm64:4.6
        tty: true
      - name: maven
        image: maven:3.6.3-jdk-11
        tty: true
        command: [&quot;cat&quot;]
        volumeMounts:
          - name: repository
            mountPath: /root/.m2/repository
      - name: docker
        image: docker:19.03.13
        command: [&quot;cat&quot;]
        tty: true
        volumeMounts:
          - name: docker-sock
            mountPath: /var/run/docker.sock
    volumes:
      - name: repository
        persistentVolumeClaim:
          claimName: repository
      - name: docker-sock
        hostPath:
          path: /var/run/docker.sock
  </code></pre>
  <p>I would be very happy if someone could help me solving this problem, that so I can attack the next obstacles, which I guess would be copying the generated apk into another Docker image and deploy it on the cluster to make it downloadable...</p>