0

I downloaded an Android project from github by sunmi printer, to test my pos printer, but when start the build and sync the project it give me this gradle error:

ERROR: Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=debug, filters=[], versionCode=9, versionName=v2.7.2}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.

Here the Gradle:

apply plugin: 'com.android.application'

android {
    signingConfigs {
        release {
            keyAlias 'key0'
            keyPassword '123456'
            storeFile file('../app/temp.jks')
            storePassword '123456'
        }
        debug {
            keyAlias 'key0'
            keyPassword '123456'
            storeFile file('../app/temp.jks')
            storePassword '123456'
        }
    }

    compileSdkVersion 23
    buildToolsVersion "23.0.3"
    defaultConfig {
        applicationId "com.test.printertestdemop1"
        minSdkVersion 21
        targetSdkVersion 23
        versionCode 9
        versionName "v2.7.2"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    lintOptions {
        abortOnError false
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
    }

    android.applicationVariants.all {
        variant ->
            variant.outputs.each {
                output -> output.outputFile = new File(output.outputFile.parent, "PrinterDemo_" + defaultConfig.versionName + "_P1.apk");
            }
    }


}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:23.3.0'
    implementation 'com.android.support:recyclerview-v7:23.3.0'
    implementation 'com.sunmi:sunmiui:latest.release'
    implementation files('libs/core-3.3.0.jar')
}
Jakir Hossain
  • 3,830
  • 1
  • 15
  • 29
Nicola
  • 353
  • 1
  • 2
  • 13
  • comment out `android.applicationVariants.all` code block and it will be working fine. Issue is due to Gradle API changes, setter method on output file object is removed. – Jeel Vankhede Sep 12 '19 at 08:53
  • Set it as answer bro so i can add a positive feedback, it's worked! – Nicola Sep 12 '19 at 09:02

1 Answers1

0

According to This reference, output of variant doesn't provide setter method to set output file name. So it doesn't work with newer version of Gradle API.

Solution: you can use setProperty() method in defaultConfig block to set change base apk name something like,

defaultConfig {
    ....
    setProperty("archivesBaseName", "your apk name here")
    ....
}
Jeel Vankhede
  • 11,592
  • 2
  • 28
  • 58