Fix Gradle sync failed: Cannot set the value of read-only property 'outputFile' for.....

在升级android studio到3.0.X版本时,出现同步错误。

Gradle sync failed: Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=debug, filters=[]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.
		Consult IDE log for more details (Help | Show Log) (1m 37s 807ms)
这是由于gradle升级至4.4版本后,对部分API进行了调整的缘故。

 each() 和 outputFile() 方法分别修改为all() 和 outputFileName。

在原有gradle文件中,

        variant.outputs.each { output ->
            output.outputFile = new File(output.outputFile.parent, "APPName" + "-" + buildType.name + "-v" +
                    defaultConfig.versionName + "-" + defaultConfig.versionCode + ".apk");
        }
    }

修改后的相应内容为

android.applicationVariants.all { variant ->
        variant.outputs.all {
            outputFileName = "cep" + "-" + buildType.name + "-" + releaseTime() + "-v" + defaultConfig.versionName + "-" + defaultConfig.versionCode + ".apk";
        }
    }


猜你喜欢

转载自blog.csdn.net/daihuimaozideren/article/details/79799946