Search code examples
androidandroid-studiogradleandroid-productflavors

Having trouble creating Gradle flavors for different manifests in a single app


I'm following these instructions for creating flavors and Android Studio keeps complaining that it can't find /path/to/my/project/app/src/main

instead of main as per the directions I have a folder called portrait and a folder called landscape in other words

/path/to/my/project/app/src/portrait/[res,java,assets,AndroidManifest.xml]

and

/path/to/my/project/app/src/landscape/[res,java,assets,AndroidManifest.xml]

my gradle file contains:

productFlavors {
    portrait {
        applicationId "com.my.project"
        versionName "1.0-portrait"
    }
    landscape {
        applicationId "com.my.project"
        versionName "1.0-landscape"
    }
}

And yet when I try to MAKE the project I get

Error:Cause: java.io.FileNotFoundException: /Users/me/git/MY/PROJECT/app/src/main/AndroidManifest.xml (No such file or directory)

I've tried noodling with the directory structure, but am unable to clear this complaint. I'm entirely unclear on why it's looking for "main"... where's it getting that directive?


Solution

  • The main sourceSet is not optional, all your java code and resources should go there. Only flavor specific code and resources should go to your flavors. Then Gradle will merge them according to http://tools.android.com/tech-docs/new-build-system/resource-merging

    So, if you don't have main, Gradle will complain.