Gradle now smart enough to know which dependencies are used by the flavor being compiled

A while back I remember reading an article talking about how Gradle was being updated to be smart about flavor dependencies and not downloading or processing dependencies not required for the flavor being compiled. At the time I remember thinking, “Oh, that might be nice. Then F-Droid can get rid of all those sed commands in their metadata files.” I recently went looking for that article and couldn’t fine it. Neither could I easily find similar information in Gradle’s release notes. However, the most recent build of Privacy Browser indicates that such is the case.

First, a little bit of background. Privacy Browser has two flavors, standard and free. Standard is the flavor built for F-Droid. Free is feature-identical except for the addition of a banner ad across the bottom of the screen. When I first released Privacy Browser Free I used Google’s AdMob with a dependency similar to the following.

freeCompile ''

This required adding the following line to the metadata:

prebuild: sed -i -e '/play-services/d' build.gradle

After a while, Google started recommending that apps using AdMob switch to the Firebase backend, which I did with the 1.12 release. This caused my build on F-Droid to fail until the prebuild line was updated to be:

prebuild: sed -i -e '/firebase/d' build.gradle

However, recently Google started recommending that apps that only use AdMob ads and not any of the other features of Firebase switch back to using the play-services-ads dependency, which I did with the 3.7 release with the following freeImplementation line:

freeImplementation ''

I was intending to update the metadata file when the build failed after it was populated for the 3.7 release. But, the build succeeded. This leads me to believe that in many cases the sed lines that exist in the metadata files are now no longer needed and can be removed.


I can confirm this: freeImplementation would be skipped unless you specify gradle: free in the YAML build block. At least that was the case for many apps I’ve merged in the past months. sed is still needed for several other cases, though…

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.