无法同步 Gradle 项目找不到参数 [com.android.support:design:27.1.0] 的方法实现()

Failed to sync Gradle project Could not find method implementation() for arguments [com.android.support:design:27.1.0]

ERROR: Error:Could not find method implementation() for arguments [com.android.support:design:27.1.0] on DefaultExternalModuleDependency{group='com.android.support.test.espresso', name='espresso-core', version='2.2.2', configuration='default'} of type org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency.

请从 Android SDK 管理器安装 Android 支持存储库。打开 Android SDK 管理器

build.gradle(模块应用)

android {
    compileSdkVersion 28
    buildToolsVersion "28.0.2"
    defaultConfig {
        applicationId "com.example.salmakhalil.signupformwithdatabase"
        minSdkVersion 14
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            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', {
       // androidTestCompile 'com.android.support:support-annotations:27.1.0'
        exclude group: 'com.android.support', module: 'support-annotations'
       implementation 'com.android.support:design:27.1.0'
// implementation 'com.android.volley:volley:1.1.0'
//implementation 'com.android.support:appcompat-v7:27.1.0'
//        implementation 'com.android.support.constraint:constraint-layout:1.0.2'
//        implementation 'junit:junit:4.12'
//        implementation 'com.android.support.test:runner:1.0.1'
//        implementation 'com.android.support.test.expresso:expresso-core:3.0.1'
    })
    compile 'com.android.support:appcompat-v7:25.+'
    testCompile 'junit:junit:4.12'
}

我该如何解决这个问题?

**build.gradle** (Module App)
apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion "28.0.2"
    defaultConfig {
        applicationId "com.example.salmakhalil.signupformwithdatabase"
        minSdkVersion 14
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            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', {
       // androidTestCompile 'com.android.support:support-annotations:27.1.0'
        exclude group: 'com.android.support', module: 'support-annotations'
       implementation 'com.android.support:design:27.1.0'
// implementation 'com.android.volley:volley:1.1.0'
//implementation 'com.android.support:appcompat-v7:27.1.0'
//        implementation 'com.android.support.constraint:constraint-layout:1.0.2'
//        implementation 'junit:junit:4.12'
//        implementation 'com.android.support.test:runner:1.0.1'
//        implementation 'com.android.support.test.expresso:expresso-core:3.0.1'
    })*/
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'com.google.android.material:material:1.1.0-alpha09'

    compile 'com.android.support:appcompat-v7:25.+'
    testCompile 'junit:junit:4.12'
}

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


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

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
allprojects {
    repositories {
        maven { url 'http://repo1.maven.org/maven2' }
        // { url "https://jitpack.io" }
        //maven { url "https://maven.google.com" }
    }
}

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

/*configurations.all {
    resolutionStrategy.force 'com.android.support:support-annotations:27.1.0'
}*/```

首先更新 android 插件的版本 gradle 和 gradle 版本。

在项目build.gradle(顶层文件)中更新android插件更改:

repositories {
        google() //<-- add
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.2' //change
    }
}

allprojects {
    repositories {
        google() //<-- add
        maven { url 'http://repo1.maven.org/maven2' }
    }
}

然后在 gradle/wrapper/gradle-wrapper.properties 中使用 distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip 更改 gradle 版本。

要解决问题中的问题,请在 module/build.gradle 更改中:

   androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
       // androidTestCompile 'com.android.support:support-annotations:27.1.0'
        exclude group: 'com.android.support', module: 'support-annotations'
       implementation 'com.android.support:design:27.1.0'
    })

至:

androidTestCompile('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.0'

改变

 androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
   // androidTestCompile 'com.android.support:support-annotations:27.1.0'
    exclude group: 'com.android.support', module: 'support-annotations'
   implementation 'com.android.support:design:27.1.0'
})

androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.android.material:material:1.1.0-alpha09'

从这里更改以下代码:

implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})

为此:

androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.android.material:material:1.1.0-alpha09'

然后在gradle属性中添加:

android.useAndroidX=true