android - 找不到参数[androidx.appcompat:appcompat:1.1.0-rc01]的方法Implementation()

标签 android android-studio gradle

我已经在多个地方看到了这个问题。问题似乎与过去的gradle版本3和android studio版本3的更新有关。每当我将依赖项更改为较新的版本时,我都会不断收到错误消息:

Could not find method implementation() for arguments [androidx.appcompat:appcompat:1.1.0-rc01] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

这是我的build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 28
    }
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
        implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
        implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }

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

    }
}

我的gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

感谢您的帮助。一直试图让我的应用在Android上运行一天。

最佳答案

在顶级文件的buildscript块中删除以下行:

//implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
//implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02

您必须在dependencies文件的module/build.gradle块中添加这些依赖项。

同时删除dependencies块内的allprojects
buildscript {
    ext {
        //...
    }
    repositories {
        //..
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
    }
}

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

关于android - 找不到参数[androidx.appcompat:appcompat:1.1.0-rc01]的方法Implementation(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58379548/

相关文章:

java - 从 ByteBuffer 中获取 IP 包数据

java - Firebase 卡住并且无法与 Android Studio 连接

java - 如何使用 HashMap 并在 ArrayAdapter 中使用它来在微调器中显示值

带有 Gradle 的 Android(Java 以非零退出值 2 完成)

android - 警告:配置 'compile'已过时,已被 'implementation'和 'api'取代

Java将所有转义字符替换为双转义

java - 使用 FQL 获取用户照片数组

java - 导入eclipse项目卡住

android - 如何将 Google Play Developer API 版本更新到 v3?

java - 使用activity_main 或content_main 做什么?