Jika Anda sudah menggunakan Kotlin Gradle DSL, alternatif untuk menggunakannya dengan cara ini:
Inilah struktur proyek saya
|-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
Saya app/build.gradle.kts
- Menggunakan pendekatan sederhana dengan
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"))))
}
- Menggunakan pendekatan yang sama seperti mengambil dari repositori maven lokal / jauh dengan
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")
}
Itu group
diperlukan, karena itu wajib (bukan opsional / memiliki nilai default) di kotlin implementation
, lihat di bawah:
// 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
)
Penafian: Perbedaannya menggunakan flatDirs
pendekatan no.1 & no.2, saya masih tidak tahu banyak, Anda mungkin ingin mengedit / mengomentari jawaban ini.
Referensi:
- https://stackoverflow.com/a/56828958/3763032
- https://github.com/gradle/gradle/issues/9272