Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android using new version catalog to add local modules

Tags:

android

gradle

I've created a new project with new libs.versions.toml file, then added a core module, then I've added it as dependency, into app module's build.gradle.kts file using the following code:

implementation(project(":core"))
// other libs using version catalog:
implementation(libs.core.ktx)
implementation(libs.appcompat)
implementation(libs.material)

Everything works fine, now I'm looking for a way to add the :core module inside the libs.versions.toml file and unify adding dependencies, think about :core:data module for instance, and implementation like it:

implementation(libs.local.core.data)
like image 729
Alireza Akbari Avatar asked Jan 24 '26 13:01

Alireza Akbari


1 Answers

Finally, I came up with a solution that can be applied to non-version-catalog projects as well:

1- in your settings.gradle(.kts) add enableFeaturePreview somewhere at the root block of the file:

enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") // <- Add this line

rootProject.name = "MyApplication"
include(":app")
include(":core:data") // <- Sample local module

2- Now you'll be able to have AutoCompilation for all local modules, using the projects keyword. Then use it like this (in app build.gradle(.kts)):

dependencies {
    implementation(projects.core.data) // <- Now add your own module like this

    implementation(libs.androidx.core.ktx)
    // ...
}
like image 189
Alireza Akbari Avatar answered Jan 26 '26 03:01

Alireza Akbari



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!