Use Docker to speed up the basic deployment idea of building Android applications

  • 2020-12-22 17:46:19
  • OfStack

meaning

Significantly shorten the distance between Android development, testing, product and channel.
Ease the burden on Android programmers.
Google's environment is already in place, and it's clear that there won't be much of a dent in docker.
Dockerfile

https://github.com/lijianying10/FixLinux/blob/master/dockerfiles/androidautobuild/Dockerfile

The story of teamwork

In agile development stand-up meetings, As a back-end programmer, I found that the release time of Android programmers was about half an hour, which I thought was too long and should be shortened by 1, which became the purpose of developing this thing. However, after studying for a period of time, I found many problems that need to be solved:

A lot of things are walled. Many dependencies cannot be reused (various pom packages). How gradlew can be installed quickly without downloading from the Internet. Automatic alignment. Automatic signature. Automatic confusion.

consideration

System underlying dependency JDK Andorid-SDK Gradlew Project depend on

Build explain

Suggestion: use the foreign vps build, otherwise you will have to wait a long time.

Build a variable


ENV JAVA_HOME /jdk1.8.0_65
ENV ANDROID_HOME /opt/android-sdk-linux/
ENV ANDROID_SDK_FILENAME android-sdk_r24.4.1-linux.tgz
ENV ANDROID_SDK_URL http://dl.google.com/android/${ANDROID_SDK_FILENAME}
ENV PATH ${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools:${JAVA_HOME}/bin/

The underlying dependence

For the gcc1 class, note that we need to install the 32-bit compilation environment, as well as git wget.


RUN sudo apt-get update && sudo apt-get install -y gcc-multilib lib32z1 lib32stdc++6 git wget && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

Install JDK


RUN cd / && wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u65-b17/jdk-8u65-linux-x64.tar.gz &&\
  tar xf jdk-8u65-linux-x64.tar.gz \
  && rm -rf $JAVA_HOME/src.zip $JAVA_HOME/javafx-src.zip $JAVA_HOME/man /jdk-8u65-linux-x64.tar.gz

Cookie is used here to determine the consent protocol.

Install SDK


RUN cd /opt && \
  wget -q ${ANDROID_SDK_URL} && \
  tar -xzf ${ANDROID_SDK_FILENAME} && \
  rm ${ANDROID_SDK_FILENAME} &&\
  echo y | android update sdk --no-ui --all --filter tools,platform-tools,extra-android-m2repository,android-21
RUN echo y | android update sdk --no-ui --all --filter android-22,build-tools-21.1.2,build-tools-22.0.1

Since it is better to keep each layer within 1G, two run are used for cutting here.
Note that SDK is installed in image with the highest version you need in your project and then installed downward. Otherwise, the folder tool will not run the tools.
Note that the above SDK plateform, etc., are based on our project, the detailed exploration 1 project code will know what to rely on.
Prepare project

Use git clone to synchronize the project directory.
Do the first manual build compilation. The command is gradlew assembleDebug
There are three purposes in point 2:

To see if the project lacks dependencies, use the android update sdk command to add the Android sdk dependency package. Automatically downloads all dependencies in the project. Install gradlew.

There are two points that need to be backed up

/root/.gradle Backup This directory allows you to automate future builds without having to install gradlew repeatedly. $PROJDIR/.gradle project relies on backup, backup up. ($PROJDIR for your project root location)

After all backups, the next build does not need a network (containers do not need ladders, which is important for speed).

Build Image according to the project

Because the dependencies of each project are not the same, they need to be customized for the project. The general operation objectives are as follows:

Create the container. Find a method to synchronize the code git, FTP, NFS, and so on. Place the above two backup points in the specified location for use. Execute the build output. Destroy the container.

As long as you can do this one, plus 1 git hook plus a simple release is a simple CI.

Alignment, signature, confusion

The build.gradlew for the project can be adjusted according to the reference documentation below

The signature is to add the following code under the Android node:


signingConfigs {
release{
      storeFile file("../xxxxxxx.keystore")
      storePassword "xxxxxx"
      keyAlias "xxxxx"
      keyPassword "xxxxx"
}}

Add the following option under release under buildTypes:


signingConfig signingConfigs.release

Alignment has been aligned according to the Android documentation following the two steps above. You are ready to install.

Confuse (proguard) and add the following option under buildTypes:


proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

conclusion

After research and practice, it takes about 31 minutes to build more than 30 channels of our application if we use an ordinary laptop. If you use the RancherOS server Xeon X5675 two blades with CPU 48G memory build time is 1 minute and 6 seconds.


Related articles: