ClashMetaForAndroid/app/build.gradle.kts
Steve Johnson ecf03507e6 Squashed commit of the following:
commit 574fba87ab733332efa17733a6602a1649e62379
Author: Steve Johnson <stevejohnson1438@proton.me>
Date:   Sun Oct 29 21:31:23 2023 +0800

    support importing local geofile

commit ec410293f3abe29835645233349d026d3a55acc0
Author: Steve Johnson <stevejohnson1438@proton.me>
Date:   Sun Oct 29 17:18:52 2023 +0800

    release assets at runtime

commit 2dfb95bab98ba661a28efe255e2965c35c6580c4
Author: Steve Johnson <stevejohnson1438@proton.me>
Date:   Sun Oct 29 16:43:41 2023 +0800

    remove embedded country.mmdb

commit fb245ed4a3c257284685f3b1bee5d9f7333833ce
Author: Steve Johnson <stevejohnson1438@proton.me>
Date:   Sun Oct 29 16:35:14 2023 +0800

    simplity gradle

commit 2fb75c87a13dea7e5c8f8f4126cc53d2d6926b99
Author: Steve Johnson <stevejohnson1438@proton.me>
Date:   Sun Oct 29 16:06:17 2023 +0800

    add geofiles download
2023-10-29 21:38:36 +08:00

68 lines
2.0 KiB
Plaintext

import java.net.URL
import java.nio.file.Files
import java.nio.file.StandardCopyOption
plugins {
kotlin("android")
kotlin("kapt")
id("com.android.application")
}
dependencies {
compileOnly(project(":hideapi"))
implementation(project(":core"))
implementation(project(":service"))
implementation(project(":design"))
implementation(project(":common"))
implementation(libs.kotlin.coroutine)
implementation(libs.androidx.core)
implementation(libs.androidx.activity)
implementation(libs.androidx.fragment)
implementation(libs.androidx.appcompat)
implementation(libs.androidx.coordinator)
implementation(libs.androidx.recyclerview)
implementation(libs.google.material)
}
tasks.getByName("clean", type = Delete::class) {
delete(file("release"))
}
val geoFilesDownloadDir = "src/main/assets"
task("downloadGeoFiles") {
val geoFilesUrls = mapOf(
"https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip.metadb" to "geoip.metadb",
"https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geosite.dat" to "geosite.dat",
// "https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/country.mmdb" to "country.mmdb",
)
doLast {
geoFilesUrls.forEach { (downloadUrl, outputFileName) ->
val url = URL(downloadUrl)
val outputPath = file("$geoFilesDownloadDir/$outputFileName")
outputPath.parentFile.mkdirs()
url.openStream().use { input ->
Files.copy(input, outputPath.toPath(), StandardCopyOption.REPLACE_EXISTING)
println("$outputFileName downloaded to $outputPath")
}
}
}
}
afterEvaluate {
val downloadGeoFilesTask = tasks["downloadGeoFiles"]
tasks.forEach {
if (it.name.startsWith("assemble")) {
it.dependsOn(downloadGeoFilesTask)
}
}
}
tasks.getByName("clean", type = Delete::class) {
delete(file(geoFilesDownloadDir))
}