//gradle.properties #sec:decoupled_projects #org.gradle.parallel=true APP_VERSION=1.0.1 IS_JENKINS=true BUILD_TIME='' //build.gradle apply plugin: 'com.android.application' def getDate() { def date = new Date() def formattedDate = date.format('yyyy-MM-dd-HH-mm') return formattedDate } def verCode = 14 android { compileSdkVersion 25 buildToolsVersion "25.0.0" defaultConfig { applicationId "com.zyyoona7.autobuildtest" minSdkVersion 15 targetSdkVersion 23 testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" multiDexEnabled true versionCode verCode versionName APP_VERSION } signingConfigs { signingConfig { //由于本地打包使用的是本机上的KeyStore //而Jenkins打包用的是服务器上的KeyStore //两个路径不一样 if("true".equals(IS_JENKINS)){ storeFile file("服务器上KeyStore的路径") }else { storeFile file(STORE_FILE_PATH) } keyAlias KEY_ALIAS keyPassword KEY_PASSWORD storePassword STORE_FILE_PASSWORD } } buildTypes { release { minifyEnabled true zipAlignEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' signingConfig signingConfigs.signingConfig } debug { } } dexOptions { javaMaxHeapSize "2g" } //渠道Flavors productFlavors { wandoujia { manifestPlaceholders = [UMENG_CHANNEL_VALUE: "wandoujia"] } xiaomi { manifestPlaceholders = [UMENG_CHANNEL_VALUE: "xiaomi"] } } //修改生成的apk名字及输出文件夹 applicationVariants.all { variant -> variant.outputs.each { output -> //新名字 def newName //时间戳 def timeNow //输出文件夹 def outDirectory //是否为Jenkins打包,输出路径不同 if ("true".equals(IS_JENKINS)) { //Jenkins打包输出到服务器路径 timeNow = BUILD_TIME //BUILD_PATH为服务器输出路径 outDirectory = BUILD_PATH //AutoBuildTest-v1.0.1-xiaomi-release.apk newName = 'AutoBuildTest-v' + APP_VERSION + '-' + variant.productFlavors[0].name + '-' + variant.buildType.name + '.apk' } else { //本机打包输出在本机路径 timeNow = getDate() outDirectory = output.outputFile.getParent() if ('debug'.equals(variant.buildType.name)) { newName = "AutoBuildTest-v${APP_VERSION}-debug.apk" } else { //AutoBuildTest-v1.0.1-xiaomi-release.apk newName = 'AutoBuildTest-v' + APP_VERSION + '-' + variant.productFlavors[0].name + '-' + variant.buildType.name + '.apk' } } output.outputFile = new File(outDirectory+'http://www.likecs.com/'+timeNow, newName) } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:25.0.0' testCompile 'junit:junit:4.12' }
Android Jenkins+Git+Gradle持续集成 (3)
内容版权声明:除非注明,否则皆为本站原创文章。