在build.gradle中根据自己的需求配置, releaseTime是我自已写的一个获取时间的函数,可以把当前打包的时候追加到文件名中,
也可以判断variant.buildType.name字段的值来生成debug还是release
拼接示例:
output.outputFileName = "Remote${android.defaultConfig.versionName}_${releaseTime()}_debug_nosign.apk"
获取量值使用${字段或函数名},其他字符串可直接写,随意拼接,使用“”把总字符串括起来即可。
apply plugin: 'com.android.application'
def releaseTime()
{
return new Date().format("MMddhhmmss",TimeZone.getTimeZone("UTC"))
}
android {
compileSdkVersion 28
defaultConfig {
applicationId "xxx.xxxxxx.xx"
minSdkVersion 19
//noinspection ExpiredTargetSdkVersion
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
sourceSets {
main {
jniLibs.srcDirs = ['libs']
java.srcDirs = ['src/main/java','src/main/aidl']
}
}
applicationVariants.all {variant ->
variant.outputs.all {output ->
if (variant.buildType.name == "debug") {
output.outputFileName = "Remote${android.defaultConfig.versionName}_${releaseTime()}_debug_nosign.apk"
} else if (variant.buildType.name == "release") {
output.outputFileName = "Remote${android.defaultConfig.versionName}_${releaseTime()}_release_nosign.apk"
}
}
}
}
dependencies {
implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.android.support:appcompat-v7:28.0.0'
}