以前的代码:
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 此问题解决
修改之后完整代码
在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\'
}
}
}
版权声明
本文仅代表作者观点,不代表百度立场。
本文系作者授权百度百家发表,未经许可,不得转载。





