Jenkins 通过Gradle对Android实现持续集成

Gradle 编译打包越来越受欢迎,特别是在安卓端,如何实现GitLab、Jenkins 、Gradle、fir工具完成版本、编译、打包、发布流程。

 

Jenkins配置 Git

Gradle构建环境配置

Gradle build.gradle配置文件

apply plugin: 'com.android.application'
Properties properties = new Properties()
properties.load(project.rootProject.file('gradle.properties').newDataInputStream())
android {
    signingConfigs {
        config {
            keyAlias 'androiddebugkey'
            keyPassword 'android'
            storeFile file('../debug.keystore')
            storePassword 'android'
        }
    }
    compileSdkVersion COMPILE_SDK_VERSION
    buildToolsVersion BUILD_TOOLS_VERSION
    defaultConfig {
        applicationId "com.xgj.android"
        minSdkVersion MIN_SDK
        targetSdkVersion TARGET_SDK_VERSION
        versionCode PUBLISH_VERSION_CODE
        versionName PUBLISH_VERSION
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_7
            targetCompatibility JavaVersion.VERSION_1_7
        }
//        删除无用的语言资源
        resConfigs "zh"
        multiDexEnabled true
    }
    buildTypes {
        release {
//            是否开启混淆
            minifyEnabled false
//            是否优化apk文件,将apk文件中未压缩的数据在4个字节边界上对齐
            zipAlignEnabled true
//            是否去除无用资源,任何在编译过程中没有用到的资源或者代码都会被删除,可以有效减小apk体积
            shrinkResources false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules-xgj.pro'
            signingConfig signingConfigs.config
        }
        debug {
            minifyEnabled false
            zipAlignEnabled true
            shrinkResources false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules-xgj.pro'
            signingConfig signingConfigs.config
        }
        // 修改包名
        applicationVariants.all { variant ->
            variant.outputs.all { output ->
                def newApkName = versionTag() + "_" + variant.productFlavors[0].name + ".apk"
                outputFileName = new File(newApkName)
            }
        }

    }
    dexOptions {
        javaMaxHeapSize "4g"
    }
    packagingOptions {
        exclude 'META-INF/MANIFEST.MF'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
    }
    lintOptions {
        abortOnError false
        disable 'MissingTranslation'
        checkReleaseBuilds false
        ignoreWarnings true
    }
    flavorDimensions 'debug'
    productFlavors {
        xgj_debug {
            dimension "debug"
            versionName = PUBLISH_VERSION + "_debug"
            System.out.println("debug   " + versionName)
            //配置信息
            manifestPlaceholders =
                    [RONG_CLOUD_APP_KEY_VALUE: properties.getProperty("rongcloudappkey.debug"),
                     JPUSH_KEY_VALUE         : properties.getProperty("jpushkey.debug"),
                     UMENG_KEY_VALUE         : properties.getProperty("umengkey.debug"),
                     BAIDU_KEY_VALUE         : properties.getProperty("baidumap.debug")
                    ]
            buildConfigField "String", "SERVER_URL", properties.getProperty("serverurl.debug")
            buildConfigField "String", "CUSTOM_ID", properties.getProperty("custom.debug")
            buildConfigField "String", "ENCODE_KEY", properties.getProperty("encode.key")
            buildConfigField "String", "ZHICHI_CUSTOM_ID", properties.getProperty("zhichi_custom.debug")
            buildConfigField "String", "RYKEY", properties.getProperty("rongyunappkey.debug")
            buildConfigField "String", "RYSecret", properties.getProperty("rongyunSecret.debug")
        }
        xgj_release {
            dimension "debug"
            versionName = PUBLISH_VERSION + "_release"
            System.out.println("dev   " + versionName)
            //配置信息
            manifestPlaceholders =
                    [RONG_CLOUD_APP_KEY_VALUE: properties.getProperty("rongcloudappkey.release"),
                     JPUSH_KEY_VALUE         : properties.getProperty("jpushkey.release"),
                     UMENG_KEY_VALUE         : properties.getProperty("umengkey.release"),
                     BAIDU_KEY_VALUE         : properties.getProperty("baidumap.release")
                    ]
            buildConfigField "String", "SERVER_URL", properties.getProperty("serverurl.release")
            buildConfigField "String", "ENCODE_KEY", properties.getProperty("encode.key")
            buildConfigField "String", "CUSTOM_ID", properties.getProperty("custom.release")
            buildConfigField "String", "ZHICHI_CUSTOM_ID", properties.getProperty("zhichi_custom.release")
            buildConfigField "String", "RYKEY", properties.getProperty("rongyunappkey.release")
            buildConfigField "String", "RYSecret", properties.getProperty("rongyunSecret.release")
        }

    }

}
//按日期生成的包名
def versionTag() {
    return PUBLISH_VERSION_CODE + "_xgj3.0.3"
}

dependencies {
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    compile fileTree(include: '*.jar', dir: 'libs')
    //依赖项目
    compile project(':Rong_Cloud_v2_6_10')
    compile project(':RecordVideo')
    compile project(':swipebackhelper')
    compile project(':PLDroidStreaming')
    compile project(':vitamio')
    //支持库
    //三方sdk
    compile files('libs/alipaySingle-20161222.jar')
    compile files('libs/baidumapapi_base_v3_6_1.jar')
    compile files('libs/baidumapapi_cloud_v3_6_1.jar')
    compile files('libs/baidumapapi_map_v3_6_1.jar')
    compile files('libs/baidumapapi_radar_v3_6_1.jar')
    compile files('libs/baidumapapi_search_v3_6_1.jar')
    compile files('libs/baidumapapi_util_v3_6_1.jar')
    compile files('libs/locSDK_6.13.jar')
    compile files('libs/jpush-android-2.1.7.jar')
    compile files('libs/zxing.jar')
    compile files('libs/SocialSDK_QQ_Full.jar')
    compile files('libs/SocialSDK_Sina_Simplify.jar')
    compile files('libs/SocialSDK_WeiXin_Full.jar')
    compile files('libs/umeng_shareboard_widget.jar')
    compile files('libs/umeng_social_api.jar')
    compile files('libs/umeng_social_net.jar')
    compile files('libs/umeng_social_shareboard.jar')
    compile files('libs/umeng_social_shareview.jar')
    compile files('libs/mta-sdk-1.6.2.jar')
    compile files('libs/open_sdk_r5756_lite.jar')
    compile files('libs/libammsdk.jar')
    compile files('libs/umeng-analytics-v5.6.7.jar')
    //http 补充包
    compile files('libs/httpmime-4.1.3.jar')
    compile files('libs/httpclient-4.5.2.jar')
    compile files('libs/httpclient-cache-4.5.2.jar')
    compile files('libs/httpclient-win-4.5.2.jar')
    compile files('libs/httpcore-4.4.4.jar')
    //数据库
    compile files('libs/greendao-1.3.7.jar')
    //json解析
    //    compile project(':netty')
    compile "com.android.support:recyclerview-v7:$SUPPORT_LIB_VERSION"
    compile "com.android.support:design:$SUPPORT_LIB_VERSION"
    compile "com.github.bumptech.glide:glide:$GLIDE"
    compile 'com.commit451:PhotoView:1.2.4'
    compile "com.google.code.gson:gson:$GSON"
    compile 'joda-time:joda-time:2.9.4'
    compile 'com.qiniu:qiniu-android-sdk:7.2.3'
    compile 'org.greenrobot:eventbus:3.0.0'
    compile 'org.xutils:xutils:3.3.38'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.lcodecorex:tkrefreshlayout:1.0.7'
    compile 'com.youth.banner:banner:1.4.9'

    compile 'io.reactivex.rxjava2:rxjava:2.0.7'
    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
}

发布Fir

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Jenkins是一个开源的持续集成和交付工具,它可以帮助开发团队自动化构建、测试和部署软件。下面是Jenkins实现持续集成和交付的一般步骤: 1. 安装和配置Jenkins:首先,你需要在服务器或本地机器上安装Jenkins,并进行基本的配置,如设置管理员账号和插件管理等。 2. 创建项目:在Jenkins中,你可以创建一个或多个项目来管理你的软件开发过程。每个项目都有自己的配置和构建脚本。 3. 配置源代码管理:在项目配置中,你需要指定你的源代码存储库(如Git、SVN等),并设置访问凭证。 4. 设置构建触发器:你可以设置触发器来决定何时触发构建过常见的触发方式包括定时触发、代码提交发、其他项目构建完成触发等。 5. 构建过程:在构建过程中,你可以定义一系列的构建步骤,如编译代码、运行单元测试生成文档等。这些步骤可以通过Jenkins提供的插件来实现。 6. 测试和质量控制:在构建过程中,你可以集成各种测试工具和静态代码分析工具,以确保代码的质量和稳定性。 7. 构建部署:一旦构建成功,你可以将构建产物部署到目标环境中,如测试环境、预发布环境或生产环境。你可以使用Jenkins提供的插件来实现自动化部署。 8. 监控和报告:Jenkins提供了丰富的监控和报告功能,你可以查看构建历史、构建日志、测试结果等信息,以便及时发现和解决问题。 9. 扩展和定制:Jenkins具有强大的扩展性,你可以根据自己的需求安装和配置各种插件,以满足特定的集成和交付需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值