赞
踩
工作记录:
在app的build.gradle文件的android节点下添加以下代码:
- applicationVariants.all { variant ->
- variant.outputs.all {
- if (!variant.buildType.isDebuggable()) {
- variant.getPackageApplication().outputDirectory = new File(project.rootDir.absolutePath + "/apk")
- }
- outputFileName = "nanchong_APP${defaultConfig.versionName}_${releaseTime()}_${variant.buildType.name}.apk"
-
- }
- }
配置签名和打包类型自动使用签名文件打包的代码如下(在app的build.gradle文件的android节点下):
- signingConfigs {
- release {
- keyAlias 'commonsign'
- keyPassword 'haocangapp'
- storeFile file('D:/ProjectWorkSpace/taizhou/commonSign.jks')
- // storeFile file('D:/AndroidStudio/Mango/commonSign.jks')
- storePassword 'haocangapp'
- }
- loadSigningConfigs() //加载签名信息
- }
- buildTypes {
- debug {
- // buildConfigField("String","ADDRESS_IP","\"http://192.168.2.199/\"")
- buildConfigField("String","ADDRESS_IP","\"http://122.226.149.162:801/\"")
- }
- release {
- minifyEnabled false
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
- buildConfigField("String","ADDRESS_IP","\"http://122.226.149.162:801/\"")
- }
- }
-
- def releaseTime() {
- return new Date().format("yyyyMMdd", TimeZone.getTimeZone("GMT+08:00"))
- }
-
- def loadSigningConfigs() {
- def Properties props = new Properties()
- def propFile = file('../signing.properties') //加载properties文件
- if (propFile.canRead()) {
- props.load(new FileInputStream(propFile))
- if (props != null && props.containsKey('RELEASE_STORE_FILE') && props.containsKey('RELEASE_STORE_PASSWORD') &&
- props.containsKey('RELEASE_KEY_ALIAS') && props.containsKey('RELEASE_KEY_PASSWORD')) {
- android.signingConfigs.release.storeFile = file(props['RELEASE_STORE_FILE'])
- android.signingConfigs.release.storePassword = props['RELEASE_STORE_PASSWORD']
- android.signingConfigs.release.keyAlias = props['RELEASE_KEY_ALIAS']
- android.signingConfigs.release.keyPassword = props['RELEASE_KEY_PASSWORD']
- } else {
- android.buildTypes.release.signingConfig = null
- }
- } else {
- android.buildTypes.release.signingConfig = null
- }
- }
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreBlack.png)
signing.properties文件内容如下:
- RELEASE_KEY_PASSWORD=xxxx
- RELEASE_KEY_ALIAS=xxxx
- RELEASE_STORE_PASSWORD=xxxx
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。