Search code examples
gradleandroid-jetpack-composegradle-kotlin-dsl

How to add gradle dependency when buildFeature.compose = true?


Each time when a module needs enabled compose I have to do the following steps:

  1. android.buildFeatures.compose = true
  2. add a set of dependencies androidx.compose.xxx

I have a common build script and now I want to simplify usage of compose in my modules.

I would like to simplify that process by automatically add all compose dependencies if child module enables compose by android.buildFeatures.compose = true

How can I do it?


Solution

  • Something like this is done in the Now in android example app. They are using gradle plugins to do that, you can see common logic for all jetpack compose modules here: AndroidCompose.kt. There is a readme that explains it pretty well.