Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regarding creating flavors in Flutter

I'm making a project in which I've added two flavors dev and prod and I need to make two firebase projects for the same as I want to store different values in the database for different environments.I have made two separate firebase projects for Dev and Prod where I have two google-services.json and two google-info.plist files. To manage them I've added them in two separate folders in app/src named release and development. Whenever I try to run the flavors, it's showing an error. The error is this:

FAILURE: Build failed with an exception.

  • Where: Build file 'flutter_flavors\android\app\build.gradle' line: 58

  • What went wrong: A problem occurred evaluating project ':app'.

    Could not find method flavorDimensions() for arguments [app] on project ':app' of type org.gradle.api.Project.

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 1s Running Gradle task 'assembleDevDebug'... Exception: Gradle task assembleDevDebug failed with exit code 1

like image 980
Hemshree Avatar asked Feb 01 '26 05:02

Hemshree


1 Answers

I had the same issue and solved it by moving the flavor snippets to be a child of the android section, as below. Previously I had it after app{} and had the same error as above.

android {
    compileSdkVersion 30

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        ...
    }
    signingConfigs {
       ...
    }
    buildTypes {
        ...
    }
    flavorDimensions "app"

    productFlavors{
        local {
            dimension "app"
            resValue "string", "app_name", "Removed"
            versionNameSuffix "-dev"
            applicationId "xxxx"
        }
        prod {
            dimension "app"
            resValue "string", "app_name", "Removed"
            applicationId "xxxx"
        }
    }
}
like image 175
ninex Avatar answered Feb 02 '26 21:02

ninex