30

当我尝试将 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')
}

从我的磨损/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 中选择什么 buildType,它仍然会为每个 buildType 构建一个 Wear apk - 我真的需要 applicationIdSuffixes。

有人有解决方法吗?到今天为止,每次我需要更改 buildType 和/或风味时,我都会手动添加和删除 wearApp 依赖项,从长远来看,这并不是一个让我感到满意的解决方案。

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

4

1 回答 1

8

根据这篇文章

尝试这个

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')
    }
于 2016-02-04T08:24:17.667 回答