我已在项目的 build.gradle
中将每次出现的 compile
替换为 implementation
,但我仍然收到此警告:
https://i.stack.imgur.com/rXimx.png
我试图在整个项目中寻找“编译”,但没有找到匹配项。那么可能是什么原因呢?
compile
..
Failed to resolve: android.arch.persistence.room:runtime:1.1.1 Open File Show in Project Structure dialog
尝试将版本更改为 1.0.0
我已将 com.google.gms:google-services
从 3.1.1
更新为 3.2.0
,警告不再出现。
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.2.0'
}
}
我对 com.google.gms:google-services 也有同样的警告。
解决方案是在 build.gradle 项目的文件中将 classpath com.google.gms:google-services 升级为 classpath 'com.google.gms:google-services:3.2.0':
https://i.stack.imgur.com/N9S5z.png
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.2.0'
}
}
allprojects {
repositories {
jcenter()
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
在 Android Studio 版本 3.1 中,依赖项 complie 字被替换为 implementation
android studio 3.1 中带有警告的依赖项
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:27.1.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
android studio 3.1 中的依赖关系OK
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
Gradel 由 Android Studio 3.1 为新项目生成。
https://i.stack.imgur.com/k98p5.png
访问https://docs.gradle.org/current/userguide/dependency_management_for_java_projects.html
详情https://docs.gradle.org/current/userguide/declaring_dependencies.html
我已将 com.google.gms:google-services 从 3.2.0 更新到 3.2.1,警告停止出现。
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.1'
classpath 'com.google.gms:google-services:3.2.1'
}
}
classpath 'com.google.gms:google-services:4.1.0'
不是最新的,但是是的,它大于 3.2.0
。还没解决!
使用当前最新版本的谷歌 gms 服务为我解决了这个问题。
在项目级别的 build.gradle 中:
buildscript {
...
dependencies {
classpath 'com.google.gms:google-services:3.2.1'
...
}
}
打开位于此处的 build.gradle 文件:
https://i.stack.imgur.com/Ktni5.png
这是编写依赖库的旧方法(对于 gradle 版本 2 及以下版本):
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile files('libs/volley.jar')
compile 'com.android.support:support-v4:21.+'
}
这是为 gradle 版本 3 导入依赖项的新(正确)方式:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'
implementation files('libs/volley.jar')
implementation 'com.android.support:support-v4:21.+'
}
谷歌回复:https://issuetracker.google.com/issues/74048134
仍有一些依赖项仍在使用编译,请仔细检查您的应用程序依赖项和传递依赖项。
https://issuetracker.google.com/issues/72479188 表示插件有时会引入“编译”依赖项,这就是触发警告的原因。可能只是最容易为该问题加注星标并等到他们修复它以指出哪些插件导致问题。
无需删除线。正如 Jkrevis 所写,将 com.google.gms:google-services 更新为 3.2.0 并停止警告。
就我而言,这是由 Realm 库引起的,在我将其更新到 Realm 的最新版本(目前为 5.1.0)后,问题解决了!
这是工作的gradle脚本:
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath "io.realm:realm-gradle-plugin:5.1.0"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.2.1'
}
}
我在不使用 com.google.gms:google-services
的情况下遇到了这个问题。解决此类问题的解决方案如下:
检查所有项目和模块的 build.gradle 文件。或者只是全局搜索关键字“编译”来查找导致此警告的位置。如果上述方法无法解决此警告,则使用 CLI 命令,./gradlew assembleDebug -d > gradle.log 将详细调试信息打印到名为 gradle.log 的文件或任何其他文件中,因为信息太多。然后搜索单词“WARNING”找到gradle.log中的位置,通常可以找到导致警告的依赖或插件。
仅更新 google-service 版本对我不起作用。
首先确保您编译的所有依赖项都替换为实现。
更新项目中的所有依赖项。因为如果您的依赖项之一正在编译,那么您的项目将显示此错误。所以更新所有依赖版本。
我已尝试在 Android Studio 3.0.1 中将 google gms services 更改为最新的 com.google.gms:google-services:3.2.1
,但警告仍然存在。
按照编译器的建议,我将所有 compile
依赖项更改为 implementation
并将 testCompile
更改为 testImplementation
,如下所示。
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:mediarouter-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.google.firebase:firebase-ads:12.0.1'
implementation 'com.google.firebase:firebase-crash:12.0.1'
implementation 'com.google.firebase:firebase-core:12.0.1'
implementation 'com.google.firebase:firebase-messaging:12.0.1'
implementation 'com.google.firebase:firebase-perf:12.0.1'
implementation 'com.google.firebase:firebase-appindexing:12.0.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
最后警告被删除!
转到项目级别的 build.gradle 文件,您会发现以下行突出显示
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4' //place your cursor over here
//and hit alt+enter and it will show you the appropriate version to select
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:4.0.2' //the same as previously
}
在我的情况下,它是一个旧依赖项,它使用 compile 作为传递依赖项:com.jakewharton.hugo
从我的 gradle 中删除它后,它编译了。
对我来说,解决此问题的解决方法是使用旧版本的 Gradle,可以在 here 中找到:
我使用了 gradle-3.0-rc-1-src 版本,但其他版本也可以使用,尽管它可能不应该比 3.0 版本更新。
首先将 zip 文件解压缩到您喜欢的任何位置。
然后转到 File -> Settings -> Build, Execution, Deployment -> Gradle 并将设置更改为 Use local gradle distribution。之后确保 Gradle Home-field 指向您刚刚解压缩到的目录中的 .gradle 目录。
重建项目,一切都应该没问题。
当前版本是 4.2.0:
构建脚本 {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:4.2.0'
}
}
谷歌最近在 2021 年 9 月更新了它的服务。给了更新,我遇到了同样的问题,然后我更新了 android studio 中的 build.gradle 文件
旧版本有问题
classpath 'com.google.gms:google-services:4.3.3'
更新了 build.gradle 中的代码
classpath 'com.google.gms:google-services:4.3.10'
您可以执行以下两个选项:
在你的项目中添加类路径'com.google.gms:google-services:3.2.0':build.gradle 依赖项并替换你的模块:build.gradle 依赖于编译和实现,你不会收到任何警告消息。
只需从 build.gradle
从 build script
添加
classpath 'com.google.gms:google-services:3.2.0'
并且所有依赖项 "compile"
都替换为 "implementation"
。
这对我有用。
classpath
,则必须在 buildscript
块内使用它;此外,不能在 buildscript
块内使用 implementation
。
对我来说,将编译更改为实现已修复它
前
compile 'androidx.recyclerview:recyclerview:1.0.0'
compile 'androidx.cardview:cardview:1.0.0'
//Retrofit Dependencies
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
后
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
//Retrofit Dependencies
implementation 'com.squareup.retrofit2:retrofit:2.1.0'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
我尝试了这里提到的所有解决方案,但没有运气。我在我的 build.gradle 文件中发现如下:
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
}
我只是将其更改如下并保存并尝试构建成功。
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
}
希望您受到 build.gradle(app) 的影响 如果这样做,请按照此步骤操作
用 build.gradle 中的 androidTestImplementation 替换 compile
androidTestImplementation 'com.android.support:appcompat-v7:27.1.1'
androidTestImplementation 'com.android.support:design:27.1.1'
很简单 !希望这能解决
就我而言,问题是 gradle 文件中带有以下行的 Google 服务 gradle 插件:
应用插件:'com.google.gms.google-services'
删除此问题解决了问题
去你build.gradle(应用程序级别)
并将“编译”一词替换为“实现”
它将工作 100%
不定期副业成功案例分享