你的位置:首页 > 操作系统

[操作系统]Gradle Android客户端程序打包


  

一、前言
  
二、简单项目Gradle打包脚本配置

//Gradle build脚本配置buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:0.12.+' }}//项目配置版本号,与Apk输出目录ext.appVersionCode = 2ext.appVersionName = "2.0"ext.appReleaseDir = "/Users/freedoms/Desktop/release"apply plugin: 'com.android.application'//获取时间戳def getDate() { def date = new Date() def formattedDate = date.format('yyyyMMdd') return formattedDate}//程序包配置android { compileSdkVersion 19 buildToolsVersion "21.1.2" sourceSets { main { manifest.srcFile 'AndroidManifest.
//打包开始时,lint运行将有可能发生错误,当有异常发生时,此设置将忽略警告,继续运行脚本,若忽略,打包过程将被强行终止
lintOptions {
  abortOnError false
}
  //签名配置  signingConfigs {  		myConfig {    	storeFile file("/Users/freedoms/Desktop/产品需求文档/android.keystore")    	storePassword "123123"    	keyAlias "android.keystore"    	keyPassword "123123"  		} 	}
 //混淆配置 buildTypes{ release { signingConfig signingConfigs.myConfig runProguard true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt' } }
  //自定义配置 productFlavors { //百度 baidu{ manifestPlaceholders = [UMENG_CHANNEL_VALUE:"baidu_android_channel",BAIDU_CHANNEL_VALUE:"baidu_baidu_android_channel"] } //360 "360"{//若配置渠道名为数字开头,必须加引号 manifestPlaceholders = [UMENG_CHANNEL_VALUE:"360_android_channel",BAIDU_CHANNEL_VALUE:"baidu_360_android_channel"] } }
   //打包重命名算法,输出XXX_Android_v2.0_20160127_baidu.apk到脚本前配置的输出目录当中 android.applicationVariants.all { variant -> def file = variant.outputFile if(variant.buildType.name.equals('release')){ variant.outputFile = new File(appReleaseDir + '/','XXX_Android_v' + appVersionName +getDate()+ '_' + variant.productFlavors[0].name + '.apk') } }}
//编码配置tasks.withType(Compile) { options.encoding = "UTF-8" }