Linux servers deploy Jenkins to package the Android Apk

Install the JAVA environment

1. Download the JDK

Download the JDK version depending on the situation At present this tutorial USES jdk8 can also go to the download page: www.oracle.com/technetwork… Download the installation package as required. You are advised to download the installation package in the tar.gz format. Upload the file to the server and run the tar -zxvf jdk-8u261-linux-i586.tar.gz command.

2. Configure environment variables

vim /etc/profile
Copy the code

Open to the end and add the JAVA_HOME environment variable

Export JAVA_HOME=/usr/local/ Java /jdk1.8.0_261 export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH=${JAVA_HOME}/bin:$PATHCopy the code

Run commands to make environment variables take effect

source /etc/profile
Copy the code

Install GRADLE environment

1. Download GRADLE

According to the project of using gradle version download the corresponding file download address: services.gradle.org/distributio…

Here is the use of gradle-5.4.1-all.zip, download and upload to the server here is put in /usr/local/gradle path (according to your own situation), decompress.

Unzip gradle 5.4.1 - all. ZipCopy the code

2. Configure environment variables

Open the file

vim /etc/profile
Copy the code

At the end of the file, add (you can put it with JAVA_HOME)

Export GRADLE_HOME = / usr/local/gradle/gradle - 5.4.1 export PATH = ${GRADLE_HOME} / bin: ${PATH}Copy the code

And then execute it

source /etc/profile
Copy the code

Install the AndroidSDK

1. Download the AndroidSDK

Open the url: developer. The android. Google. Cn/studio

Locate the SDK Tools package under Command Line Tools Only and download the Linux package

After the download is complete, upload to the server /opt/ Android (the path can be put together with Gradle depending on your situation). Unzip XXX is decompressed

After normal decompression only this one folder, OK, we go to configure the environment at this time

Open the

vim /etc/profile
Copy the code

Same as above

export ANDROID_HOME=/opt/android/sdk
export PATH=$PATH:$ANDROID_HOME:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools/bin
Copy the code

Configuration Android_home

perform

source /etc/profile
Copy the code

At this point, go to the tools layer folder

perform

sdkmanager --list
Copy the code

A table like the one below should appear

At this time according to the current project needs to install the version can be.

For example, the current project needs build-tools. 29.0.2 platforms; Android – 28, the NDK; 21.3.6528147

For example:

sdkmanager "platform-tools" sdkmanager "build-tools; 29.0.2 "sdkmanager" platforms; android-28" sdkmanager "ndk; 21.3.6528147"Copy the code

After the required version is installed, the current folder will appear as shown in the above figure.

All the environment variables required by this point are installed.

4. Install Jenkins

1. Download the installation package

To: pkg.jenkins-ci.org/redhat-stab… For example, download jenkins-2.222.1-1.1.noarch. RPM and upload it to the server

RPM - the ivh Jenkins - 2.222.1-1.1 noarch. RPMCopy the code

The installation is complete.

2. Modify the configuration

vim /etc/sysconfig/jenkins
Copy the code

You can change the port according to your own needs, the original is 8080.

Basically, the installation is complete. You can access the server IP :8080.

If there is no pass check problem

systemctl status jenkins
Copy the code

If it is a Java environment problem, you can replace your own path

Run the vi /etc/init.d/ Jenkins command to change the Java directory to your own

Then start Service Jenkins Start

When you first opened Jenkins, there was an initial password that you had to enter.

The password is on the server CD /var/lib/jenkins/secrets

Start packing

1. Enable the Jenkins system configuration and configure the following three parameters

ANDROID_HOME

/usr/share/android-sdk

GRADLE_USER_HOME

/ usr/local/gradle/gradle – 5.4.1

JAVA_HOME

/ usr/local/Java/jdk1.8.0 _261

These three paths are consistent in the above server’s environment variable

2. After the Gradle plug-in is successfully installed, enter the global tool configuration of system management

This address is also the environment variable configuration of the above server.

3. Create a task

Source code management has Git by default according to their needs

Install subversion without SVN plugins

Then add the build step

1 Position select the global parameter you just set. 2 Position select your execute commands can be separated by Spaces

Click Save to go back to the home page to build.

Copyright Notice: All articles in this blog are under the [CC BY 4.0CN agreement] license unless otherwise stated. Reprint please indicate the source!