Question

I'd appreciate any help with this since I'm a noobie w/ gradle. I've got a build script with multiple buildTypes, but it appears settings for one of them are overwriting the others.

Here's my build.gradle:

buildscript {
    repositories {
        mavenCentral()
    }

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

apply plugin: 'android'

dependencies {
    compile project(':facebook-android-sdk-3.0.1:facebook')
    compile project(':google-play-services_lib')
    compile project(':nineoldandroids')
    compile project(':SlidingMenu-master:library')
    compile project(':ViewPagerIndicator')
    compile project(':volley')
    compile project(':windowed-seek-bar')
    compile files('compile-libs/androidannotations-2.7.1.jar', 'libs/Flurry_3.2.1.jar', 'libs/google-play-services.jar', 'libs/gson-2.2.4.jar', 'libs/picasso-1.1.1.jar', 'libs/crittercism_v3_0_11_sdkonly.jar', 'libs/gcm.jar', 'libs/apphance-library.jar')
}

android {
    buildToolsVersion "17.0"
    compileSdkVersion 17

    signingConfigs {
        debug {
            storeFile file('keystores/debug.keystore')
        }

        release {
            storeFile file('keystores/release.keystore')
            storePassword "***"
            keyAlias "***"
            keyPassword "***"
        }
    }

    buildTypes {
        debug {
            sourceSets {
                main {
                    manifest.srcFile 'AndroidManifest.xml'
                    java.srcDirs = ['src', 'normal']
                    resources.srcDirs = ['src']
                    aidl.srcDirs = ['src']
                    renderscript.srcDirs = ['src']
                    res.srcDirs = ['res']
                    assets.srcDirs = ['assets']
                }
            }
        }

        release {
            signingConfig signingConfigs.release

            sourceSets {
                main {
                    manifest.srcFile 'AndroidManifest.xml'
                    java.srcDirs = ['src', 'normal']
                    resources.srcDirs = ['src']
                    aidl.srcDirs = ['src']
                    renderscript.srcDirs = ['src']
                    res.srcDirs = ['res']
                    assets.srcDirs = ['assets']
                }
            }
        }

        utest {
            debuggable true
            signingConfig signingConfigs.debug

            sourceSets {
                main {
                    manifest.srcFile 'utest/AndroidManifest.xml'
                    java.srcDirs = ['src', 'utest']
                    resources.srcDirs = ['src']
                    aidl.srcDirs = ['src']
                    renderscript.srcDirs = ['src']
                    res.srcDirs = ['res']
                    assets.srcDirs = ['assets']
                }
            }
        }
    }
}

The settings for utest are overriding the settings for release and debug. Anybody know why?

Was it helpful?

Solution

Your usage of source sets is wrong. It is not inside each build type closure. They are declared on their own:

android {
    buildTypes {
        debug {
            ...
        }
        release {
            ...
        }
        utest {
            ...
        }
    }

    sourceSets {
        debug {
            ...
        }
        release {
            ...
        }
        utest {
            ...
        }
    }
}

Note that the build types have their own source sets on top of the 'main' source sets. So you shouldn't set all the build type sourceset to use 'src'. You could do

android {
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }
        utest {
            manifest.srcFile 'utest/AndroidManifest.xml'
            java.srcDirs = ['utest']
        }
    }
}

Note that in this case the manifest under utest/AndroidManifest.xml will be merged in the main manifest.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top