Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to specify testApplicationId per flavor in Gradle?

I have two product flavors, and set the testApplicationId like so in build.gradle:

defaultConfig {
    minSdkVersion 8
    targetSdkVersion 19
    testApplicationId 'com.example.testapp'
}

Is it possible to override this testApplicationId in each productFlavor?

I tried overriding the testApplicationId itself in the individual productFlavors, but then the R.class file doesn't get generated, and I get a compile error.

I read about the packageName/applicationId not affecting the R.class file, but I'm not sure if that rule holds for the testApplicationId too.

like image 873
Jeff Brateman Avatar asked Jun 20 '14 18:06

Jeff Brateman


1 Answers

I verify this works as expected in Android Gradle Plugin version 2.3.0

defaultConfig {
    ...   
    testApplicationId 'default'
}

productFlavors {
    first {
        testApplicationId 'first'
    }
    second {
        testApplicationId 'second'
    }
}

android.applicationVariants.all { variant ->
    variant.productFlavors.each {
        def buildType = variant.buildType.name.capitalize()
        println "$it.name$buildType $it.testApplicationId"
    }
}

Give following output:

firstDebug first
firstRelease first
secondDebug second
secondRelease second
like image 61
azizbekian Avatar answered Oct 04 '22 03:10

azizbekian