How can I get BuildConfig.VERSION_NAME from another module in Android?

10.8k Views Asked by At

I want to get VERSION_NAME from domain module. My config is in the main gradle (build.gradle (app)) and I don't know how to get this config. I try to get version name with:

package com.example.domain (domain)

val versionName = com.example.mainmodule.BuildConfig.VERSION_NAME

but BuildConfig is unresolved reference.

package com.example.mainmodule (app)

build.gradle(app)

productFlavors {
    production {
        applicationId "com.example.mainmodule"
        versionCode 107
        versionName '1.9.1'
    }
}

Do I have to create any "dependencies.gradle" or something like that?

1

There are 1 best solutions below

0
On BEST ANSWER

You cannot have cyclic module dependencies. Your app module depends on the domain module so the domain module cannot depend on the app module and therefore cannot access its code.

In this case, you can obtain your app's version name via a Context. See https://stackoverflow.com/a/6593822/101361