简体   繁体   中英

how to build and run android apk on emulator using dockerfile

I have a android application on github account. I want to checkout that project and create its apk through gradle and generate its apk on windows .And then run that apk on emulator. All these things I want to do through script using dockerfile so that it creates an image.

This is my dockerfile

FROM java:8
ENV DEBIAN_FRONTEND noninteractive
# Dependencies
RUN dpkg --add-architecture i386 && apt-get update && apt-get install -yq libsdl1.2debian:i386 zlib1g:i386 libncurses5:i386 ant maven --no-install-recommends
ENV GRADLE_URL http://services.gradle.org/distributions/gradle-2.2.1-all.zip
RUN curl -L ${GRADLE_URL} -o /tmp/gradle-2.2.1-all.zip && unzip /tmp/gradle-2.2.1-all.zip -d /usr/local && rm /tmp/gradle-2.2.1-all.zip
ENV GRADLE_HOME /usr/local/gradle-2.2.1
# Download and untar SDK
ENV ANDROID_SDK_URL http://dl.google.com/android/android-sdk_r24.1.2-linux.tgz
RUN curl -L "${ANDROID_SDK_URL}" | tar --no-same-owner -xz -C /usr/local
ENV ANDROID_HOME /usr/local/android-sdk-linux
ENV ANDROID_SDK /usr/local/android-sdk-linux
ENV PATH ${ANDROID_HOME}/tools:$ANDROID_HOME/platform-tools:$PATH
# Install Android SDK components
ENV ANDROID_SDK_COMPONENTS tools,platform-tools,android-22,build-tools-22.0.1,sys-img-armeabi-v7a-android-22,extra-android-m2repository,extra-google-m2repository
RUN echo y | android update sdk --no-ui --all --filter "${ANDROID_SDK_COMPONENTS}" --force
# Create emulator
RUN echo "no" | android create avd \
                --force \
                --name test \
                --target android-22 \
                --abi armeabi-v7a \
                --skin WVGA800 \
                --sdcard 512M
CMD emulator -avd test -force-32bit
# Support Gradle
ENV TERM dumb
ENV JAVA_OPTS -Xms256m -Xmx512m

Please let me know how to do this.

If I understand you questions what you want is:

  1. Check out the android project from github for this the command is git clone --bare https://youurl.org/user/repo.git
  2. Create its apk through gradle build for this the command is gradlew android:installDebug android:run
  3. Run that apk on android emulator for this the command is, from your SDK's tools/ directory , install the .apk on the emulator:

     adb install <path_to_your_bin>.apk adb -s emulator-path install path/to/your/app.apk 

Once your repo is set, you can use below gradle commands to build and install. The advantage of gradle commands over adb commands is that, You can choose between different flavors and product versions. See this detailed article for build, test and deploy via bash script using gradle commands.

./gradlew build


./gradlew assembleDebug

#Install APK on device / emulator
./gradlew installDebug

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM