Andrew
Andrew

Reputation: 8110

Android gradle product flavors with wearable apps

I'm adding a wearable component to an existing app which uses product flavors in the gradle build to build multiple versions of the app.

I know the package names / application Id's need to match between the mobile and wearable builds, but do I just need to copy the

productFlavors
signingConfigs
buildTypes

from my main mobile app. I'm not quite sure if all of this is needed to get things working or not.

Upvotes: 2

Views: 684

Answers (1)

CodeChimp
CodeChimp

Reputation: 4835

The productFlavors no, unless you are going to do something specific for the wear app with a particular flavor.

The signingConfigs and buildTypes you should copy, the wear app definitely needs to be signed as well. You may adapt the buildType for wear such is enable/disable minify it you want from the main app.

Here's a portion of my own mobile and wear build configs

Mobile

    android {
    compileSdkVersion 20
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "org.codechimp.qrwear"
        minSdkVersion 18
        targetSdkVersion 20
        versionCode 26
        versionName "1.20"
    }

    productFlavors {
        prod {
        }

        dev {
            versionName = android.defaultConfig.versionName + " dev"
        }
    }

    signingConfigs { release }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
    }
    } 

Wear

   android {
    compileSdkVersion 20
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "org.codechimp.qrwear"
        minSdkVersion 20
        targetSdkVersion 20
        versionCode 26
        versionName "1.20"
    }

    signingConfigs { release }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
    }
    }

Upvotes: 4

Related Questions