Build Variant Android studio

Asked

Viewed 154 times

0

Why should my build variants (first image) does not present the options I want for the compilation? In this case I wanted the "mockdebug" as presented in the second image.

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

What do I need to do to get all these choice options on build variants?

build.Gradle

    apply plugin: 'com.android.application'

    android {
        compileSdkVersion 25
        buildToolsVersion "25.0.2"
        defaultConfig {
            applicationId "com.example.projeto"
            minSdkVersion 15
            targetSdkVersion 25
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
        sourceSets {
            main {
                java.srcDirs = ['src/main/java']
            }
            test {
                java.srcDirs = ['src/test/java', 'src/main/java']
                resources.srcDirs = ['src/test/res', 'src/main/res']
            }
            androidTest {
                java.srcDirs = ['src/androidTest/java', 'src/main/java']
                resources.srcDirs = ['src/androidTest/res', 'src/main/res']
            }
        }
    }

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

        // Optional -- Mockito framework
        compile 'com.android.support:appcompat-v7:25.3.0'
        compile 'com.android.support.constraint:constraint-layout:1.0.1'
        compile 'com.prolificinteractive:material-calendarview:1.4.3'
        compile 'com.android.support:support-v4:25.3.0'
        compile 'com.android.support:recyclerview-v7:25.3.0'
        compile 'com.android.support:design:25.3.0'
        compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
        testCompile 'junit:junit:4.12'
        testCompile 'org.mockito:mockito-core:1.10.19'
        testCompile 'org.robolectric:robolectric:3.0'
        androidTestCompile 'junit:junit:4.12'
        androidTestCompile 'com.android.support:support-annotations:25.3.0'

        //Android testing support librarys runner and rules
        androidTestCompile('com.android.support.test:runner:0.5') {
            // Necessary if your app targets Marshmallow (since the test runner
            // hasn't moved to Marshmallow yet)
            exclude group: 'com.android.support', module: 'support-annotations'
        }
        androidTestCompile("com.android.support.test:rules:0.5") {
            exclude group: 'com.android.support', module: 'support-annotations'
        }

        //Expresso UI Testing dependencies
        androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2') {
            exclude group: 'com.android.support', module: 'support-annotations'
        }
        androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.2'

        // add this for intent mocking support
        androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.2'

        // add this for webview testing support
        androidTestCompile 'com.android.support.test.espresso:espresso-web:2.2.2'
    }
  • Also share your build.Radle

  • already added the build.Radle @Leonardo Lima

  • http://www.techotopia.com/index.php/An_Android_Studio_Gradle_Build_Variants_Example

1 answer

2


To add Flavors as in the image, you should add a block of productFlavors in his build.gradle. Within it you can create several Flavors and personalize them.

...
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
productFlavors {
    prod {
        // Configurações de prod
    }
    mock {
        // Configurações de mock
    }
}
...
  • Thank you @Leonardo Lima

Browser other questions tagged

You are not signed in. Login or sign up in order to post.