Android Studio 3+;Gradle 4.0+;收缩资源+;libraryProject=无法在project中找到匹配的配置
我在将我的项目迁移到最新的Gradle 4.0+Android Studio 3版本时遇到了一些问题,这给了我各种各样的错误。一点一点地,除了这一个,我设法把它们都分类了Android Studio 3+;Gradle 4.0+;收缩资源+;libraryProject=无法在project中找到匹配的配置,android,gradle,build.gradle,android-build-type,android-studio-3.0,Android,Gradle,Build.gradle,Android Build Type,Android Studio 3.0,我在将我的项目迁移到最新的Gradle 4.0+Android Studio 3版本时遇到了一些问题,这给了我各种各样的错误。一点一点地,除了这一个,我设法把它们都分类了 Could not resolve all dependencies for configuration ':app:forGoogleCoverageRuntimeClasspath'. > Unable to find a matching configuration in project :mylib
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.
为了解决问题:
收缩资源
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')
}
可能的解决办法是在所有模块中创建缺少构建类型的代码,但当谷歌计划为其创建解决方案时,这会把代码弄得乱七八糟。更多信息:如我(但被版主删除)和你提到的 但还有第二种(相同但更干净)解决方案: 将此添加到顶级项目
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:
在构建项目之前,不要忘记删除上述解决方法强>
编辑:2017-07-18
有官方文件:
要解决此错误,您需要指定来自的生成类型
“mylibrary”Android插件应与应用程序的“暂存”匹配
构建类型。可以使用中的buildTypeMatching属性执行此操作
应用程序的build.gradle文件,如下所示:
编辑:2017-09-06
buildTypeMatching
已从AS beta 4中删除。现在使用
matchingFallbacks
请参阅:可能重复的 确保所有模块中的构建配置(构建类型)的确切数量
在我3.0之前的设置中,我的com.android.library模块中只有debug{}和release{}。我又添加了一个类似于app模块的配置。如果你的应用程序包含库依赖项不包含的生成类型,那么它的生成对我来说很好。 例如,您的应用程序包含“暂存”生成类型,但依赖项仅包含“调试”和“发布”生成类型 您将得到如下错误:
无法解析“”的依赖项:app@staging/compileClasspath':无法解析项目:库。打开文件显示详细信息
您可以通过添加
buildTypes {
staging {
proguardFile getDefaultDexGuardFile('dexguard-release.pro')
proguardFile 'dexguard-rules.pro'
matchingFallbacks = ['debug', 'release'] //add this line
}
}
解决与依赖项匹配相关的生成错误如果到达此处,则我的解决方案是:
buildTypes {
release {
// minifyEnabled false
// proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
build {
// minifyEnabled false
// proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
错误报告在下面:随时开始。现在,它帮助我从我的构建类型中删除shrinkResources在我的项目中,app模块和lib模块中的构建类型是“debug”和“release”。已尝试将buildTypeMatching“debug”、“release”放在app build.gradle中。它仍然抛出相同的错误,这里是我的应用程序和库的构建类型你的方式,在金丝雀4和6工作。在金丝雀7和金丝雀8中,它仍然抛出一个错误这里是我的应用程序和库的构建类型
buildTypes {
staging {
proguardFile getDefaultDexGuardFile('dexguard-release.pro')
proguardFile 'dexguard-rules.pro'
matchingFallbacks = ['debug', 'release'] //add this line
}
}
buildTypes {
release {
// minifyEnabled false
// proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
build {
// minifyEnabled false
// proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}