The latest version (3.0.0) of the Android Plugin for Gradle has broken its API for manipulating Variant Outputs. This API was used for manipulating files creating during builds (such as AndroidManifest.xml), and has been removed to improve configuration times.
What new APIs are available to manipulate Variant Outputs, and how do they differ to the 2.X APIs?
Build variants are the result of Gradle using a specific set of rules to combine settings, code, and resources configured in your build types and product flavors. Although you do not configure build variants directly, you do configure the build types and product flavors that form them.
The Android Gradle plugin (AGP) is the official build system for Android applications. It includes support for compiling many different types of sources and linking them together into an application that you can run on a physical Android device or an emulator.
Basically, it runs the process that bundles all the resources (images, layout XML files, string resources, etc), your Kotlin or Java source code, any libraries added to your project. Note: It is important to understand that Gradle in itself is not the compiler, linker or bundler itself.
Android Studio uses Gradle, an advanced build toolkit, to automate and manage the build process, while allowing you to define flexible custom build configurations. Each build configuration can define its own set of code and resources, while reusing the parts common to all versions of your app.
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
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With