如果您已经在使用Kotlin Gradle DSL,则可以通过以下方式使用它:
这是我的项目结构
|-root
|----- app
|--------- libs // I choose to store the aar here
|-------------- my-libs-01.aar
|-------------- my-libs-02.jar
|--------- build.gradle.kts // app module gradle
|----- common-libs // another aar folder/directory
|----------------- common-libs-01.aar
|----------------- common-libs-02.jar
|----- build.gradle.kts // root gradle
我的 app/build.gradle.kts
- 使用简单的方法
fileTree
// android related config above omitted...
dependencies {
// you can do this to include everything in the both directory
// Inside ./root/common-libs & ./root/app/libs
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar", "*.aar"))))
implementation(fileTree(mapOf("dir" to "../common-libs", "include" to listOf("*.jar", "*.aar"))))
}
- 使用相同的方法,例如从本地/远程Maven存储库中获取
flatDirs
// android related config above omitted...
repositories {
flatDir {
dirs = mutableSetOf(File("libs"), File("../common-libs")
}
}
dependencies {
implementation(group = "", name = "my-libs-01", ext = "aar")
implementation(group = "", name = "my-libs-02", ext = "jar")
implementation(group = "", name = "common-libs-01", ext = "aar")
implementation(group = "", name = "common-libs-02", ext = "jar")
}
的group
需要,由于其强制性的(不可选/有默认值)在科特林implementation
,见下图:
// Filename: ReleaseImplementationConfigurationAccessors.kt
package org.gradle.kotlin.dsl
fun DependencyHandler.`releaseImplementation`(
group: String,
name: String,
version: String? = null,
configuration: String? = null,
classifier: String? = null,
ext: String? = null,
dependencyConfiguration: Action<ExternalModuleDependency>? = null
)
免责声明:使用1号和 flatDirs
2号方法,我还是不太了解,您可能需要编辑/评论此答案。
参考文献:
- https://stackoverflow.com/a/56828958/3763032
- https://github.com/gradle/gradle/issues/9272