Closed clhols closed 7 years ago
The flavors of the project are being introduced within flavors/base/src. In order to move the created flavors forward throughout the module dependency graph they currently have to be referenced throughout the depending modules. This is not specific to instant apps, but to the implementation of this sample.
Ok, that calms me down. I started with the flavor sample, because my app has flavors. But from your description I realize that the sample is for flavors of feature modules and not app flavors. I will to add an app flavor to the "hello-feature-module" sample and see how that works out. Thanks for clarifying.
You're welcome.
If I add the following product flavors to "hello-feature-module":
flavorDimensions "pricing"
productFlavors {
paid {
applicationIdSuffix = '.free'
}
free {
applicationIdSuffix = '.paid'
}
}
I get the following error:
* What went wrong:
Could not determine the dependencies of task ':features:base:processReleaseFeatureManifest'.
> Could not resolve all task dependencies for configuration ':features:base:releaseFeatureMetadataValues'.
> Could not resolve project :installed.
Required by:
project :features:base
> Cannot choose between the following configurations of project :installed:
- freeReleaseMetadataElements
- paidReleaseMetadataElements
All of them match the consumer attributes:
- Configuration 'freeReleaseMetadataElements':
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Metadata' and found compatible value 'Metadata'.
- Required com.android.build.gradle.internal.dependency.BuildTypeAttr 'release' and found compatible value 'release'.
- Found com.android.build.gradle.internal.dependency.VariantAttr 'freeRelease' but wasn't required.
- Found pricing 'free' but wasn't required.
- Configuration 'paidReleaseMetadataElements':
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Metadata' and found compatible value 'Metadata'.
- Required com.android.build.gradle.internal.dependency.BuildTypeAttr 'release' and found compatible value 'release'.
- Found com.android.build.gradle.internal.dependency.VariantAttr 'paidRelease' but wasn't required.
- Found pricing 'paid' but wasn't required.
How do I fix this without defining flavors in the base and feature modules?
I guess that it is due to the reverse dependency from the features back to the 'installed' application. And now that the application has flavors, Gradle can't choose as described here: https://www.youtube.com/watch?v=jp_Dv4VjVWE&feature=youtu.be&t=1320
I then tried to set flavorSelection in the feature modules, but then get:
Error:(30, 0) Could not find method flavorSelection() for arguments [pricing] on object of type com.android.build.gradle.FeatureExtension.
So the reverse dependency forces me to create flavors in the feature modules and that is what I want to avoid. Why is the reverse dependency needed?
@keyboardsurfer FYI
@clhols I'm stuck with the same issue, how did you solve it?
@droidster I didn't. @keyboardsurfer is your best bet for at solution.
@clhols I "solved" it by adding the same flavors, paid and free in my case in the feature module and the instant app module. They are just empty flavors with no config. Only the installed app module flavors have any purpose. Thanks for replying. :)
You can also use missingDimensionStrategy
for modules that don't specify the flavor you're interested in building.
In this sample you could use:
defaultConfig {
missingDimensionStrategy 'pricing', 'free'
}
to set it as default for the instant build.
missingDimensionStrategy
takes two arguments. So in my example from earlier it must be set to missingDimensionStrategy 'pricing', 'free'
in defaultConfig
in :features:base.
Thanks, updated my comment accordingly.
This feature is annoying. The productFlavor is infecting. I have multi-level modules, I'm forced to add empty productFlavor all over the build.gradles. Didn't find way to easy the boilerplate.
Same thing here but using dynamic feature module, I have lost 3 hours trying to build my project. I'm having to put the same productFlavors from :app into my feature module and the flavorDimensions.
Google has any plans to make this better?
When having a project that builds multiple flavors you just have to specify productFlavors in app/build.gradle and not in your library. But with instant apps you when have to specify all flavors in all feature modules? Just to set the dimension? Why should feature "hallo" and "bye" care if the app comes in free and paid variants. It seems as that is very redundant. I guess you could but the productFlavors in a project level gradle file and refer to that with "apply from:" in the feature modules and the instant module, but it still looks ugly I think. Is this "by design" in the new Android gradle plugin?