Search code examples
androidgradleandroid-gradle-pluginandroid-buildandroid-build-type

Android - Set two built types to the same source folder


Until recently our Android app only had two buildTypes debug and release. We just added a qa build type and I'd like to have the qa build type point to the debug source code, so I don't have to duplicate the code. Is this possible?

The main difference between qa and debug is Proguard. Our build.gradle file looks like the following:

productFlavors {
        dev {
            minSdkVersion 21
        }
        prod {
            minSdkVersion 14
        }
    }

buildTypes {
    debug { 
        // no proguard
        // use debug code
    }
    qa { 
        // proguard
        // use debug code
    }
    release { 
        // proguard
        // use release code
    }
}

The file structure looks like this:

src
├── debug
│   ├── assets
│   ├── java
│   └── res
├── main
│   ├── java
│   └── res
├── release
│   ├── assets
│   ├── java
│   └── res

I have tried using sourceSets and it doesn't seem to work:

sourceSets {
    qa {
        java.srcDirs = ['src/debug/java']
        res.srcDirs = ['src/debug/res']
    }
}

Solution

  • I was so close. I just needed to add the location of the android manifest file and the assets folder.

    sourceSets {
        qa {
            manifest.srcFile 'src/debug/AndroidManifest.xml'
            java.srcDirs = ['src/debug/java']
            res.srcDirs = ['src/debug/res']
            assets.srcDirs = ['src/debug/assets']
        }
    }