build.gradle编译已弃用警告

时间:2019-07-03 21:41:06

标签: android android-studio android-gradle

我正在尝试在android studio上运行我的一个老项目,该项目的最后一次编辑是在2017年,从那时以来一直没有被触及。

我一直在将gradle文件中的“ compile”更改为“ implementation”时出错,但仍然收到相同的警告

"WARNING: Configuration 'compile' is obsolete and has been replaced 
with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: 
http://d.android.com/r/tools/update-dependency-configurations.html
Affected Modules: app"

这是gradle文件中的实际代码

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:recyclerview-v7:27.1.1'

它应该在没有此警告的情况下成功构建,我在这里做错了什么?

4 个答案:

答案 0 :(得分:0)

您可以尝试this

只需更新

  

com.google.gms:google-services

答案 1 :(得分:0)

您可以尝试以下操作: 转到文件>使用Gradle文件同步项目

然后与系统完成同步

转到文件>使缓存无效并重新启动

希望它能起作用

答案 2 :(得分:0)

尽管我看不到您的依赖项列表有任何问题,但是请使用调试日志来确定哪个依赖项是造成这种情况的原因。 使用命令行进行编译并在某些文件中收集日志。

gradlew assembleDebug --debug > abc_1.txt

println("....1")
implementation fileTree(dir: 'libs', include: ['*.jar'])
println("....2")
implementation 'com.android.support:appcompat-v7:27.1.1'
println("....3")
testImplementation 'junit:junit:4.12'
println("....4")
androidTestImplementation 'com.android.support.test:runner:1.0.2'
println("....5")
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
println("....6")
implementation 'com.android.support:appcompat-v7:27.1.1'
println("....7")
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
println("....8")
implementation 'com.android.support:recyclerview-v7:27.1.1'
println("....9")

我的示例输出

10:22:23.633 [QUIET] [system.out] ...1
10:22:23.633 [QUIET] [system.out] ...2
10:22:23.634 [QUIET] [system.out] ...3
10:22:23.634 [QUIET] [system.out] ...4
10:22:23.634 [QUIET] [system.out] ...5
10:22:23.634 [QUIET] [system.out] ...6
10:22:23.635 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Build operation 'Execute container callback action' started
10:22:23.635 [WARN] [org.gradle.api.Project] WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
10:22:23.635 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Completing Build operation 'Execute container callback action'
10:22:23.635 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Build operation 'Execute container callback action' completed
10:22:23.635 [QUIET] [system.out] ...7
10:22:23.635 [QUIET] [system.out] ...8
10:22:23.636 [QUIET] [system.out] ...9
10:22:23.636 [QUIET] [system.out] ...10

答案 3 :(得分:0)

我在项目中使用的是很旧的领域版本

classpath "io.realm:realm-gradle-plugin:2.2.1"

更新为

之后
classpath "io.realm:realm-gradle-plugin:5.12.0"

警告消失了,一切又恢复正常了