background

As business requirements evolve, engineering complexity increases and the practice of automation becomes more and more intense. In fact, the automation of engineering has always been the goal we strive to pursue, which can effectively improve our production efficiency, minimize the probability of human error, and achieve some complex business needs.

In my current company, for example, we have 22 channel packages, which are divided into test environment and production environment. The new iteration began to eliminate the need to burn the beta APP directly for testers and occasionally interrupted by business and operations to add a channel package. Especially near the release of the week, almost every day to the new version. This has two effects: first, it interrupts the development schedule of the developers; Second, developer packaging is inefficient.

To solve this problem, mobile applications must be built automatically. Specifically, Jenkins uses continuous integration (CI) system to automatically detect and pull the latest code on Git, automatically package it into different channel APK, and upload it to dandelion and self-built FTP server. (Next, testers can open one (or more) fixed web sites, scan a QR code, and download the latest version…)

The environment

Because the servers on the Intranet of the company are all Windows operating systems, the following operations are all Windows as an example. Jenkins’ configuration is the same regardless of the operating system.

Install Jenkins

Jenkins-ci.org/… By default, visit http://localhost:8080/ to enter the Jenkins configuration page.

Install Jenkins plugins

Choose System Administration > Manage Plug-ins > Optional Plug-ins to search for the following plug-ins

Git plugin

SSH Credentials Plugin

Gradle Plugin – For Android

Note:

  1. Here you need to use VPN or modify the hosts file of the system to search the plug-in;
  2. There is a Windows to install JDK, Git, Gradle environment.

The effect picture after installation:

The new Job

Home page, New -> Build a free style software project.

Configuring the Git Repository

If the git plug-in is installed, git will appear in source control.

Configure automatic pull up to date code

In build triggers, there are two strategies for automatically pulling code and compiling:

  1. Set Poll SCM, set timer, check periodically for code updates, compile if there are updates, otherwise not compile.
  2. You can also set up Build periodically to perform compilation tasks.

Configuration gradle

If the gradle plugin was successfully installed, the following Invoke Gradle script should appear:

Then, the corresponding APK can be automatically generated under build/outputs/ APK of app under project.

To distinguish between a test environment and a production environment, I created two tasks for the primary branch and sub-branch on Git:

FTP server setup:

D:\Jenkins\ Jobs \XXForAndroidTest\workspace\app\build\outputs\apk: D:\Jenkins\ Jobs \XXForAndroidTest\workspace\app\build\outputs\apk

If the compilation fails, check the following problems:

  1. Make sure that gradle, Git, and JDK environment variables are configured correctly
  2. The SDK definition in local.properties could not be found because local.properties is not normally added to the repository.
  3. There is also the path of the signature key for build.gradle in the subproject

Local.properties

sdk.dir=xx/xx/android-sdk
Copy the code

Recompiling will generally compile successfully, although it can be slow when third-party libraries need to be redownloaded.

To summarize

After the above toss and toss, we can finally completely free the hands of developers to concentrate on writing code, we should try to put energy on the business to improve work efficiency in the future work.