zoukankan      html  css  js  c++  java
  • 全陷阱破解:在Linux环境下的Jenkins中持续集成Androidproject

    本方案以 RHEL / Centos 64位Linux操作系统为例,由于这是眼下最常见的server环境。

    一、安装Java SDK。


    建议,不要使用诸如yum之类的玩意自己主动安装,由于openJDK之类的东东终于各种幺蛾子跑不起来。老老实的去oracle站点下载至少Java7 64位的终于版本号。手动安装之,配置好系统path和JAVA_HOME环境变量。

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

    二、安装Android SDK管理工具。
    思路就是去Google站点上把Linux版本号的Android SDK管理工具压缩包搞下来,假设訪问不了Google(中国特色你懂的)就上网找IP地址配host之类的方法搞定。

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

    然后就是解压缩配置环境变量啦,终于确保”android”命令在系统中可用就是目的。
    编辑 ~/.bash_profile 加入系统路径2枚:

    PATH=$PATH:$your_android-sdk-linux/tools
    PATH=$PATH:$your_android-sdk-linux/platform-tools
    export PATH

    64位系统请设置这个环境变量:

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

    完事后检測一下是否OK。执行命令:

    android -h

    三、安装Ant为了执行自己主动编译脚本。


    建议老老实实去下载 Apache Ant,注意:android-sdk_r23.0.2 必须要 Ant 1.8 版本号以上才行,解压之,并将其bin文件夹配置到系统执行路径中。过程不再废话~
    期间可能会遇到问题:

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

    这样解决:

    sudo yum install ant-apache-regexp

    或(Ubuntu系统)

    sudo apt-get install ant-optional

    四、下载Android SDK。
    思路是先查看有哪些版本号的SDK,它们的编号怎样,然后选择自己须要的下载之。假设全下载的话就太多了,在中国。慢。搞定这些事你会用到例如以下命令:

    # 查看远程全部的SDK
    android list sdk --all
    
    # 查看本地已安装的SDK
    android list target
    
    # 只下载编号为27的SDK,--no-ui 不须要启动图形界面
    android update sdk --no-ui --all --filter 27
    
    # 下载 platform-tools和android-19
    android update sdk --no-ui -u --all --filter platform-tools,android-19
    
    # 下载全部的SDK(不建议这样做)
    android update sdk --no-ui

    五、開始尝试构建工程
    Android工程一般没有Ant构建文件build.xml。因此须要在项目根文件夹执行例如以下命令測试一下是否能生成:

    android update project -p .

    可能你会遇到例如以下问题:

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

    解决的方法:

    yum install -y compat-libstdc++-296.i686 
    yum install -y compat-libstdc++-33.i686 

    /android/sdk/build-tools/android-4.1/aapt: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory

    解决的方法:

    yum install -y zlib

    /android/sdk/build-tools/android-4.1/aapt: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory

    解决的方法:

    yum install -y libstdc++.so.6

    error while loading shared libraries: libz.so.1: cannot open shared obj

    解决的方法:

    yum install -y zlib.i686

    六、设置Jenkins和设置相关环境。


    分析代码质量你须要Findbugs。
    所以建议你下载 Findbugs 2.0.3,然后解压缩到某个文件夹就算安装了。再复制 findbugs-ant.jar 到 ANT_HOME/lib 文件夹。
    在“android-sdk/tools/ant”这个文件夹里创建 findbugs-exclude.xml 这个文件,不过findbugs不要扫描非Java代码,内容例如以下:

    <?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>

    然后编辑“android-sdk/tools/ant/build.xml”,添加 findbugs 的构建任务:

    <taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask"/>
    <target name="findbugs">
      <mkdir dir="reports" />
        <findbugs home="<你的findbugs安装文件夹>" 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>

    官方的标准做法是这样建议的。我认为太麻烦。供參考吧:

    <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>

    最后,開始愉快的操作Jenkins:
    首先在Jenkins系统环境变量控制台里配置 findbugs.home 和 android-sdk.home ,你懂得。


    然后“构建一个自由风格的软件项目”在Jenkins里。
    在项目里按例如以下顺序加入“构建步骤”:
    Execute shell
    Command

    android update project -p . --target android-19

    Invoke Ant
    Targets

    clean
    debug
    findbugs
    lint

    看到了吧,findbugs命令就是我们刚才配置的Ant构建任务。
    lint命令须要Jenkins安装响应的插件,这里不再赘述。


    參考资料:
    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

  • 相关阅读:
    Machine-wide Progress Telerik Fiddler installation has been found at ...Please, use that one or uninstall it ...
    Jmeter接口测试(简单的)
    Loadrunner 访问数据库
    Windows MySQL查看log日志 同步log和系统时间
    Windows 修改MySQL配置文件my.ini后如何生效
    已打开Eclipse,但找不到Eclipse存放路径
    UiPath
    UiPath
    UiPath
    UiPath
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/5161148.html
Copyright © 2011-2022 走看看