How can Variant Outputs be manipulated using the Android Gradle Plugin 3.0.0+?

The changes to outputFiles has now been documented on the Android Developer site.

Essentially, instead of accessing the outputFile directly from the gradle API, the recommendation is to access the directory containing the file instead. The snippet below demonstrates this with a manifest file, but can be applied to other outputFiles as well.

android.applicationVariants.all { variant ->
    variant.outputs.all { output ->
        output.processManifest.doLast {

            String manifestPath = "$manifestOutputDirectory/AndroidManifest.xml"
            def manifestContent = file(manifestPath).getText()

            // Manipulate the file as needed
        }
    }
}