Android Studio gradle flavors not showing Build Variants correctly

1.9k views Asked by At

I'm having trouble understanding build variants in Android studio. I created an empty project and added product flavors as follows.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.example.myapplication"
        minSdkVersion 16
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    flavorDimensions "version"
    productFlavors {
        demo {
            applicationIdSuffix ".demo"
        }
        full {
            applicationIdSuffix ".full"
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

I synced the project with Gradle files and I only get a demo debut variant. As per my understanding, I should get,

  • demoDebug
  • demoRelease
  • fullDebug
  • fullRelease

Am I following anything wrong? Any help is greatly appreciated.

3

There are 3 answers

0
Ezekiel Sebastine On

Specify the dimension for each flavor in the flavor block like this

flavorDimensions "version"
    productFlavors {
        demo {
            dimension 'version'
            applicationIdSuffix ".demo"
        }
        full {
            dimension 'version'
            applicationIdSuffix ".full"
        }
    }
0
Akki On

Try to manually sync your project with grade files. Use any of the below as per your Android Studio version:

Tools -> Android -> Sync Project with Gradle Files [For older Android Studio version]

File -> Sync Project with Gradle Files [For newer Android Studio versions]

0
Fawad khan On

Try that its work for me: File -> Sync Project with Gradle Files