Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: FlavorDimension doesn't support more than one dimension, or at least Android Studio doesn't #1590

Open
3 tasks done
Edodums opened this issue Sep 3, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@Edodums
Copy link

Edodums commented Sep 3, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Is there a StackOverflow question about this issue?

  • 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

  • I agree to follow this project's Code of Conduct
@Edodums Edodums added the bug Something isn't working label Sep 3, 2024
@Jaehwa-Noh
Copy link
Contributor

Could you share your code snippet and screenshot?

@Edodums
Copy link
Author

Edodums commented Sep 3, 2024

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

@Jaehwa-Noh
Copy link
Contributor

@Edodums
You can see the flavor in here.
image
Is this what you want?

@Edodums
Copy link
Author

Edodums commented Sep 4, 2024

Yep, this is the problem I was talking about. It defies the utility of having gradle plugin and build logic.

@Jaehwa-Noh
Copy link
Contributor

Jaehwa-Noh commented Sep 4, 2024

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

@Edodums
Copy link
Author

Edodums commented Sep 4, 2024

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

@Jaehwa-Noh
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants