Android studio gradle flavors not showing in Build Variants
Asked Answered
A

3

45

from what I understand, Android Studio is supposed to show the whole matrix of build variants and flavors in the "Build Variants" panel.

I've created an empty project, with the following build.gradle.

  buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 17
    buildToolsVersion "18.1.0"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 18
    }

    productFlavors {
        productFlavors {
            flavor1 {
                packageName "com.example.flavor1"
                versionCode 20
            }

            flavor2 {
                packageName "com.example.flavor2"
                minSdkVersion 14
            }
        }    }

}

dependencies {
    compile 'com.android.support:appcompat-v7:+'
}

Even so, I only get "Debug" and "Release" as build variants, not the expected "Debugflavor1", "Debugflavor2", etc. Any ideas why this is happening? Is my assumption about the ability to include flavors wrong? If so, how can one build a flavor in Android Studio?

UPDATE, SOLVED: See first comment. You need to manually sync project with the gradle files via "Tools" - "Android" - "sync .."

Appledorf answered 29/10, 2013 at 11:6 Comment(2)
have you "synced with gradle files" and/or restarted AS?Impanel
No, I havent. Now I have. It worked (syncing)! Updated post.Appledorf
C
73

You need to update your project with your gradle changes. In the latest version of Android Studio (currently version 3.1.1) you would accomplish this with:

File -> Sync Project with Gradle Files
Chroma answered 13/4, 2018 at 19:35 Comment(2)
what if that option is grayed out? (btw, graying out is the worst UI ever. leaves user without info on how to solve an issue)Hightension
@Hightension sometimes that means gradle sync activity is already in progress.Sumac
A
50

You need to manually sync project with the gradle files via

Tools -> Android -> Sync Project with Gradle Files

Appledorf answered 29/10, 2013 at 11:15 Comment(1)
That's no longer entirely true, the menu option Sync Project with Gradle Files seems to have moved to the File menu.Topical
P
0

In case it may help somebody: this happened to me before, where syncing the project with the gradle files didn't work, and I couldn't find any other way to select the flavor I wanted to build.

I quit Android Studio and started it again, and the Build Variants panel reappeared. Things were back to normal.

Purism answered 29/1, 2023 at 6:54 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.