Error: (81, 0) getMainOutputFile is no longer supported. Use getOutputFileName if you need to specify a file name for output.

I am trying to customize the build process using below code

   android.applicationVariants.all { variant ->
            def appName = "MyApplication.apk"

            variant.outputs.each { output ->
                output.outputFile = new File(output.outputFile.parent, appName)
            }
        }

But from android studio 3.0 it doesn’t work, I get below the error

Error: (81, 0) getMainOutputFile is no longer supported. Use getOutputFileName if you need to specify a file name for output.

+4
source share
2 answers

Just do it like this:

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig getSigningConfig()
        android.applicationVariants.all { variant ->
            def date = new Date();
            def formattedDate = date.format('dd MMMM yyyy')
            variant.outputs.all {
                def newApkName
                newApkName = "MyApp-${variant.versionName}, ${formattedDate}.apk"
                outputFileName = newApkName;
            }
        }
    }
}
+2
source

This is described in the Android Gradle v3 Plugin Migration Guide :

API- Variant . - , APK , :

// 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 = "${project.name}-${variant.name}-${variant.versionName}.apk"
    }
}

api , .

+1

Source: https://habr.com/ru/post/1679117/


All Articles