Search code examples
androidbuild.gradlewear-osandroid-productflavorsandroid-build-type

Android wear project with 3 flavors, 3 buildTypes and 2 applicationIdSuffixes


When I build my project after trying to combine wearApp flavors and buildTypes with applicationIdSuffixes, i get the following error message:

Error:Execution failed for task ':app:handleFirstCustomerTestMicroApk'.
> The main and the micro apps do not have the same package name.

From my app/build.gradle:

buildTypes {
    debug {
        applicationIdSuffix '.debug'
        debuggable true
        embedMicroApp = true
    }
    customerTest {
        applicationIdSuffix '.customertest'
        debuggable true
        embedMicroApp = true
    }
    release {
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        minifyEnabled true
        embedMicroApp = true
    }
}

productFlavors {
    first {
        applicationId 'com.my.app.first'
    }
    second {
        applicationId 'com.my.app.second'
    }
    third {
        applicationId 'com.my.app.third'
    }
}

dependencies {
    firstWearApp project(path: ':wear', configuration: 'firstDebug')
    firstWearApp project(path: ':wear', configuration: 'firstCustomerTest')
    firstWearApp project(path: ':wear', configuration: 'firstRelease')

    secondWearApp project(path: ':wear', configuration: 'secondDebug')
    secondWearApp project(path: ':wear', configuration: 'secondCustomerTest')
    secondWearApp project(path: ':wear', configuration: 'secondRelease')

    thirdWearApp project(path: ':wear', configuration: 'thirdDebug')
    thirdWearApp project(path: ':wear', configuration: 'thirdCustomerTest')
    thirdWearApp project(path: ':wear', configuration: 'thirdRelease')
}

From my wear/build.gradle:

buildTypes {
    debug {
        applicationIdSuffix '.debug'
        minifyEnabled false
    }
    customerTest {
        applicationIdSuffix '.customertest'
        minifyEnabled false
    }
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
productFlavors {
    first {
        applicationId 'com.my.app.first'
    }
    second {
        applicationId 'com.my.app.second'
    }
    third {
        applicationId 'com.my.app.third'
    }
}

android {
    publishNonDefault true
}

I know from these that <buildType>WearApp is possible, but what I really need is <flavor><BuildType>WearApp (which don't seem to be possible right now):

Keeping all the above 9 wearApp dependencies sort of works if I remove the applicationIdSuffixes, but then it still builds one wear apk per buildType no matter what buildType I choose in Android Studio - and I really need the applicationIdSuffixes.

Anyone have a workaround for this? As of today I'm adding and removing wearApp dependencies manually every time I need to change my buildType and / or flavor, and it's not exactly a solution I'm comfortable with in the long run.

EDIT: I didn't notice this at first, but for some reason variants firstDebug, secondDebug and thirdDebug builds just fine with all 9 wearApp dependencies in build.gradle. The error message remains the same for firstCustomerTest, firstRelease, secondCustomerTest, secondRelease, thirdCustomerTest and thirdRelease though. All variants compile the 9 wearApps every time, would be neat to reduce this to 1.


Solution

  • According to This Post

    Try this

    configurations {
        firstDebugWearApp
        firstCustomerTestWearApp
        firstReleaseWearApp
        secondDebugWearApp
     ...//  And all the others
    }
      dependencies {
            firstDebugWearApp project(path: ':wear', configuration: 'firstDebug')
            firstCustomerTestWearApp project(path: ':wear', configuration: 'firstCustomerTest')
            firstReleaseWearApp project(path: ':wear', configuration: 'firstRelease')
    
            secondDebugWearApp project(path: ':wear', configuration: 'secondDebug')
            secondCustomerTestWearApp project(path: ':wear', configuration: 'secondCustomerTest')
            secondReleaseWearApp project(path: ':wear', configuration: 'secondRelease')
    
            thirdDebugWearApp project(path: ':wear', configuration: 'thirdDebug')
            thirdCustomerTestWearApp project(path: ':wear', configuration: 'thirdCustomerTest')
            thirdReleaseWearApp project(path: ':wear', configuration: 'thirdRelease')
        }