当我尝试将wearApp flavors和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
(目前似乎不可能):
- Android穿戴应用程序打包失败与口味
- Wear应用程序和带有applicationIdSuffix的定制构建类型
- https://code.google.com/p/android/issues/detail?id=74658
如果我去掉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会很方便。