针对1.0中新版Gradle已经做了以下替换:
Renamed a few properties to make things more consistent.
BuildType.runProguard -> minifyEnabled
BuildType.zipAlign -> zipAlignEnabled
BuildType.jniDebugBuild -> jniDebuggable
BuildType.renderscriptDebug -> renderscriptDebuggable
ProductFlavor.renderscriptSupportMode -> renderscriptSupportModeEnabled
ProductFlavor.renderscriptNdkMode -> renderscriptNdkModeEnabled
if (variant.zipAlignEnabled) {
def file = variant.outputFile
def fileName = file.name.replace("apk/" + applicationId + "-V" + versionName + "-" + versionCode + "-" + variant.name + "-" + buildTime() + "-unaligned.apk")
variant.outputFile = new File(file.parent, fileName)
}
但还是会报
Could not find property 'zipAlignEnabled' on com.android.build.gradle.internal.api.ApplicationVarian
修改方案:
if (variant.buildType.zipAlignEnabled) {
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
def fileName = "apk/" + applicationId + "-V" + versionName + "-" + versionCode + "-" + variant.name + "-" + buildTime() + "-unaligned.apk"
output.outputFile = new File(outputFile.parent, fileName)
}
}
ldTime() + ".apk");
} else {
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
def fileName = "apk/" + applicationId + "-V" + versionName + "-" + versionCode + "-" + variant.name + "-" + buildTime() + ".apk"
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
效果:
参考链接: