studio3.1.4的版本遇到的问题 之前我的代码是这样写的,报了两个问题如下:
applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
// 输出apk名称为wandoujia_v1.0.0.1320_20150115.apk
def fileName = "${variant.productFlavors[0].name}_v${defaultConfig.versionName}.${defaultConfig.versionCode}_${releaseTime()}.apk"
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
报了两个问题
1. Absolute path are not supported when setting an output file name
将”outputFile.parent” 修改为相对路径解决此问题
修改为 :outputFileName = new File(“../../../release/”, fileName)
2.Cannot set the value of read-only property ‘outputFile’ for ApkVariantOutputImpl_Decorated
将each 修改为all
output.outputFile 修改为outputFileName 此问题解决
修改之后完整代码
输出样式 : v1.0.1_20180910
相关代码:
在app的build.gradle中配置
android {
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
applicationVariants.all { variant ->
variant.outputs.all { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
//输出名称为 v1.0.1_20180910
def fileName = "v${defaultConfig.versionName}.${defaultConfig.versionCode}_${releaseTime()}.apk"
outputFileName = new File("../../../release/", fileName)
}
}
}
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}