android - Android 找不到方法“implementation()”
问题描述
所以我在 Gradle 文件中实现了一些依赖项,当我尝试同步它时,我得到了
Build file '/home/qwirrr/AndroidStudioProjects/ClockIn/build.gradle' line: 9
A problem occurred evaluating root project 'ClockIn'.
> Could not find method implementation() for arguments [androidx.fragment:fragment:1.3.6] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Gradle 文件如下所示:
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
implementation 'androidx.fragment:fragment:1.3.6'
implementation 'com.google.android.material:material:1.0.0'
classpath "com.android.tools.build:gradle:7.0.3"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
我试图在类路径行中更改implementation
甚至compile
更改 Gradle 版本,但没有成功。
我该如何解决?
注意:我使用的是 Pop_OS!20.04 LTS 如果重要的话
解决方案
您的依赖项应该进入build.gradle
您的模块/应用程序而不是build.gradle
您的项目:
您的build.gradle
应用程序应如下所示:
plugins {
id 'com.android.application'
...
}
android {
...
}
dependencies {
//all your dependencies goes here
implementation 'androidx.fragment:fragment:1.3.6'
implementation 'com.google.android.material:material:1.0.0'
}
唯一应该进入build.gradle
项目的是类路径。
推荐阅读
- html - Pandoc:在不创建锚点的情况下在 HTML 中使用语法高亮显示?
- c# - EF Core 需要显式设置 id-property,尽管它是在“表拆分”场景中生成的数据库
- ssh - Windows:rsync 在 msys 中工作,但在 cygwin 中不工作(git bash)
- javascript - 不断从 Gmail api users.messages.get 收到无效的 id 值错误消息
- html - 为网站上的锚链接提供平滑滚动,但现在无法访问外部链接
- javascript - 如何将 HTML DOM 元素 javascript 函数访问到另一个 javascript
- linq - 如何用逗号分隔的字符串或 int 映射到 IEnumerable
使用自动映射器 - swiftui - 在 SwiftUI 中的多个导航视图的情况下隐藏导航栏
- angular - 使用 Angular Bootstrap,我无法在下拉菜单中获取下拉项目
- reactjs - 如何在使用 React Player 更改 url 时停止播放加载的视频并加载新视频?