Android wear 项目有 3 种风格、3 种构建类型和 2 种 applicationIdSuffixes

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

当我尝试将 wearApp 风格和 buildTypes 与 applicationIdSuffixes 组合后构建我的项目时,我收到以下错误消息:

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

来自我的 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')
}

来自我的 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
}

我从这些知道<buildType>WearApp是可能的,但我真正需要的是<flavor><BuildType>WearApp(现在似乎不可能):

如果我删除 applicationIdSuffixes,保持以上所有 9 个 wearApp 依赖项可以正常工作,但是无论我在 Android Studio 中选择什么构建类型,它仍然会为每个构建类型构建一个 wear apk - 我真的需要applicationIdSuffixes.

有人对此有解决方法吗?从今天开始,每次我需要更改我的构建类型和/或风格时,我都会手动添加和删除 wearApp 依赖项,并且这并不是我在长期 运行.

中感到满意的解决方案

编辑:起初我没有注意到这一点,但由于某些原因,变体 firstDebug、secondDebug 和 thirdDebug 构建得很好,build.gradle 中的所有 9 个 wearApp 依赖项。 firstCustomerTest、firstRelease、secondCustomerTest、secondRelease、thirdCustomerTest 和 thirdRelease 的错误消息保持不变。所有变体每次都编译 9 个 wearApps,将其减少到 1 个会很好。

根据This Post

试试这个

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')
    }