The basic deployment idea of using Docker to speed up the construction of Android applications _android

Source: Internet
Author: User

Significance

An enormous shortening of the Android development to the test to the distance of the product to the channel.
Lighten the burden for Android programmers.
Google's environment is already in place, and it's obviously not going to have much of a hole in the Docker (mistakes, escapes).
Dockerfile

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

The story of team collaboration

At the stand-up meeting of Agile Development, as a back-end programmer, I found that Android programmers were releasing about half an hour or so, and I thought it was too long to shorten it and became the object of the research. But after studying for a while, we found a lot of problems to solve:

    1. Many things are by the wall.
    2. Many dependencies cannot be reused (various pom packs).
    3. Gradlew How to quickly install does not need to download from the Internet.
    4. Automatic alignment.
    5. Automatic signing.
    6. Automatic obfuscation.

Consider the scope

    • System underlying dependencies
    • Jdk
    • Andorid-sdk
    • Gradlew
    • Project Dependencies

Building an explanation

Suggestion: Use foreign VPS to build, otherwise have to wait for a long time.

Building variables

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/

Underlying dependencies

GCC class, note that we need to install the 32-bit compilation environment, as well as Git wget.

Copy Code code as follows:

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


Installing 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

A cookie is used here to determine the consent agreement.

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

   

Because it's best to control every layer within 1G so there's two run for cutting here.
Note that the SDK is installed in image with the highest version you need in your project and then installed down, or there will be a situation where the tool folder cannot run the tool.
Note that the above SDK Plateform are based on our project, a detailed exploration of the project code to know what to rely on.
Prepare the Project

Synchronize the project directory with Git clone.
Make the first manual build compilation. Command is: Gradlew assembledebug
The purpose of the 2nd is three:

    1. To see if your project is missing dependencies, use the Android Update SDK command to increase the number of Android SDK dependencies.
    2. Automatically downloads all dependencies in the project.
    3. Install Gradlew.

There are two points that need to be backed up

    1. /root/.gradle Backup This directory can be installed in the future without the need to repeatedly install Gradlew.
    2. $PROJDIR/.gradle The backup of the project dependencies, backed up. ($PROJDIR for your project root location)

After the backup, the next compilation will not need the network (the container does not need a ladder, which is important to the speed of ascension).

Build Image from Project

Because each project relies on different dependencies, it needs to be customized for the project. The approximate operating objectives are as follows:

    • Create a container.
    • Find a way to synchronize code GIT,FTP,NFS and so on.
    • Place the top two backup points at the specified location for use.
    • Executes the build output.
    • Destroy the container.

In fact, as long as the above point, add a git hook plus a simple release is a simple CI.

Align, sign, confuse

The Build.gradlew of the project can be adjusted according to the following reference documentation

The signature is added below the Android node with the following code:

Signingconfigs {
release{
      storefile file (".. /xxxxxxx.keystore ")
      Storepassword" xxxxxx "
      keyalias" xxxxx "
      Keypassword" xxxxx "
}}

Under release below Buildtypes, add the following options:

Copy Code code as follows:

Signingconfig Signingconfigs.release


Alignment is aligned according to the official Android documentation as modified by the previous two-step code. Ready to install.

Obfuscation (Proguard), add the following options below the buildtypes below:

Copy Code code as follows:

Proguardfiles getdefaultproguardfile (' proguard-android.txt '), ' Proguard-rules.pro '


Summary

After research and combat, if the use of ordinary laptops, our application of more than 30 channels probably need to use 31 minutes to build. If you use the Rancheros server Xeon X5675 two CPU 48G memory blade Server build time is 1 minutes 6 seconds.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.