Could not find property 'zipAlignEnabled' on com.android.build.gradle.internal.api.ApplicationVarian

针对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)
                    }
                }
            }

效果:

Could not find property 'zipAlignEnabled' on com.android.build.gradle.internal.api.ApplicationVarian_第1张图片


参考链接:

http://stackoverflow.com/questions/27222688/could-not-find-property-zipalignenabled-on-com-android-build-gradle-internal-a

http://stackoverflow.com/questions/25997866/gradle-warning-variant-getoutputfile-and-variant-setoutputfile-are-deprecat


你可能感兴趣的:(android,gradle,Build,Studio)