gpt4 book ai didi

Android Studio 3 + Gradle 4.0 + shrinkResources + libraryProject = 无法在项目中找到匹配的配置

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:04:03 24 4
gpt4 key购买 nike

我在将我的项目迁移到最新的 Gradle 4.0 + Android Studio 3 版本时遇到问题,这给了我各种各样的错误。渐渐地,我设法将它们全部整理出来,除了这个。

    Could not resolve all dependencies for configuration ':app:forGoogleCoverageRuntimeClasspath'.
> Unable to find a matching configuration in project :mylibrary:
- Configuration 'debugApiElements':
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' and found compatible value 'AndroidTypeAttr{name=Aar}'.
- Required com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=coverage}' and found incompatible value 'BuildTypeAttr{name=debug}'.
- Found com.android.build.gradle.internal.dependency.VariantAttr 'VariantAttr{name=debug}' but wasn't required.
- Required org.gradle.api.attributes.Usage 'for runtime' and found incompatible value 'for compile'.
- Required store 'ProductFlavorAttr{name=forGoogle}' but no value provided.
- Configuration 'debugRuntimeElements':
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' and found compatible value 'AndroidTypeAttr{name=Aar}'.
- Required com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=coverage}' and found incompatible value 'BuildTypeAttr{name=debug}'.
- Found com.android.build.gradle.internal.dependency.VariantAttr 'VariantAttr{name=debug}' but wasn't required.
- Required org.gradle.api.attributes.Usage 'for runtime' and found compatible value 'for runtime'.
- Required store 'ProductFlavorAttr{name=forGoogle}' but no value provided.
- Configuration 'releaseApiElements':
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' and found compatible value 'AndroidTypeAttr{name=Aar}'.
- Required com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=coverage}' and found incompatible value 'BuildTypeAttr{name=release}'.
- Found com.android.build.gradle.internal.dependency.VariantAttr 'VariantAttr{name=release}' but wasn't required.
- Required org.gradle.api.attributes.Usage 'for runtime' and found incompatible value 'for compile'.
- Required store 'ProductFlavorAttr{name=forGoogle}' but no value provided.
- Configuration 'releaseRuntimeElements':
- Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'AndroidTypeAttr{name=Aar}' and found compatible value 'AndroidTypeAttr{name=Aar}'.
- Required com.android.build.gradle.internal.dependency.BuildTypeAttr 'BuildTypeAttr{name=coverage}' and found incompatible value 'BuildTypeAttr{name=release}'.
- Found com.android.build.gradle.internal.dependency.VariantAttr 'VariantAttr{name=release}' but wasn't required.
- Required org.gradle.api.attributes.Usage 'for runtime' and found compatible value 'for runtime'.
- Required store 'ProductFlavorAttr{name=forGoogle}' but no value provided.

为了确定问题:

  1. 我已经通过 Android Studios 项目助手创建了一个最小的应用程序项目
  2. 添加了一个空库模块,然后我将其添加到我的应用程序依赖项中。
  3. 添加了一个 flavorDimensions 和 2 productFlavors
  4. 添加了 3 种构建类型并让一种构建类型继承自另一种
  5. 让继承的构建类型启用shr​​inkResources

最后一步产生了提到的错误,类似于这个问题: Gradle 4.0 Unable to find a matching configuration

有没有人知道这是怎么回事或解决这个问题的方法?我也会提交错误报告。

我完整的gradle文件:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "gradletest.test"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

flavorDimensions "store"

productFlavors {
forAmazon {
dimension "store"
}

forGoogle {
dimension "store"
}
}

buildTypes {

debug {
debuggable true
minifyEnabled false
}

release {
minifyEnabled true
debuggable false
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}

coverage.initWith(buildTypes.debug)
coverage {
testCoverageEnabled true
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}


}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support.constraint:constraint-layout:1.0.2'

implementation project(':mylibrary')
}

最佳答案

可能的解决方法是在所有缺少 buildTypes 的模块中创建,但当 Google 计划为其创建解决方案时,它是疯狂的困惑代码。更多信息:https://issuetracker.google.com/issues/62170415正如我(但被版主删除)和你提到的。

但是还有第二种(相同但更简洁)解决方案:将其添加到您的顶级项目 build.gradle

subprojects {
afterEvaluate {project ->
if (project.hasProperty("android")) {
android {
buildTypes {
YOUR_MISSING_BUILD_TYPES {
BUILD_TYPE_PARAMS_OR_EMPTY
}
}
}
}
}
}

编辑:2017-07-12

它最终在 classpath 'com.android.tools.build:gradle:3.0.0-alpha6' 中得到修复。您可以使用新的 DSL:https://issuetracker.google.com/issues/62241369

android {
buildTypeMatching 'staging', 'debug'
productFlavorMatching 'color', 'blue', 'cyan'
}

在构建项目之前不要忘记删除上述解决方法!

编辑:2017-07-18

有官方文档:https://issuetracker.google.com/issues/62241369

To resolve this error, you need to specify which build type from "mylibrary" the Android plugin should match to the app's "staging" build type. You can do this with the buildTypeMatching property in the app's build.gradle file, as shown below:

// Add the following to the consumer's build.gradle file.
android {
...
// Tells the Android plugin to use a library's 'debug' build type
// when a 'staging' build type is not available. You can include
// additional build types, and the plugin matches 'staging' to the
// first build type it finds from the one's you specify. That is,
// if 'mylibrary' doesn't include a 'debug' build type either, the
// plugin matches 'staging' with the producer's 'release' build type.
buildTypeMatching 'staging', 'debug', 'release'
}

编辑:2017-09-06

buildTypeMatching 已从 AS beta 4 中删除。
现在使用 matchingFallbacks
参见:https://stackoverflow.com/a/46038946/4594990

关于Android Studio 3 + Gradle 4.0 + shrinkResources + libraryProject = 无法在项目中找到匹配的配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44242945/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com