Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Gradle main project and submodule flavors

I have a main Android project, which depends on a submodule.

The main project has flavors defined in Gradle.

Also the submodule has a few flavors defined. This should be logical - to be able to have flavors for both projects. For example in the submodule:

productFlavors {
    flavorName {
    }
}

But this does not work - The build crashes with a message saying that submodule resources are not found in the main project. But when I delete flavors from the submodule, everything works fine.

It seems to mix the build order when flavors are defined for the subproject, could this be true?

What am I missing? Is it even possible for both main and sub projects to have flavors?

like image 540
Demonick Avatar asked Oct 17 '25 00:10

Demonick


1 Answers

When you reference your sub-modules as dependencies in your build.gradle file, be sure to specify which flavor of the sub-module you are referring to:

dependencies {
    compile project(path: ':module', configuration:'yourflavorDebug')
}

then be sure in your build variants, you are building the flavor your main module depends on, and everything should work out.

Also be sure the libraries you are referencing have this in their build.gradle as well:

publishNonDefault true

Without it android studio doesn't seem to be able to depend on flavors of that module. More information here.

like image 122
Kevin DiTraglia Avatar answered Oct 19 '25 13:10

Kevin DiTraglia



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!