Java Gradle - 错误找不到参数的方法 implementation() [com.android.support:appcompat-v7:26.0.0]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45615474/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Gradle - Error Could not find method implementation() for arguments [com.android.support:appcompat-v7:26.0.0]
提问by cole
I am trying to open existing android project in android studio and it gradle cannot build the app without the error
我正在尝试在 android studio 中打开现有的 android 项目,它 gradle 无法在没有错误的情况下构建应用程序
Error android studio keeps on throwing
错误android studio不断抛出
Error:(74, 1) A problem occurred evaluating project ':app'.
> Could not find method implementation() for arguments
[com.android.support:appcompat-v7:26.0.0] on object of type
org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
My Code in build.gradle Which can help to understand my issue My dependencies
我在 build.gradle 中的代码可以帮助理解我的问题我的依赖项
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
// google & support
implementation "com.android.support:appcompat-v7:$supportVersion"
implementation "com.android.support:cardview-v7:$supportVersion"
implementation "com.android.support:recyclerview-v7:$supportVersion"
implementation "com.android.support:design:$supportVersion"
implementation "com.android.support:palette-v7:$supportVersion"
implementation "com.android.support:customtabs:$supportVersion"
implementation "com.android.support:support-v4:$supportVersion"
implementation 'com.google.android.exoplayer:exoplayer:r2.0.4'
// utils
implementation 'com.github.bumptech.glide:glide:4.0.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.0.0'
implementation 'com.koushikdutta.ion:ion:2.1.7'
implementation 'com.github.Commit451:bypasses:1.0.4'
implementation 'com.jakewharton:butterknife:8.8.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.0'
implementation 'com.drewnoakes:metadata-extractor:2.9.1'
implementation "com.orhanobut:hawk:2.0.1"
}
Please help to solve the issue
请帮助解决问题
采纳答案by Saurabh Thorat
Replace implementation
with compile
.
替换implementation
为compile
。
compile
was recently deprecatedand replaced by implementation
or api
compile
最近被弃用并替换为implementation
或api
回答by donfuxx
You need to use at least Gradle 3.4or newer to be able to use implementation
. It is not recommended to keep using the deprecated compile
since this can result in slower build times. For more details see the official android developer guide:
您至少需要使用Gradle 3.4或更高版本才能使用implementation
. 不建议继续使用已弃用的,compile
因为这会导致构建时间变慢。有关更多详细信息,请参阅官方 android 开发人员指南:
When your module configures an implementation dependency, it's letting Gradle know that the module does not want to leak the dependency to other modules at compile time. That is, the dependency is available to other modules only at runtime. Using this dependency configuration instead of api or compile can result in significant build time improvements because it reduces the amount of projects that the build system needs to recompile. For example, if an implementation dependency changes its API, Gradle recompiles only that dependency and the modules that directly depend on it. Most app and test modules should use this configuration.
当您的模块配置实现依赖项时,它会让 Gradle 知道该模块不想在编译时将依赖项泄漏给其他模块。也就是说,依赖项仅在运行时对其他模块可用。使用此依赖项配置而不是 api 或 compile 可以显着缩短构建时间,因为它减少了构建系统需要重新编译的项目数量。例如,如果一个实现依赖改变了它的 API,Gradle 只会重新编译那个依赖和直接依赖它的模块。大多数应用程序和测试模块应该使用此配置。
https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#new_configurations
https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#new_configurations
Update:compile
will be removed by end of 2018, so make sure that you use only implementation
now:
更新:compile
将于 2018 年底移除,因此请确保您只在implementation
现在使用:
Warning:Configuration 'compile' is obsolete and has been replaced with 'implementation'. It will be removed at the end of 2018
警告:配置 'compile' 已过时,已被 'implementation' 取代。将于 2018 年底移除
回答by xiqing lau
change apply plugin: 'java' to apply plugin: 'java-library'
更改应用插件:'java' 以应用插件:'java-library'
回答by krishnamurthy
Make sure your gradle version 3..or higher before using "implementation" .
确保您的 gradle 版本 3 .. 在使用“实现”之前或更高。
Open project level gradle file under dependencies
在依赖项下打开项目级别的 gradle 文件
dependencies{
classpath 'com.android.tools.build:gradle:3.1.2'
}
open the gradle-wrapper.properties
file and set the distributionUrl
:
打开gradle-wrapper.properties
文件并设置distributionUrl
:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
or latest version
或最新版本
synk project, Hope this solved your problem
synk 项目,希望这解决了你的问题
回答by Saurabh kumar
Your Code
你的代码
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
Replace it By
替换为
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
回答by Nguyen Tan Dat
So ridiculous, but I still wanna share my experience in case of that someone falls into the situation like me.
太可笑了,但我还是想分享一下我的经验,以防有人遇到像我这样的情况。
Please check if you changed: compileSdkVersion
--> implementationSdkVersion
by mistake
请检查您是否更改:compileSdkVersion
-->implementationSdkVersion
错误
回答by Bot
As mentioned here, https://stackoverflow.com/a/50941562/2186220, use gradle plugin version 3 or higher while using 'implementation'.
如此处所述,https://stackoverflow.com/a/50941562/2186220,在使用“实现”时使用 gradle 插件版本 3 或更高版本。
Also, use the google()
repository in buildscript
.
此外,使用google()
存储库buildscript
。
buildscript {
repositories {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
}
}
These changes should solve the issue.
这些更改应该可以解决问题。
回答by Sunil Kumar
Make sure you're adding these dependencies in android/app/build.gradle, not android/build.gradle
确保您在 android/app/build.gradle 中添加这些依赖项,而不是 android/build.gradle
回答by Edward Mpanza
Replace your implementation
with classpath
. That should work.
替换你implementation
的classpath
。那应该工作。
回答by user8783065
I moved implementation
to module-level build.gradle from root-level build.gradle. It solves the issue.
我implementation
从根级 build.gradle转移到模块级 build.gradle。它解决了这个问题。