android - 在不同文件中配置 Gradle 依赖项
问题描述
我正在使用位于 build.gradle (Project) 所在目录的外部 dependencies.gradle 文件。我正在使用以下命令
build.gradle (项目)
apply from: 'dependencies.gradle'
依赖项.gradle
ext {
SUPPORT_LIB_VERSION = '28.0.0'
dependencies = [
ANNOTATIONS: "com.android.support:support-annotations:$SUPPORT_LIB_VERSION"
]}
build.gradle(应用程序)
api rootProject.ext.dependencies.ANNOTATIONS
上面的代码工作得很好。我想知道如何使用相同的方法排除组或模块?让我写下我卡住的地方
dependencies = [
espresso: ("com.android.support.test.espresso:espresso-contrib:3.0.2") {
exclude group: 'com.android.support', module: 'appcompat'
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'recyclerview-v7'
}
]
我收到此错误
No signature of method: java.lang.String.call() is applicable for argument types: (dependencies_83n19kvhft5hx8evun34kydx1$_run_closure1$_closure2) values: [dependencies_83n19kvhft5hx8evun34kydx1$_run_closure1$_closure2@759d33fd] Possible solutions: wait(), any(), wait(long), take(int), any(groovy.lang.Closure), each(groovy.lang.Closure)
解决方案
如果要排除某些数据,则需要在build.gradle
文件中进行:
依赖项.gradle
dependencies = [
espresso: "com.android.support.test.espresso:espresso-contrib:3.0.2"
]
构建.gradle
testImplementation(rootProject.ext.dependencies.espresso) {
exclude group: 'com.android.support', module: 'appcompat'
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'recyclerview-v7'
}
因为implementation(object) { //Closure... }
是一个有 2 个参数的方法:对象和动作。你可以看到这个文档。
推荐阅读
- mysql - 如何编写 MySQL sql 查询?
- datetime - 如何在容器中注入 Docker 容器构建时间戳?
- ios - 如何将CALayer放在视频数据输出的CMSampleBuffer上?
- vue.js - 返回Vue中静态资源(png)的路径
- android - DFU模式下的蓝牙:某些设备的连接总是失败
- node.js - 在回调函数中更改全局变量值
- css - 在 TYPO3 中使用自己的自定义 css
- android - 如果 Oreo 上的屏幕关闭,我的 WebView 不会呈现 HTML 页面
- python - Pytorch 张量 - 如何通过特定张量获取索引
- node.js - 在 NodeJS 中启用 CORS