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