在尝试将wearApp flavor和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个wearApps,将整齐地减少为1。答案 0 :(得分: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')
}