Test Source Directories for Multi Dimension Flavors not recognized in Android Studio

753 views
Skip to first unread message

rgo...@lapresse.ca

unread,
Jun 29, 2015, 3:17:23 PM6/29/15
to adt...@googlegroups.com
I have an issue with test and androidTest source directories for multi-dimension flavors.


Given the following flavors:

    flavorDimensions "taste", "serving"

    productFlavors {
        chocolate {
            flavorDimension "taste"
        }
        strawberry {
            flavorDimension "taste"
        }
        kiwi {
            flavorDimension "taste"
        }
        sample {
            flavorDimension "serving"
        }
        whole {
            flavorDimension "serving"
        }
    }

There are no issues with "non-test" source directories (of any flavor combination) being recognized in Android Studio: 
src/sample, src/whole, src/chocolate, src/strawberry, src/kiwi, 
src/chocolateSample, src/chocolateWhole, src/strawberrySample, src/strawberryWhole, src/kiwiSample, src/kiwiWhole

My issue is with "test" source directories.  
Only single dimension flavors are recognized: src/testSample, src/testWhole, src/testChocolate, src/testStrawberry, src/testKiwi.  
Multi-Dimension flavors are not:  src/testChocolateSample, src/testChocolateWhole, src/testStrawberrySample, src/testStrawberryWhole, src/testKiwiSample, src/testKiwiWhole

This is also the case for the "androidTest" equivalent source directories.


I am under the impression that it is the app.iml which is not correctly generated.  While understanding that we should NEVER do this, the folders are correctly recognized if I were to manually add in the missing entries.

Why should this work with non-test source directories but fail with test source directories?  Is this a known issue or a limitation by the gradle plugin?

I tried researching this, but only found topics related single flavor dimensions for test source folders or mult-dimension flavors for non-test source folders.  There is nothing with regards to multi-dimension flavors for test source folders.

Thanks,

Michal Bendowski

unread,
Jun 30, 2015, 9:58:18 AM6/30/15
to adt...@googlegroups.com
This is fixed in 1.3, you can try it out with 1.3.0-beta3. It also comes with a task called :app:sourceSets that prints out all the source sets that Gradle would recognize. In your case the output look like this.

Additional tip: remember you can use android.variantFilter { ... } to reduce the number of variants. See the DSL reference and old release notes for details.

------------------------------------------------------------
Project :app
------------------------------------------------------------

androidTest
-----------
Compile configuration: androidTestCompile
build.gradle name: android.sourceSets.androidTest
Java sources: [app/src/androidTest/java]
Manifest file: app/src/androidTest/AndroidManifest.xml
Android resources: [app/src/androidTest/res]
Assets: [app/src/androidTest/assets]
AIDL sources: [app/src/androidTest/aidl]
RenderScript sources: [app/src/androidTest/rs]
JNI sources: [app/src/androidTest/jni]
JNI libraries: [app/src/androidTest/jniLibs]
Java-style resources: [app/src/androidTest/resources]

androidTestChocolate
--------------------
Compile configuration: androidTestChocolateCompile
build.gradle name: android.sourceSets.androidTestChocolate
Java sources: [app/src/androidTestChocolate/java]
Manifest file: app/src/androidTestChocolate/AndroidManifest.xml
Android resources: [app/src/androidTestChocolate/res]
Assets: [app/src/androidTestChocolate/assets]
AIDL sources: [app/src/androidTestChocolate/aidl]
RenderScript sources: [app/src/androidTestChocolate/rs]
JNI sources: [app/src/androidTestChocolate/jni]
JNI libraries: [app/src/androidTestChocolate/jniLibs]
Java-style resources: [app/src/androidTestChocolate/resources]

androidTestChocolateSample
--------------------------
Compile configuration: androidTestChocolateSampleCompile
build.gradle name: android.sourceSets.androidTestChocolateSample
Java sources: [app/src/androidTestChocolateSample/java]
Manifest file: app/src/androidTestChocolateSample/AndroidManifest.xml
Android resources: [app/src/androidTestChocolateSample/res]
Assets: [app/src/androidTestChocolateSample/assets]
AIDL sources: [app/src/androidTestChocolateSample/aidl]
RenderScript sources: [app/src/androidTestChocolateSample/rs]
JNI sources: [app/src/androidTestChocolateSample/jni]
JNI libraries: [app/src/androidTestChocolateSample/jniLibs]
Java-style resources: [app/src/androidTestChocolateSample/resources]


// ...

testWhole
---------
Compile configuration: testWholeCompile
build.gradle name: android.sourceSets.testWhole
Java sources: [app/src/testWhole/java]
Java-style resources: [app/src/testWhole/resources]

whole
-----
Compile configuration: wholeCompile
build.gradle name: android.sourceSets.whole
Java sources: [app/src/whole/java]
Manifest file: app/src/whole/AndroidManifest.xml
Android resources: [app/src/whole/res]
Assets: [app/src/whole/assets]
AIDL sources: [app/src/whole/aidl]
RenderScript sources: [app/src/whole/rs]
JNI sources: [app/src/whole/jni]
JNI libraries: [app/src/whole/jniLibs]
Java-style resources: [app/src/whole/resources]

rgo...@lapresse.ca

unread,
Aug 21, 2015, 12:57:23 PM8/21/15
to adt-dev
Hi Michal:

Thanks for your response on this issue.

I have since updated to Android Studio 1.3.1 and this problem remains.
Multi-Flavor Test Source Directories are still not recognized in this version.


Ryan

rgo...@lapresse.ca

unread,
Aug 21, 2015, 1:01:36 PM8/21/15
to adt-dev
Hello Again:

The gradle :app:sourceSets task is also not recognized.

Ryan

rgo...@lapresse.ca

unread,
Aug 21, 2015, 1:37:59 PM8/21/15
to adt-dev
I finally got this working.
It turns out I was compiling against the wrong version of gradle.

dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}

Multi-Flavor Variants are working since this update.

test
testChocolate
testChocolateSample
testChocolateSampleDebug
are all correctly recognized.

testDebug
testChocolateDebug
testSampleDebug
are not recognized (not in as non-test directories) but I understand this to be normal behaviour since we are required to "complete" the variant with the entire multi-flavor (not a partial flavour) when joining to a BuildType.

Thanks,
Ryan
Reply all
Reply to author
Forward
0 new messages