当我尝试将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中选择哪种buildType,它都仍会为每个buildType构建一个Weap APK-我确实需要applicationIdSuffixes。
有人对此有解决方法吗?从今天起,每次需要更改buildType和/或 flavor 时,我都会手动添加和删除wearApp依赖关系,从长远来看,这并不是我完全满意的解决方案。
编辑:我起初没有注意到这一点,但是由于某些原因,在build.gradle中使用first9,secondDebug和thirdDebug的所有9个wearApp依赖项构建变体都很好。错误消息对于firstCustomerTest,firstRelease,secondCustomerTest,secondRelease,thirdCustomerTest和thirdRelease仍然相同。所有变体每次都会编译9个wearApp,将其精简为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')
}