nowinandroid
nowinandroid copied to clipboard
[Bug]: FlavorDimension doesn't support more than one dimension, or at least Android Studio doesn't
Is there an existing issue for this?
- [X] I have searched the existing issues
Is there a StackOverflow question about this issue?
- [X] I have searched StackOverflow
What happened?
Try to define a second FlavorDimension ( for example "environment" ) , Add a flavor, called for "prod”. Sync, you'll notice no problem is there, build variant are correctly created. Try now to go to "project structure" and you'll notice that it will tell you that Flavor "x" has no dimension, for each module and for each flavor.
I don't know why this happens but it's making me mad, because it's a recent problem, and it doesn't let me to use succesfully "build project"
Relevant logcat output
No response
Code of Conduct
- [X] I agree to follow this project's Code of Conduct
Could you share your code snippet and screenshot?
Like for example
package com.google.samples.apps.nowinandroid
import com.android.build.api.dsl.ApplicationExtension
import com.android.build.api.dsl.ApplicationProductFlavor
import com.android.build.api.dsl.CommonExtension
import com.android.build.api.dsl.ProductFlavor
@Suppress("EnumEntryName")
enum class FlavorDimension {
contentType,
another
}
// The content for the app can either come from local static data which is useful for demo
// purposes, or from a production backend server which supplies up-to-date, real content.
// These two product flavors reflect this behaviour.
@Suppress("EnumEntryName")
enum class NiaFlavor(val dimension: FlavorDimension, val applicationIdSuffix: String? = null) {
demo(FlavorDimension.contentType, applicationIdSuffix = ".demo"),
prod(FlavorDimension.contentType),
banana(FlavorDimension.another, applicationSuffix=".another")
}
fun configureFlavors(
commonExtension: CommonExtension<*, *, *, *, *, *>,
flavorConfigurationBlock: ProductFlavor.(flavor: NiaFlavor) -> Unit = {},
) {
commonExtension.apply {
FlavorDimension.values().forEach { flavorDimension ->
flavorDimensions += flavorDimension.name
}
productFlavors {
NiaFlavor.values().forEach { niaFlavor ->
create(niaFlavor.name) {
dimension = niaFlavor.dimension.name
flavorConfigurationBlock(this, niaFlavor)
if (this@apply is ApplicationExtension && this is ApplicationProductFlavor) {
if (niaFlavor.applicationIdSuffix != null) {
applicationIdSuffix = niaFlavor.applicationIdSuffix
}
}
}
}
}
}
}
The fact is that the Build Variants are correctly created, but in the "Project Structure" menu the error "Flavor banana has no dimension" pops up, for each module. I think It's a gradle / Android Studio issue, I've tried for two days in multiple ways the only way is to literally copy paste directly in each build file the productFlavors { create(banana) ..... } , but it wasn't a problem at least until February.
The build project obviously doesn't work , it seems that something has stop to function, so I kinda think and pull the fault to Android Studio. No amount of Invalidate Cache , clean works against this, so
@Edodums
You can see the flavor in here.
Is this what you want?
Yep, this is the problem I was talking about. It defies the utility of having gradle plugin and build logic.
I'm not fully understand this issue, but if the problem is related with Android Studio. Here is not a right place. What about you make an issue ticket over Android Studio? https://developer.android.com/studio/report-bugs
I'll report it but, as you can see that "invalid" I don't get why that happens. Also because as you can see the BuildVariants in the little section under the "Project files" are actually correctly created
I can see it, It is hard to know what had been happened in the behind scene. If you can, could you share the issue tracker link at here? I also interested in.