相关文章推荐
鼻子大的甘蔗  ·  Job artifacts | ...·  1 周前    · 
有胆有识的铁链  ·  Java中 ...·  11 月前    · 
大力的眼镜  ·  Git: ...·  1 年前    · 
暗恋学妹的吐司  ·  如何在AndroidStudio ...·  2 年前    · 
不羁的山羊  ·  git clone failed exit ...·  2 年前    · 
www.jcodecraeer.com

Android Studio 2.3升级到Android Studio 3.0 Gradle builde报错

Unable to resolve dependency for ':app@xxPreview/compileClasspath': Could not resolve project :library.
Could not resolve project :library.
Required by: project :app
> Unable to find a matching configuration of project :library:
         - Configuration 'debugApiElements':
             - Required com.android.build.api.attributes.BuildTypeAttr 'preview' and found incompatible value 'debug'.
             - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
             - Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but was't required.
             - Required org.gradle.api.attributes.Usage 'java-api' and found compatible value 'java-api'.
             - Required versionCode 'xiaomi' but no value provided.
         - Configuration 'debugRuntimeElements':
             - Required com.android.build.api.attributes.BuildTypeAttr 'preview' and found incompatible value 'debug'.
             - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
             - Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
             - Required org.gradle.api.attributes.Usage 'java-api' and found incompatible value 'java-runtime'.
             - Required versionCode 'xiaomi' but no value provided.
         - Configuration 'releaseApiElements':
             - Required com.android.build.api.attributes.BuildTypeAttr 'preview' and found incompatible value 'release'.
             - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
             - Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.
             - Required org.gradle.api.attributes.Usage 'java-api' and found compatible value 'java-api'.
             - Required versionCode 'xiaomi' but no value provided.
         - Configuration 'releaseRuntimeElements':
             - Required com.android.build.api.attributes.BuildTypeAttr 'preview' and found incompatible value 'release'.
             - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
             - Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.
             - Required org.gradle.api.attributes.Usage 'java-api' and found incompatible value 'java-runtime'.
             - Required versionCode 'xiaomi' but no value provided.复制代码

build.gradle(module:library):

apply plugin: 'com.android.library'
android {
    buildTypes {
        release {
        debug{
}复制代码

build.gradle(module:app):

apply plugin: 'com.android.application'
//apply plugin: 'com.android.library'
android {
    buildTypes {
        release {
        preview {
        debug {
dependencies {
    compile project(':library')
}复制代码

builde.gradle(project:root):

dependencies {
    classpath 'com.android.tools.build:gradle:2.3.3'
}复制代码
dependencies {
    classpath 'com.android.tools.build:gradle:3.0.0'
}复制代码

原因:app中buildTypes集合不是library的buildTypes集合子集,即 app中buildType属性preview在依赖的library中找不到。

1, 在 所有library 中添加buildType属性preview。如下:

build.gradle(module:library):

apply plugin: 'com.android.library'
android {
    buildTypes {
        release {
        preview {
        debug {
}复制代码

2, 将Gradle API回滚到能够适配的版本。如下:

builde.gradle(project:root):

dependencies {
        //从3.0.0回滚到2.3.3
        classpath 'com.android.tools.build:gradle:2.3.3'
}复制代码

方法1和方法2任选一种

Best fix:

build.gradle(module:app):

apply plugin: 'com.android.application'
//apply plugin: 'com.android.library'
android {
    buildTypes {
        release {
        preview {
        //关键代码,release, debug为library中已有buildType
            matchingFallbacks = ['release', 'debug']
        debug {
dependencies {
    compile project(':library')
}复制代码