无法解决:com.android.support:design-v7:27.1.1

时间:2018-07-05 10:40:04

标签: android android-gradle android-support-library

我正在使用Android Studio 3.1.3。 Gradle构建同步失败。我使用了以下方法,但没有使用它。如果有解决方案,请告诉我

  1. maven { url "https://maven.google.com" }

  2. 使重启和缓存无效

  3. multiDexEnabled true

  4. 添加mavenLocal()mavenCentral()

    这是模块级别的 build.gradle 文件:

    android {
            compileSdkVersion 27
            defaultConfig {
                applicationId "com.developers.a_g.designapp"
                minSdkVersion 15
                targetSdkVersion 27
                buildToolsVersion '27.1.1'
                versionCode 1
                versionName "1.0"
                multiDexEnabled true
                testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
            }
            buildTypes {
                release {
                    minifyEnabled false
                    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                }
            }
        }
    
    dependencies {
        implementation fileTree( dir: 'libs',include: ['*.jar'])
        implementation 'com.android.support:appcompat-v7:27.1.1'
        implementation 'com.android.support.constraint:constraint-layout:1.1.2'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test:runner:1.0.2'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
        implementation 'com.android.support:cardview-v7:27.1.1'
        implementation 'com.android.support:design-v7:27.1.1'
        implementation 'com.rengwuxian.materialedittext:library:2.1.4'
        implementation 'com.szagurskii:patternedtextwatcher:0.5.0'
        implementation 'com.github.d-max:spots-dialog:0.7@aar'
        implementation 'com.squareup.retrofit2:retrofit:2.3.0'
        implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
    }
    
    
     android {
            compileSdkVersion 27
            defaultConfig {
                applicationId "com.developers.a_g.designapp"
                minSdkVersion 15
                targetSdkVersion 27
                buildToolsVersion '27.1.1'
                versionCode 1
                versionName "1.0"
                multiDexEnabled true
                testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
            }
            buildTypes {
                release {
                    minifyEnabled false
                    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                }
            }
        }
    
    dependencies {
        implementation fileTree( dir: 'libs',include: ['*.jar'])
        implementation 'com.android.support:appcompat-v7:27.1.1'
        implementation 'com.android.support.constraint:constraint-layout:1.1.2'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test:runner:1.0.2'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
        implementation 'com.android.support:cardview-v7:27.1.1'
        implementation 'com.android.support:design-v7:27.1.1'
        implementation 'com.rengwuxian.materialedittext:library:2.1.4'
        implementation 'com.szagurskii:patternedtextwatcher:0.5.0'
        implementation 'com.github.d-max:spots-dialog:0.7@aar'
        implementation 'com.squareup.retrofit2:retrofit:2.3.0'
        implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
    }
    

这是项目级别的 build.gradle 文件:

    buildscript {

        repositories {

            jcenter()
            google()


            maven {
                url "https://maven.google.com"
            }
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.1.3'
        }
    }

    allprojects {
        repositories {
            google()
            jcenter()
        }
    }

    task clean(type: Delete) {
        delete rootProject.buildDir
    }

6 个答案:

答案 0 :(得分:3)

首先确保您使用的是

targetSdkVersion 27
compileSdkVersion 27
buildToolsVersion '27.0.3'

您的喜好就像:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        //..
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        //..
    }
}

并更新如下的设计实现:

implementation 'com.android.support:design:27.1.1'

您会收到此错误,因为com.android.support:design-v7不存在,没有-v7就存在,您也可以随时检查支持库in this link以确保您使用的是正确的库。 / p>

答案 1 :(得分:2)

您应该将google()存储库添加到依赖项中

allprojects {
    repositories {
       google()
       jcenter() 
    }
}

答案 2 :(得分:2)

不要

 implementation 'com.android.support:design-v7:27.1.1'
 buildToolsVersion '27.1.1'

要做

implementation 'com.android.support:design:27.1.1'
buildToolsVersion '27.0.3'

请确保您在下面添加了

    allprojects {
        repositories {
            google()
            jcenter()
            maven { url 'https://maven.google.com/' }

        }
    }

然后 Clean-Rebuild-Build

答案 3 :(得分:0)

还要在所有项目部分中添加Maven URL并同步gradle或尝试一一删除外部库,并同步gradle希望对您有所帮助

allprojects { repositories { google() jcenter()maven :"http://www.google.com" } }

答案 4 :(得分:0)

这是正确的形式
实施'com.android.support:design:27.1.1'

答案 5 :(得分:0)

升级到 Android Studio 3.3 破坏了我所有的项目。

这是我今天遇到的问题之一。在浪费太多时间找到解决方案之后,这就是工作的重点。当我解决此问题时,我已经忘了实际上在做什么。我真的很奇怪,为什么Google总是在Android Studio中附带损坏的gradle文件。似乎Google工程师甚至他们自己都不知道如何编写正确的gradle,并且在最终发布Android Studio之前也没有人对其进行质量检查。

模块级别gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27

    defaultConfig {
        applicationId "com.journaldev.okhttp"
        minSdkVersion 25
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation 'com.android.support:design:27.1.1'
    testImplementation 'junit:junit:4.12'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1'
    implementation 'com.squareup.okhttp3:okhttp:3.10.0'
}

以及项目级别的收益:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://maven.google.com/' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}