1

I have a library project with 2 flavors

configurations {
    // Initializes placeholder configurations that the Android plugin can use when targeting
    // the corresponding variant of the app.
    internalDebug {}
    internalRelease {}
    externalDebug {}
    externalRelease {}
}

flavorDimensions("outerInner")
productFlavors {
    internal{dimension "outerInner"}
    external{dimension "outerInner"}
}

No custom sourceSets defined in build.gradle

For one of the flavor I have custom layouts inside:

enter image description here

All other sources should be from main.

When I include this libaryr to app:

implementation project(path: ':sdk', configuration: 'internalDebug')

There no classes of the sdk library at all and all imports marks as red.

The question is why there is no sources from main's library folders in app?

dilix
  • 3,761
  • 3
  • 31
  • 55
  • Do you have *product flavors* in **main app module**? – Jeel Vankhede Nov 14 '19 at 12:01
  • @JeelVankhede no, I guess it should **not** be a problem since I explicitly set configuration I want to use. – dilix Nov 14 '19 at 12:04
  • I had in my case *(Multi flavor library -> multi flavor app with different names of product flavors)*, try this in library gradle `publishNonDefault true` in `android {}` block. – Jeel Vankhede Nov 14 '19 at 12:05
  • @JeelVankhede nope, doesn't help... could you share you build.gradle for library and main app? – dilix Nov 14 '19 at 12:07
  • Sorry @dilix, I can not share Gradle files right now because it's no longer accessible by me, but here is the solution that I referred at that time which was helpful for me : https://stackoverflow.com/a/36828415/10271334. I hope it helps! – Jeel Vankhede Nov 14 '19 at 12:13

1 Answers1

1

Finally I got the solution as defining missingDimensionStrategy in app's build.gradle.

// Specifies a sorted list of flavors that the plugin should try to use from
// a given dimension. The following tells the plugin that, when encountering
// a dependency that includes a "minApi" dimension, it should select the
// "minApi18" flavor. You can include additional flavor names to provide a
// sorted list of fallbacks for the dimension.
missingDimensionStrategy 'outerInner', 'internal'

It means that if during the build gradle will found a dependency that have the flavorDimension outerInner it should use internal for that.

After this is applied I could simply include

implementation project(path: ':sdk')

For each app's buildType it will use appropriate debug or relese SDK build and fallback to internal implementation.

External implementation is delivered to maven with artifact bundleExternalDebugAar setting.

dilix
  • 3,761
  • 3
  • 31
  • 55
  • Thanks. This is useful for adding a dependency on a project without defining flavors as in the library `missingDimensionStrategy 'your_dimension', 'your_default_flavor'`. – JCarlosR Aug 15 '22 at 23:56