Android buildTypes与productFlavors错误
决定用gradle 6.5从Android gradle插件3.5.x切换到gradle插件4.10,但还是出了问题 这是我的身材,格雷德尔Android buildTypes与productFlavors错误,android,gradle,android-gradle-plugin,build.gradle,Android,Gradle,Android Gradle Plugin,Build.gradle,决定用gradle 6.5从Android gradle插件3.5.x切换到gradle插件4.10,但还是出了问题 这是我的身材,格雷德尔 defaultConfig { applicationId "com.example.myapp targetSdkVersion targetSdkVersionVar multiDexEnabled true } flavorDimensions "version" productFlavor
defaultConfig {
applicationId "com.example.myapp
targetSdkVersion targetSdkVersionVar
multiDexEnabled true
}
flavorDimensions "version"
productFlavors {
kitkat {
sourceSets { "src/android/kitkat" }
dimension "version"
minSdkVersion minSdkKitkat
targetSdkVersion targetSdkKitkat
versionNameSuffix "-kitkat"
}
nougat {
sourceSets { "src/android/nougat" }
dimension "version"
minSdkVersion minSdkNougat
targetSdkVersion targetSdkVersionVar
versionNameSuffix "-nougat"
}
}
buildTypes {
debug {
multiDexKeepFile file('multidex-config.txt')
multiDexKeepProguard file('multidex-config.pro')
minifyEnabled false
zipAlignEnabled true
sourceSets {
//main.java.srcDirs += 'src/main/kotlin'
main {
java.srcDirs = ['src/android/default/java/', 'src/common/java/']
jni.srcDirs = [] //disable ndk support
manifest.srcFile 'src/android/default/AndroidManifest.xml'
resources.srcDirs = ['src/android/default']
aidl.srcDirs = ['src/android/default']
renderscript.srcDirs = ['src/android/default']
res.srcDirs = ['src/android/default/res']
assets.srcDirs = ['src/android/default/assets']
}
test {
java.srcDirs = ['src/test/java']
}
androidTest {
java.srcDirs = ['src/androidTest/java']
}
}
}
release {
multiDexKeepFile file('multidex-config.txt')
multiDexKeepProguard file('multidex-config.pro')
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
zipAlignEnabled true
sourceSets {
main {
java.srcDirs = ['src/android/default/java/', 'src/common/java/']
jni.srcDirs = [] //disable ndk support
manifest.srcFile 'src/android/default/AndroidManifest.xml'
resources.srcDirs = ['src/android/default']
aidl.srcDirs = ['src/android/default']
renderscript.srcDirs = ['src/android/default']
res.srcDirs = ['src/android/default/res']
assets.srcDirs = ['src/android/default/assets']
}
test {
java.srcDirs = ['src/test/java']
}
androidTest {
java.srcDirs = ['src/androidTest/java']
}
}
}
}
尝试生成时,我收到以下错误消息:
Could not determine the dependencies of task ':app:checkKitkatReleaseLibraries'.
> Could not resolve all task dependencies for configuration ':app:kitkatReleaseReverseMetadataValues'.
> Could not resolve project :app.
Required by:
project :app
> The consumer was configured to find a usage of 'android-reverse-meta-data' of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release', attribute 'version' with value 'kitkat'. However we cannot choose between the following variants of project :app:
- kitkatDebugAndroidTestCompile
- kitkatDebugAndroidTestRuntime
- kitkatDebugRuntime
- kitkatDebugUnitTestCompile
- kitkatDebugUnitTestRuntime
- kitkatReleaseRuntime
- kitkatReleaseUnitTestCompile
- kitkatReleaseUnitTestRuntime
- nougatDebugAndroidTestCompile
- nougatDebugAndroidTestRuntime
- nougatDebugRuntime
- nougatDebugUnitTestCompile
- nougatDebugUnitTestRuntime
- nougatReleaseRuntime
- nougatReleaseUnitTestCompile
- nougatReleaseUnitTestRuntime
All of them match the consumer attributes:
- Variant 'kitkatDebugAndroidTestCompile' capability myapp:app:unspecified:
- Unmatched attributes:
- Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'release')
- Doesn't say anything about its usage (required a usage of 'android-reverse-meta-data')
- Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :app' but the consumer didn't ask for it
- Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it
- Doesn't say anything about version (required 'kitkat')
- Variant 'kitkatDebugAndroidTestRuntime' capability myapp:app:unspecified:
- Unmatched attributes:
- Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'release')
- Doesn't say anything about its usage (required a usage of 'android-reverse-meta-data')
- Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :app' but the consumer didn't ask for it
- Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it
- Doesn't say anything about version (required 'kitkat')
- Variant 'kitkatDebugRuntime' capability myapp:app:unspecified:
- Unmatched attributes:
- Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'release')
- Doesn't say anything about its usage (required a usage of 'android-reverse-meta-data')
- Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :app' but the consumer didn't ask for it
- Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it
- Doesn't say anything about version (required 'kitkat')
- Variant 'kitkatDebugUnitTestCompile' capability myapp:app:unspecified:
- Unmatched attributes:
- Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'release')
- Doesn't say anything about its usage (required a usage of 'android-reverse-meta-data')
- Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :app' but the consumer didn't ask for it
- Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it
- Doesn't say anything about version (required 'kitkat')
- Variant 'kitkatDebugUnitTestRuntime' capability myapp:app:unspecified:
- Unmatched attributes:
- Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'release')
- Doesn't say anything about its usage (required a usage of 'android-reverse-meta-data')
- Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :app' but the consumer didn't ask for it
- Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it
- Doesn't say anything about version (required 'kitkat')
- Variant 'kitkatReleaseRuntime' capability myapp:app:unspecified:
- Unmatched attributes:
- Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'release')
- Doesn't say anything about its usage (required a usage of 'android-reverse-meta-data')
- Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :app' but the consumer didn't ask for it
- Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it
- Doesn't say anything about version (required 'kitkat')
- Variant 'kitkatReleaseUnitTestCompile' capability myapp:app:unspecified:
- Unmatched attributes:
- Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'release')
- Doesn't say anything about its usage (required a usage of 'android-reverse-meta-data')
- Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :app' but the consumer didn't ask for it
- Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it
- Doesn't say anything about version (required 'kitkat')
- Variant 'kitkatReleaseUnitTestRuntime' capability myapp:app:unspecified:
- Unmatched attributes:
- Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'release')
- Doesn't say anything about its usage (required a usage of 'android-reverse-meta-data')
- Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :app' but the consumer didn't ask for it
- Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it
- Doesn't say anything about version (required 'kitkat')
- Variant 'nougatDebugAndroidTestCompile' capability myapp:app:unspecified:
- Unmatched attributes:
- Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'release')
- Doesn't say anything about its usage (required a usage of 'android-reverse-meta-data')
- Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :app' but the consumer didn't ask for it
- Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it
- Doesn't say anything about version (required 'kitkat')
- Variant 'nougatDebugAndroidTestRuntime' capability myapp:app:unspecified:
- Unmatched attributes:
- Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'release')
- Doesn't say anything about its usage (required a usage of 'android-reverse-meta-data')
- Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :app' but the consumer didn't ask for it
- Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it
- Doesn't say anything about version (required 'kitkat')
- Variant 'nougatDebugRuntime' capability myapp:app:unspecified:
- Unmatched attributes:
- Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'release')
- Doesn't say anything about its usage (required a usage of 'android-reverse-meta-data')
- Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :app' but the consumer didn't ask for it
- Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it
- Doesn't say anything about version (required 'kitkat')
- Variant 'nougatDebugUnitTestCompile' capability myapp:app:unspecified:
- Unmatched attributes:
- Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'release')
- Doesn't say anything about its usage (required a usage of 'android-reverse-meta-data')
- Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :app' but the consumer didn't ask for it
- Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it
- Doesn't say anything about version (required 'kitkat')
- Variant 'nougatDebugUnitTestRuntime' capability myapp:app:unspecified:
- Unmatched attributes:
- Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'release')
- Doesn't say anything about its usage (required a usage of 'android-reverse-meta-data')
- Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :app' but the consumer didn't ask for it
- Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it
- Doesn't say anything about version (required 'kitkat')
- Variant 'nougatReleaseRuntime' capability myapp:app:unspecified:
- Unmatched attributes:
- Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'release')
- Doesn't say anything about its usage (required a usage of 'android-reverse-meta-data')
- Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :app' but the consumer didn't ask for it
- Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it
- Doesn't say anything about version (required 'kitkat')
- Variant 'nougatReleaseUnitTestCompile' capability myapp:app:unspecified:
- Unmatched attributes:
- Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'release')
- Doesn't say anything about its usage (required a usage of 'android-reverse-meta-data')
- Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :app' but the consumer didn't ask for it
- Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it
- Doesn't say anything about version (required 'kitkat')
- Variant 'nougatReleaseUnitTestRuntime' capability myapp:app:unspecified:
- Unmatched attributes:
- Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'release')
- Doesn't say anything about its usage (required a usage of 'android-reverse-meta-data')
- Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :app' but the consumer didn't ask for it
- Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it
- Doesn't say anything about version (required 'kitkat')
The following variants were also considered but didn't match the requested attributes:
- Variant 'kitkatDebugApiElements' capability myapp:app:unspecified declares a component, as well as attribute 'version' with value 'kitkat':
- Incompatible because this component declares an API of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug' and the consumer needed a usage of 'android-reverse-meta-data' of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release'
- Variant 'kitkatDebugRuntimeElements' capability myapp:app:unspecified declares a component, as well as attribute 'version' with value 'kitkat':
- Incompatible because this component declares a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug' and the consumer needed a usage of 'android-reverse-meta-data' of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release'
- Variant 'kitkatReleaseApiElements' capability myapp:app:unspecified declares a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release', attribute 'version' with value 'kitkat':
- Incompatible because this component declares an API of a component and the consumer needed a usage of 'android-reverse-meta-data' of a component
- Variant 'kitkatReleaseRuntimeElements' capability myapp:app:unspecified declares a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release', attribute 'version' with value 'kitkat':
- Incompatible because this component declares a runtime of a component and the consumer needed a usage of 'android-reverse-meta-data' of a component
- Variant 'nougatDebugApiElements' capability myapp:app:unspecified:
- Incompatible because this component declares an API of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'version' with value 'nougat' and the consumer needed a usage of 'android-reverse-meta-data' of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release', attribute 'version' with value 'kitkat'
- Variant 'nougatDebugRuntimeElements' capability myapp:app:unspecified:
- Incompatible because this component declares a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'version' with value 'nougat' and the consumer needed a usage of 'android-reverse-meta-data' of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release', attribute 'version' with value 'kitkat'
- Variant 'nougatReleaseApiElements' capability myapp:app:unspecified declares a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release':
- Incompatible because this component declares an API of a component, as well as attribute 'version' with value 'nougat' and the consumer needed a usage of 'android-reverse-meta-data' of a component, as well as attribute 'version' with value 'kitkat'
- Variant 'nougatReleaseRuntimeElements' capability myapp:app:unspecified declares a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release':
- Incompatible because this component declares a runtime of a component, as well as attribute 'version' with value 'nougat' and the consumer needed a usage of 'android-reverse-meta-data' of a component, as well as attribute 'version' with value 'kitkat'
在此之前,当我使用GradleToolsV3.x时,它工作得非常好
有什么想法、想法、提示、线索吗?好吧,为了使用不同的后端,我不会指定比调试和发布更多的构建类型。相反,我将使用以下一些技术:
- 更多口味
- 自定义生成配置字段(文档)
- 结合多种产品风格(文档)
BuildConfig
class访问应用程序代码中的生成类型、生成风格和自定义字段
口味简单的方法
- 生成类型:
debug
发布
- 口味:
dev
测试
live
devDebug
devRelease
testDebug
testRelease
liveDebug
liveRelease
- 风味维度:
后端
目标
- 生成类型:
debug
发布
- 口味:
维度:目标
dev
测试
live
维度:后端
生产
测试
productionDevDebug
productionDevRelease
productionTestDebug
productionTestRelease
productionLiveDebug
productionLiveRelease
testDevDebug
testDevRelease
testdebug
testrelease
testLiveDebug
testLiveRelease
buildConfigField "boolean", "production_backend", "false"
或
按照@Chriki的评论点击这个链接,试图提出最小的可重复性问题,突然找到了解决方案。魔术师在声明中说:
android {
...
dynamicFeatures = [":app"]
}
每当我评论这一行时,一切都正常
注意:这里应该是对gradle日志/调试消息的厌恶辐射,实际上是那些日志/消息的缺失。最后,我花了将近一个星期的时间试图找到一个解决方案,最后意外地找到了
如果@Chriki发布答案,我会奖励他。看来你们的主要项目使用的是有味道维度的库,而你们的应用程序不知道使用哪一个。您应该在defaultConfig块中使用missingDimensionStrategy来指定默认风格。例如:
missingDimensionStrategy 'dimension', 'flavor1', 'flavor2'
有关更多详细信息,请查看链接。遇到同样的问题,即无法使用与使用者库具有不同变体的库依赖项。如果有人有解决方法或修复方法,那就太好了。这个任务来自哪里?从您的部分构建配置来看(至少对我来说)不清楚。A太好了…我不知道如何在我的特殊情况下使用你的建议。。。
missingDimensionStrategy 'dimension', 'flavor1', 'flavor2'