android 自定义 打包文件类型,Android Studio配置打包生成自定义文件名

这篇博客详细介绍了如何配置Android项目的Gradle脚本,实现应用的自动化打包。内容包括设置应用ID、版本号、签名配置、多渠道打包、日期戳命名以及在Debug和Release模式下不同的APK命名规则。此外,还涉及到依赖管理和资源优化的相关设置。
摘要由CSDN通过智能技术生成

https://blog.csdn.net/and_you_with_me/article/details/78799226

## 举例

~~~

apply plugin: 'com.android.application'

// 当前beta版本号

ext.build_number = "beta1";

// 显示的时间格式,形如20171110

def releaseTime() {

return new Date().format("yyyyMMdd", TimeZone.getDefault());

}

android {

useLibrary 'org.apache.http.legacy'

compileSdkVersion 25

buildToolsVersion "27.0.3"

defaultConfig {

applicationId "com.jinnong"

minSdkVersion 14

targetSdkVersion 25

versionCode 6

versionName "1.0.6"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

multiDexEnabled true

}

applicationVariants.all { variant ->

variant.outputs.each { output ->

def outputFile = output.outputFile

if (outputFile != null && outputFile.name.endsWith('.apk')) {

// 显示app名称+当前版本号

def fileName = "TouchH-V${variant.versionName}"

// 如果有渠道,显示渠道名""

if (variant.flavorName!=""){

fileName = fileName + "-${variant.flavorName}"

}

// 加入打包时间

fileName = fileName + "-${releaseTime()}"

// 如果是debug版本,加入beta版本号

if ('debug'.equals(variant.buildType.name)) {

fileName = fileName + "-${build_number}.apk"

} else {

// 如果是release版本,直接显示

fileName = fileName + "-release.apk"

}

output.outputFile = new File(outputFile.parent, fileName)

}

}

}

signingConfigs {

release {

keyAlias 'jnkey'

keyPassword '123456'

storeFile file('C:/Users/Administrator/Desktop/jnkey.jks')

storePassword '123456'

}

}

buildTypes {

release {

//Zipalign优化

zipAlignEnabled true

// 移除无用的resource文件

shrinkResources false

minifyEnabled false

proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

signingConfig signingConfigs.release

}

}

sourceSets {

main {

jniLibs.srcDirs = ['libs']

}

}

splits {

abi {

enable true

reset()

include 'armeabi-v7a'

}

}

packagingOptions {

exclude 'META-INF/rxjava.properties'

exclude 'META-INF/LICENSE.txt'

exclude 'META-INF/NOTICE.txt'

exclude 'META-INF/NOTICE'

exclude 'META-INF/LICENSE'

exclude 'META-INF/DEPENDENCIES'

exclude 'META-INF/notice.txt'

exclude 'META-INF/license.txt'

exclude 'META-INF/dependencies.txt'

exclude 'META-INF/LGPL2.1'

exclude 'META-INF/maven.com.squareup.retrofit2.converter-gson/pom.xml'

}

repositories {

flatDir {

dirs 'libs'

}

}

}

dependencies {

compile fileTree(include: ['*.jar'], dir: 'libs')

androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {

exclude group: 'com.android.support', module: 'support-annotations'

})

compile 'com.android.support:design:25.3.1'

compile 'com.android.support:appcompat-v7:25.3.1'

compile 'com.android.support.constraint:constraint-layout:1.0.2'

testCompile 'junit:junit:4.12'

//compile files('libs/BaiduLBS_Android.jar')

compile files('libs/gson-2.2.4.jar')

compile files('libs/universal-image-loader-1.9.5.jar')

compile 'com.jakewharton:butterknife:7.0.1'

compile 'com.wang.avi:library:2.1.3'

compile 'org.apache.httpcomponents:httpcore:4.4.2'

compile(name: 'AliyunPlayer', ext: 'aar')

compile 'com.android.support:multidex:1.0.1'

compile 'com.tencent.bugly:crashreport:latest.release'

}

~~~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值