美文网首页Android
Jenkins mac上配置原生android

Jenkins mac上配置原生android

作者: stormKid | 来源:发表于2017-11-29 10:37 被阅读25次

    1、下载gradle

    shell指令:

    ~ builder$ brew install gradle
    

    检查是否安装完毕:

    ~ builder$ gradle -version
    ------------------------------------------------------------
    Gradle 4.2.1
    ------------------------------------------------------------
    
    Build time:   2017-10-02 15:36:21 UTC
    Revision:     a88ebd6be7840c2e59ae4782eb0f27fbe3405ddf
    
    Groovy:       2.4.12
    Ant:          Apache Ant(TM) version 1.9.6 compiled on June 29 2015
    JVM:          1.8.0_131 (Oracle Corporation 25.131-b11)
    OS:           Mac OS X 10.12.6 x86_64
    

    2、原生项目修改build.gradle配置

    打开app目录下的build.gradle,并加上一段编译代码

    apply plugin: 'com.android.application'
    apply plugin: 'android-apt'
    
    android {
        .........// 有很多默认配置信息
        
        //由于国内网络情况影响,默认gradle地址无法访问,
        //编译会报错,加上此行忽略报错依旧执行build
        lintOptions{
            abortOnError false
        }
        
    }
    
    

    3、原生项目修改local.properties配置

    ## This file is automatically generated by Android Studio.
    # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
    #
    # This file must *NOT* be checked into Version Control Systems,
    # as it contains information specific to your local configuration.
    #
    # Location of the SDK. This is only used by Gradle.
    # For customization when using a Version Control System, please read the
    # header note.
    #Thu Jul 27 09:49:07 CST 2017
    
    
    # WIN系统下,机器编译环境地址
    #ndk.dir=E\:\\sdk\\ndk-bundle
    #sdk.dir=E\:\\sdk
    
    
    # MAC OS下,机器编译环境地址
    ndk.dir=/Users/builder/Library/Android/sdk/ndk-bundle
    sdk.dir=/Users/builder/Library/Android/sdk
    

    4、jenkins shell命令配置

    说明:svn配置在此不做赘述
    下图为shell命令配置

    0001.png

    执行构建后的效果总共分为三个步骤:下载依赖->清理项目->编译项目成APK

    Started by user APPbuild
    Building in workspace /Users/builder/.jenkins/workspace/AndroidDemo
    Updating svn://172.16.1.202/zgcsx/android/Master at revision '2017-10-25T15:31:05.447 +0800'
    Using sole credentials ke_li/****** in realm ‘<svn://172.16.1.202:3690> 545e6826-7b7a-4598-b980-8796c9348690’
    U         .gitignore
    D         local.properties
    A         local.properties
    At revision 5097
    
    Using sole credentials ke_li/****** in realm ‘<svn://172.16.1.202:3690> 545e6826-7b7a-4598-b980-8796c9348690’
    [AndroidDemo] $ /bin/sh -xe /var/folders/s3/rkpsdb0x223c37qsfp9wwzhw0000gn/T/jenkins8814663042433137266.sh
    
    
    + gradle init
    Starting a Gradle Daemon (subsequent builds will be faster)
    File /Users/builder/.android/repositories.cfg could not be loaded.
    Checking the license for package Android SDK Build-Tools 25 in /Users/builder/Library/Android/sdk/licenses
    License for package Android SDK Build-Tools 25 accepted.
    Preparing "Install Android SDK Build-Tools 25 (revision: 25.0.0)".
    "Install Android SDK Build-Tools 25 (revision: 25.0.0)" ready.
    Finishing "Install Android SDK Build-Tools 25 (revision: 25.0.0)"
    Installing Android SDK Build-Tools 25 in /Users/builder/Library/Android/sdk/build-tools/25.0.0
    "Install Android SDK Build-Tools 25 (revision: 25.0.0)" complete.
    "Install Android SDK Build-Tools 25 (revision: 25.0.0)" finished.
    Download ........// 这里会下很多依赖包
    :init
    The build file 'build.gradle' already exists. Skipping build initialization.
    :init SKIPPED
    
    BUILD SUCCESSFUL in 2m 8s
    
    + gradle clean
    The setTestClassesDir(File) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use the setTestClassesDirs(FileCollection) method instead.
    The getTestClassesDir() method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use the getTestClassesDirs() method instead.
    The ConfigurableReport.setDestination(Object) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use the method ConfigurableReport.setDestination(File) instead.
    :clean
    :app:clean
    
    BUILD SUCCESSFUL in 1s
    2 actionable tasks: 2 executed
    
    + gradle build
    The setTestClassesDir(File) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use the setTestClassesDirs(FileCollection) method instead.
    The getTestClassesDir() method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use the getTestClassesDirs() method instead.
    The ConfigurableReport.setDestination(Object) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use the method ConfigurableReport.setDestination(File) instead.
    ...... // 这里有很多编译信息,包括没有编译通过的信息
    :app:test UP-TO-DATE
    :app:check
    :app:build
    
    BUILD SUCCESSFUL in 1m 24s
    68 actionable tasks: 68 executed
    Finished: SUCCESS
    

    3、编译注意:

    请在gradle中配置好打包的key与alias的值,否则上面的打包方式打出来的包无法安装!

    相关文章

      网友评论

        本文标题:Jenkins mac上配置原生android

        本文链接:https://www.haomeiwen.com/subject/wbhubxtx.html