Suj*_*tha 7 java android gradle build.gradle android-gradle-plugin
我知道这个问题:How to add dependencies to project's top-level build.gradle file?
但它没有给出我需要的答案。
假设我的 android 项目有 3 个库模块A,B和C. 而所有三种用途公共依赖发言权D1这里D1是图书馆一样Dagger,Room等等。
现在不是添加D1到所有三个,我正在考虑添加D1到项目级别build.gradle。
我尝试做这样的事情,但它给出了错误:
Could not find method implementation() for arguments [directory 'libs'] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
buildscript {
ext.kotlin_version = '1.3.0'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.dagger:dagger-android-support:2.15'
implementation "com.google.dagger:dagger:2.16"
kapt "com.google.dagger:dagger-android-processor:2.16"
kapt "com.google.dagger:dagger-compiler:2.16"
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Run Code Online (Sandbox Code Playgroud)
在项目级别添加依赖项的正确方法是build.gradle什么?
创建一个名为 例如 的新模块项目,common-libs并将所有常见依赖项放入该项目中,打开common-libs/build.gradle.
改变
implementation fileTree(dir: 'libs', include: ['*.jar'])
Run Code Online (Sandbox Code Playgroud)
到
api fileTree(dir: 'libs', include: ['*.jar'])
Run Code Online (Sandbox Code Playgroud)
然后对于所有上游依赖项目,只需调用
dependencies {
...
api project(':common-libs')
}
Run Code Online (Sandbox Code Playgroud)
请参阅: https: //developer.android.com/studio/build/dependency#dependency_configurations
| 归档时间: |
|
| 查看次数: |
1353 次 |
| 最近记录: |