Search code examples
androidgradleandroid-gradle-pluginandroid-productflavors

Gradle can't see product flavors. How can I add them?


When I try to add a flavor to my project, Gradle simply don't want to sync and even if I sync it I can't see the flavor in Build Variats. What can cause this problem? The project has a few modules, I need to add flavors to the app. My file:

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.24.4'
    }
}

repositories {
    maven { url 'https://maven.fabric.io/public' }
}


def keystorePropertiesFile = "${rootDir}${File.separator}keystore.properties" as File

keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

android {

    dexOptions {
           javaMaxHeapSize "4g"
    }

    compileSdkVersion 25
    buildToolsVersion "25.0.3"

    defaultConfig {
        applicationId ""
        minSdkVersion 21
        targetSdkVersion 25
        versionCode 9999
        versionName "17.2 (9999)"
    }

    productFlavors {
        testFlavor {
            applicationId "com.volodymyr.mobiletest"
        }
    }

    def keystoreFilePath = "${System.properties['user.home']}${File.separator}${keystoreProperties['storeFile']}"
    signingConfigs {
        config {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreFilePath)
            storePassword keystoreProperties['storePassword']
        }
    }

    buildTypes {
        release {

        }
        debug {

        }
    }
    splits {
        abi {
            enable true
            reset()
            include 'armeabi-v7a', 'arm64-v8a'//, 'x86', 'x86_64'
            universalApk true
        }
    }

    lintOptions {
        lintConfig file("lint.xml")

        check "WrongConstant"
        abortOnError true
    }
}

tasks.whenTaskAdded { task ->
    if(task.name.equals("assembleDebug")){
        task.dependsOn(lint)
    }
}
dependencies {
}

I deleted some info from here, like dependencies, id and so on just to show a structure.


Solution

  • The problem was in that that this gradle file is using only for CI. To change gradle config I needed to improve build file at settings.gradle.