2021-09-11 09:53:09 +03:00
|
|
|
import com.github.kr328.golang.GolangPlugin
|
2021-05-14 19:51:08 +03:00
|
|
|
import java.io.FileOutputStream
|
|
|
|
import java.net.URL
|
|
|
|
import java.time.Duration
|
|
|
|
|
|
|
|
plugins {
|
|
|
|
kotlin("android")
|
2021-09-11 09:53:09 +03:00
|
|
|
id("com.android.library")
|
2021-05-14 19:51:08 +03:00
|
|
|
id("kotlinx-serialization")
|
2021-09-11 09:53:09 +03:00
|
|
|
id("golang-android")
|
2021-05-14 19:51:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
val geoipDatabaseUrl =
|
|
|
|
"https://github.com/Dreamacro/maxmind-geoip/releases/latest/download/Country.mmdb"
|
|
|
|
val geoipInvalidate = Duration.ofDays(7)!!
|
|
|
|
val geoipOutput = buildDir.resolve("intermediates/golang_blob")
|
|
|
|
|
2021-09-11 09:53:09 +03:00
|
|
|
golang {
|
|
|
|
sourceSets {
|
2021-05-16 12:55:47 +03:00
|
|
|
create("foss") {
|
2021-09-11 09:53:09 +03:00
|
|
|
srcDir.set(file("src/foss/go"))
|
2021-05-14 19:51:08 +03:00
|
|
|
}
|
|
|
|
create("premium") {
|
2021-09-11 09:53:09 +03:00
|
|
|
srcDir.set(file("src/premium/go"))
|
|
|
|
}
|
|
|
|
all {
|
|
|
|
fileName.set("libclash.so")
|
2021-05-14 19:51:08 +03:00
|
|
|
}
|
|
|
|
}
|
2021-09-11 09:53:09 +03:00
|
|
|
}
|
2021-05-14 19:51:08 +03:00
|
|
|
|
2021-09-11 09:53:09 +03:00
|
|
|
android {
|
|
|
|
productFlavors {
|
|
|
|
all {
|
|
|
|
externalNativeBuild {
|
|
|
|
cmake {
|
|
|
|
arguments("-DGO_SOURCE:STRING=${golang.sourceSets.getByName(name).srcDir.asFile.get()}")
|
|
|
|
arguments("-DGO_OUTPUT:STRING=${GolangPlugin.outputDirOf(project, null, null)}")
|
|
|
|
arguments("-DFLAVOR_NAME:STRING=$name")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-05-14 19:51:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
externalNativeBuild {
|
|
|
|
cmake {
|
|
|
|
path = file("src/main/cpp/CMakeLists.txt")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dependencies {
|
2021-09-11 09:53:09 +03:00
|
|
|
implementation(project(":common"))
|
2021-05-14 19:51:08 +03:00
|
|
|
|
|
|
|
implementation(kotlin("stdlib-jdk7"))
|
2021-09-11 09:53:09 +03:00
|
|
|
implementation(deps.androidx.core)
|
|
|
|
implementation(deps.kotlin.coroutine)
|
|
|
|
implementation(deps.kotlin.serialization.json)
|
2021-05-14 19:51:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
repositories {
|
|
|
|
mavenCentral()
|
|
|
|
}
|
|
|
|
|
|
|
|
task("downloadGeoipDatabase") {
|
|
|
|
val databaseFile = geoipOutput.resolve("Country.mmdb")
|
|
|
|
val moduleFile = geoipOutput.resolve("go.mod")
|
|
|
|
val sourceFile = geoipOutput.resolve("blob.go")
|
|
|
|
|
|
|
|
val moduleContent = """
|
|
|
|
module "cfa/blob"
|
|
|
|
""".trimIndent()
|
|
|
|
|
|
|
|
val sourceContent = """
|
|
|
|
package blob
|
|
|
|
|
|
|
|
import _ "embed"
|
|
|
|
|
|
|
|
//go:embed Country.mmdb
|
|
|
|
var GeoipDatabase []byte
|
|
|
|
""".trimIndent()
|
|
|
|
|
2021-09-11 09:53:09 +03:00
|
|
|
outputs.dir(geoipOutput)
|
|
|
|
|
2021-05-14 19:51:08 +03:00
|
|
|
onlyIf {
|
|
|
|
System.currentTimeMillis() - databaseFile.lastModified() > geoipInvalidate.toMillis()
|
|
|
|
}
|
|
|
|
|
|
|
|
doLast {
|
|
|
|
geoipOutput.mkdirs()
|
|
|
|
|
|
|
|
moduleFile.writeText(moduleContent)
|
|
|
|
sourceFile.writeText(sourceContent)
|
|
|
|
|
|
|
|
URL(geoipDatabaseUrl).openConnection().getInputStream().use { input ->
|
|
|
|
FileOutputStream(databaseFile).use { output ->
|
|
|
|
input.copyTo(output)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
afterEvaluate {
|
|
|
|
val downloadTask = tasks["downloadGeoipDatabase"]
|
|
|
|
|
|
|
|
tasks.forEach {
|
|
|
|
if (it.name.startsWith("externalGolangBuild")) {
|
|
|
|
it.dependsOn(downloadTask)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|