天天看點

Cannot set the value of read-only property 'outputFile'

今天把Android studio 升到3.0以後,把原先的工程導入之後,出現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.就是後來打包命名的gradle出現了問題

舊版本

AS 2.3.1的版本

android.applicationVariants.all { variant ->
    variant.outputs.each { output ->
        def outputFile = output.outputFile
        if (outputFile != null && outputFile.name.endsWith('.apk')) {
            //這裡修改apk檔案名
            def fileName = outputFile.name.replace("app", "doctor")
            output.outputFile = new File(outputFile.parent, fileName)
        }
    }
}      

新版本

AS 3.1.2

android.applicationVariants.all { variant ->
    variant.outputs.all {
        outputFileName = "doctor.apk"
    }
}      

希望可以幫助到大家

繼續閱讀