Android Gradle 3.0.0-alpha2 plugin, Unable to set read-only property value 'outputFile'

i used this code

applicationVariants.all { variant -> variant.outputs.each { output -> def SEP = "_" def flavor = variant.productFlavors[0].name def buildType = variant.variantData.variantConfiguration.buildType.name def version = variant.versionName def date = new Date() def formattedDate = date.format('ddMMyy_HHmm') def newApkName = PROJECT_NAME + SEP + flavor + SEP + buildType + SEP + version + SEP + formattedDate + ".apk" def file = new File(newApkName) output.outputFile = file } } 


change the apk file name when creating a new apk, but since I am using Android Studio 3.0 Canary 2 , this error appears:
Unable to set read-only property value 'outputFile' ....

+79
android-studio android-gradle
May 29 '17 at 9:39 a.m.
source share
8 answers

As the Android 3.0 Plugin Migration Guide offers:

  • Use all() instead of each()
  • Use outputFileName instead of output.outputFile if you only change the file name (this is your case)

Example from the manual:

 // If you use each() to iterate through the variant objects, // you need to start using all(). That because each() iterates // through only the objects that already exist during configuration timeβ€” // but those object don't exist at configuration time with the new model. // However, all() adapts to the new model by picking up object as they are // added during execution. android.applicationVariants.all { variant -> variant.outputs.all { outputFileName = "${variant.name}-${variant.versionName}.apk" } } 
+191
May 30 '17 at 14:43
source share

See below:

 applicationVariants.all { variant -> variant.outputs.all { output -> def newApkName = applicationId + "-" + variant.versionName + "(" + variant.versionCode + ")" + ".apk"; outputFileName = new File("${project.projectDir}/../outputs/apks/" + variant.name, newApkName); } } 
+6
Aug 15 '17 at 9:14
source share

Below code works for me on android studio canary 3.0.0-alpha3

 android.applicationVariants.all { variant.outputs.all { def newApkName newApkName = "APPLICATION_NAME-" + defaultConfig.versionName + "-" + defaultConfig.versionCode".apk" outputFileName = newApkName; } } 

This is apk file name change

+4
Jun 16 '17 at 9:10
source share

This is a complete example of this question.

Only you have to insert into your gradle 3. 0+ after productFlavours

  android.applicationVariants.all { variant -> variant.outputs.all { def SEP = "_" def flavor = variant.productFlavors[0].name def buildType = variant.variantData.variantConfiguration.buildType.name def version = variant.versionName def versionCode = variant.versionCode def date = new Date(); def formattedDate = date.format('ddMMyy_HHmm') outputFileName = "${flavor}${SEP}${buildType}${SEP}${version}${SEP}${versionCode}${SEP}${formattedDate}.apk" } } 
+2
Jan 18 '18 at 16:59
source share

I founded gradle 3.0 no longer works. source link

However, more complex tasks associated with accessing outputFile objects no longer work. This is because, at the configuration stage, specific tasks are no longer created. This leads to the fact that the plugin does not know all of its outputs in front, but it also means faster setup time.

then I used the gradlew command to compile project.and cp apk output to the specified path

On the Execute command line, I placed the command below.

 ./gradlew clean assembleDebug cp $WORKSPACE/app/build/outputs/apk/debug/*.apk $WORKSPACE/JenkinsApk 
0
Oct 31 '17 at 7:48
source share

I have the same problem. Error "Unable to set read-only property value 'outputFile' ...." "

Therefore, I changed the version of the Android plug-in repository to 2.3.3 in the Project Structure window. It works now and the error has disappeared.

Project structure

Later do Clean and Rebuild for the project and so that it

Hope this will be helpful for you.

0
Jun 19 '18 at 14:31
source share

It has been a year and a half since the question was asked, but maybe this will help someone (for example, me) who will be the first to find this post. I believe that the answer to changing the file name and directory was answered here .

 applicationVariants.all { variant -> variant.outputs.all { output -> def relativeRootDir = output.packageApplication.outputDirectory.toPath() .relativize(rootDir.toPath()).toFile() output.outputFileName = new File( "$relativeRootDir/release", newOutputName) } } 
0
Dec 13 '18 at 0:37
source share

After upgrading to Android Studio 3.0.0 and using the new gradle, now apks output will be distributed in directories by name and type of flavor.

-one
Oct 31 '17 at 11:04 on
source share



All Articles