Full-trap hack: Continuous integration of Android engineering in Jenkins in a Linux environment

Source: Internet
Author: User
Tags lua

This scenario takes the Rhel/centos 64-bit Linux operating system as an example, as this is the most common server environment today.

First, install the Java SDK.
It is recommended that you do not use things like Yum to install automatically, because the OPENJDK and the like will eventually be a variety of non-moth to run up. Old and honest go to Oracle website download at least JAVA7 64-bit final version, manually installed, configure the system path and JAVA_HOME environment variables.

vim ~/.bash_profileexport JAVA_HOME=<Java安装路径>PATH=$PATH:$JAVA_HOME/bin……

Second, install the Android SDK Management tool.
The idea is to go to the Google site to the Linux version of the Android SDK Management tool compression package, if you can not access Google (Chinese characteristics you know) on the Internet to find IP address with host and other methods to get it done.

wget https://dl.google.com/android/android-sdk_r23.0.2-linux.tgz

Then it is the decompression configuration environment variable, and finally ensure that the "Android" command is available in the system is the purpose.
Edit ~/.bash_profile Add system path 2 pieces:

PATH=$PATH:$your_android-sdk-linux/toolsPATH=$PATH:$your_android-sdk-linux/platform-toolsexport PATH

64-bit System please set this environment variable:

export ANDROID_SWT=$your_android-sdk-linux/tools/lib/x86_64# 如果是32位系统则这样设置:# export ANDROID_SWT=$your_android-sdk-linux/tools/lib/x86

After the finished check whether OK, run the command:

-h

Third, install ant in order to execute the automatic compilation script.
It is recommended to honestly download Apache ant, Note: android-sdk_r23.0.2 must be above the ANT 1.8 version, unzip it, and configure its bin directory to the system execution path. The process no longer nonsense ~
You may experience problems during:

Java.lang.ClassNotFoundException:org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp

This solves:

sudo yum install ant-apache-regexp

or (Ubuntu system)

sudo apt-get install ant-optional

Iv. Download the Android SDK.
The idea is to first see what versions of the SDK, their number, and then choose their own needs to download, if the full download is too much, in China, slow. You'll be using the following command to get these things done:

# 查看远程所有的SDKlist--all# 查看本地已安装的SDKlist target# 仅仅下载编号为27的SDK,--no-ui 不需要启动图形界面--no-ui --all --filter 27# 下载 platform-tools和android-19--no-ui -u --all --filter platform-tools,android-19# 下载所有的SDK(不建议这样做)--no-ui

Start to try to build the project
Android projects generally do not have ant build file Build.xml, so you need to run the following command at the project root to test if you can build:

update project -p .

You may encounter the following problems:

Execute failed: java.io"/android/sdk/build-tools/android-4.1/aapt"error=2

Workaround:

-y compat-libstdc++-296.-y compat-libstdc++-33.
/android/sdk/build-tools/android-4.1whileshared libraries: libz.so.1opensharedfilefileor directory

Workaround:

install -y zlib
/android/sdk/build-tools/android-4.1whileshared libraries: libstdc++.so.6opensharedfilefileor directory

Workaround:

yuminstall-ylibstdc++.so.6
errorwhileshared libraries: libz.so.1shared obj

Workaround:

install -y zlib.i686

Vi. setting up Jenkins and setting the relevant environment.
Analyze code quality you need to findbugs.
It is recommended that you download Findbugs 2.0.3 and then unzip it to a directory even if it is installed. Copy the Findbugs-ant.jar to the Ant_home/lib directory again.
In the "android-sdk/tools/ant" this directory to create findbugs-exclude.xml this file, just findbugs do not scan non-Java code, the content is as follows:

<?xml version= "1.0" encoding= "UTF-8"?><findbugsfilter>  <Match>    <Class name="~.*\." r\$.* "/>    <Bug Code="Nm"/>  </Match>  <Match>    <Class name="~.*\." manifest\$.* "/>    <Bug Code="Nm"/>  </Match></findbugsfilter>

Then edit "Android-sdk/tools/ant/build.xml" to increase FindBugs's build task:

<taskdef name= "findbugs" classname=" Edu.umd.cs.findbugs.anttask.FindBugsTask "/><target name="FindBugs">  <mkdir dir="reports" />    <findbugs Home="< your findbugs installation directory >" output="xml" outputFile="Reports/findbugs.xml" excludefilter="Findbugs-exclude.xml" >      <auxclasspath path="${project.target.android.jar}"/>      <auxclasspath>              <fileset dir="Libs" includes="*.jar" />                                                  </auxclasspath>      <class location ="${out.dir}" />      <sourcepath path="${source.dir}" />    </findbugs></target>

The official standard practice is this advice, I feel too troublesome, for reference:

< property name= "findbugs.home" value="${env. Findbugs_home} " />  <path id="Findbugs_lib">      <fileset dir="${findbugs.home}/lib/">          <include name="*.jar"/>      </fileset>  </path>  <taskdef name= "findbugs" classname=" Edu.umd.cs.findbugs.anttask.FindBugsTask " classpathref=" Findbugs_lib " />  <target name="FindBugs" depends="-compile">      <mkdir dir="reports" />      <findbugs Home="${findbugs.home}" output="html" outputFile="reports/${ant.project.name}_findbugs.html">          <auxclasspath path="${android.jar}" />          <auxclasspath>              <fileset dir="${other-dependency-lib-dir}/libs" includes="*.jar" />          </auxclasspath>          <class location ="${out.dir}" />          <sourcepath path="${source.dir}" />      </findbugs>  </target>

Finally, start a pleasant operation with Jenkins:
First configure Findbugs.home and Android-sdk.home in the Jenkins System environment variable console, you know.
Then "build a free-style software project" in Jenkins.
In the project, add the "build step" in the following order:
Execute Shell
Command

androidupdateproject-p.--targetandroid-19

Invoke Ant
Targets

cleandebugfindbugslint

See, the FindBugs command is the ant build task we just configured.
The lint command requires Jenkins to install the response plugin, which is not mentioned here.

Resources:
Http://www.cnblogs.com/ifantastic/p/3981295.html
Https://www.digitalocean.com/community/tutorials/how-to-build-android-apps-with-jenkins
Http://stackoverflow.com/questions/17963508/how-to-install-android-sdk-build-tools-on-the-command-line
http://wolfgangkiefer.blog.163.com/blog/static/86265503201310206246960

Full-trap hack: Continuous integration of Android engineering in Jenkins in a Linux environment

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.