gpt4 book ai didi

Android Studio/Kotlin : Gradle error - cannot find compile() method for arguments [com. android.support:recyclerview-v7:$support_version]

转载 作者:行者123 更新时间:2023-11-29 19:09:47 25 4
gpt4 key购买 nike

我使用的是 Android Studio 3.0 Canary 6。我在处理 build.gradle(项目)文件时遇到了一些问题。

build.gradle 文件如下:

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

buildscript {
ext.kotlin_version = '1.1.3-2'
ext.support_version = '26.0.1'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha6'
classpath "org.jetbrains.kotlin:kotlin-gradle-
plugin:$kotlin_version"
compile "com.android.support:appcompat-v7:$support_version"
compile "com.android.support:recyclerview-v7:$support_version"

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

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

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

我得到的错误是:

Error:Error:line (13)Could not find method compile() for arguments [com.android.support:appcompat-v7:26.0.1] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. Please install the Android Support Repository from the Android SDK Manager. Open Android SDK Manager.

请帮我解决这个错误。

最佳答案

从顶级 build.gradle 中删除 compile 依赖项,并将其放入您的应用程序级别 build.gradle dependencies,在项目 View 的 app/src 下可用。

dependencies {
compile "com.android.support:appcompat-v7:26.0.1"
compile "com.android.support:recyclerview-v7:26.0.1"
}

应用级依赖项(主要以编译开头)应放在应用级 build.gradle 文件下,而不是顶层 build.gradle 下。

实际上,build.gradle文件是用Groovy语言编写的,compile是一个方法调用。在 Groovy 中,我们可以 leave the parenthesis for top-level expressions .这就是为什么您会收到如下错误:

Could not find method complie()

关于Android Studio/Kotlin : Gradle error - cannot find compile() method for arguments [com. android.support:recyclerview-v7:$support_version],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45783601/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com