[英]Could not find method implementation() for arguments [com.android.support:appcompat-v7:28.0.0]
[英]Gradle - Error Could not find method implementation() for arguments [com.android.support:appcompat-v7:26.0.0]
我正在嘗試在 android 工作室中打開現有的 android 項目,它 gradle 無法在沒有錯誤的情況下構建應用程序
錯誤 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.
我在 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"
}
請幫助解決問題
用implementation
替換compile
。
compile
最近被棄用並被implementation
或api
取代
在使用“實現”之前,請確保您的 Gradle 版本為3.*.*
或更高版本。
打開依賴項下的項目級Gradle文件:
dependencies{
classpath 'com.android.tools.build:gradle:3.1.2'
}
打開 'gradle-wrapper.properties' 文件並設置distributionUrl
:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
或最新版本。
同步項目。 我希望這能解決你的問題。
確保您在 android/app/build.gradle 中添加這些依賴項,而不是 android/build.gradle
您至少需要使用Gradle 3.4或更新版本才能使用implementation
。 不建議繼續使用已棄用的compile
因為這會導致構建時間變慢。 有關更多詳細信息,請參閱官方 android 開發人員指南:
當您的模塊配置實現依賴項時,它會讓 Gradle 知道該模塊不想在編譯時將依賴項泄漏給其他模塊。 也就是說,依賴項僅在運行時對其他模塊可用。 使用此依賴項配置而不是 api 或 compile 可以顯着縮短構建時間,因為它減少了構建系統需要重新編譯的項目數量。 例如,如果一個實現依賴改變了它的 API,Gradle 只會重新編譯那個依賴和直接依賴它的模塊。 大多數應用程序和測試模塊應該使用此配置。
https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#new_configurations
更新: compile
將於 2018 年底移除,因此請確保您現在僅使用implementation
:
警告:配置 'compile' 已過時,已被 'implementation' 取代。 將於 2018 年底移除
更改應用插件:'java' 以應用插件:'java-library'
太可笑了,但我還是想分享一下我的經驗,以防有人遇到像我這樣的情況。
請檢查您是否更改: compileSdkVersion
--> implementationSdkVersion
錯誤
對我來說,我把我的依賴放在了錯誤的位置。
buildscript {
dependencies {
//Don't put dependencies here.
}
}
dependencies {
//Put them here
}
你的代碼
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
替換為
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
我將implementation
從根級 build.gradle 移動到模塊級 build.gradle。 它解決了這個問題。
如此處所述, https ://stackoverflow.com/a/50941562/2186220,在使用“實現”時使用 gradle 插件版本 3 或更高版本。
此外,在buildscript
使用google()
存儲庫。
buildscript {
repositories {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
}
}
這些更改應該可以解決問題。
用classpath
替換你的implementation
。 那應該工作。
就我而言,這是因為我使用了Implementation
而不是implementation
。
如果未定義實現,則您正在編寫錯誤的文件。 在 Unity 2019+ 上,正確的文件是main template grandle
而不是其他一些。
正如官方文檔中所建議的,您需要添加以下內容:
buildscript {
repositories {
// Gradle 4.1 and higher include support for Google's Maven repo using
// the google() method. And you need to include this repo to download
// Android Gradle plugin 3.0.0 or higher.
google()
...
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.0'
}
}
添加這些刪除我的錯誤。 也使用實現而不是編譯。
對我來說,問題是我寫道:
android {
compileSdk 31
…
代替:
android {
compileSdkVersion 31
所以確保你的build.gradle
是正確的。
La implementación es una configuración dedependencia que se usa para la declaración de la biblioteca y Google la introdujo en ellemento Android Gradle 3.0。 Lasdependencias de implementación se declaran en esta configuración que es interna y no está destinada a la exposición del consumidor。
El motivo principal del 錯誤“No se pudo encontrar la implementationación del método() para los argumentos [com.android.support:appcompat-v7:26.0.0]”“es que Gradle no puedación de laconfiguraciocer.
métodos para resolver este 錯誤:
方法 1:實現 Gradle 的最新版本
方法 2:Cambiar "implementación" 一個 "compilar"
方法 3:mover lasdependencias al módulo build.gradle
方法 4:cambie el Complemento de aplicación:“java”和“java-library”
方法 5:Cambie "implementationSdkVersion" 和 "compileSdkVersion"
Fuente de informationación, para mas detalles[aquí]: https://www.geeksforgeeks.org/fix-error-could-not-find-method-implementation-for-arguments-com-android-supportappcompat-v726-0-0 -在-android-studio/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.