如何解决Android buildTypes与productFlavors错误
决定使用Gradle 6.5从Android gradle插件3.5.x切换到gradle插件4.10并错误地卡住了。
这是我的build.gradle
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 'release'
- Variant 'kitkatReleaseApiElements' capability myapp:app:unspecified declares a component,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,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,attribute 'version' with value 'kitkat'
- Variant 'nougatDebugRuntimeElements' capability myapp:app:unspecified:
- Incompatible because this component declares a runtime of a component,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 'kitkat'
在此之前,当我使用gradle-tools v 3.x-运行正常时。
有什么想法,想法,提示和线索吗?
解决方法
好吧,为了使用不同的后端,我不会指定比调试和发布更多的构建类型。相反,我将使用其中一些技巧:
您可以使用BuildConfig
类在应用程序代码中访问构建类型,构建风格和自定义字段。
具有简单口味的方法
- 构建类型:
-
debug
-
release
-
- 香料:
-
dev
-
test
-
live
-
哪些会导致这些生成变体(您不必全部使用它们):
-
devDebug
-
devRelease
-
testDebug
-
testRelease
-
liveDebug
-
liveRelease
使用尺寸组合多种口味的方法
-
香料尺寸:
-
backend
-
target
-
-
构建类型:
-
debug
-
release
-
-
香料:
-
target
维度:-
dev
-
test
-
live
-
-
backend
维度:-
production
-
test
-
哪些会导致这些生成变体(再次,您不必全部使用它们):
-
productionDevDebug
-
productionDevRelease
-
productionTestDebug
-
productionTestRelease
-
productionLiveDebug
-
productionLiveRelease
-
testDevDebug
-
testDevRelease
-
testTestDebug
-
testTestRelease
-
testLiveDebug
-
testLiveRelease
使用构建字段
在构建类型和构建风味声明中使用附加值,例如:
buildConfigField "boolean","production_backend","false"
或
buildConfigField "String","backend","\"production\""
关注此链接https://www.journaldev.com/21533/android-build-types-product-flavors
,您遇到的问题似乎是您的主项目使用了具有风味维度的库,而您的应用程序不知道要使用哪一个。您应该在 defaultConfig 块中使用 missingDimensionStrategy 来指定默认风格。例如:
missingDimensionStrategy 'dimension','flavor1','flavor2'
请查看 this 链接了解更多详情。
,在@Chriki的评论之后,他试图提出可重复性最小的问题,并突然找到了解决方案。魔术在声明中:
android {
...
dynamicFeatures = [":app"]
}
每当我对此行发表评论时,一切正常。
P.S。这应该是辐射辐射,用于记录日志/调试消息,而实际上没有这些日志/消息。最终,我花了将近一个星期的时间来寻找解决方案,最后却偶然发现了。
如果@Chriki发布答案,我将奖励他。
,我遇到了同样的问题,但我正在处理多 gradle 文件项目,在每个项目上添加了变体后,它工作正常。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。