build.gradle.kts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import java.net.URL
  2. import java.nio.file.Files
  3. import java.nio.file.StandardCopyOption
  4. plugins {
  5. kotlin("android")
  6. kotlin("kapt")
  7. id("com.android.application")
  8. }
  9. dependencies {
  10. compileOnly(project(":hideapi"))
  11. implementation(project(":core"))
  12. implementation(project(":service"))
  13. implementation(project(":design"))
  14. implementation(project(":common"))
  15. implementation(libs.kotlin.coroutine)
  16. implementation(libs.androidx.core)
  17. implementation(libs.androidx.activity)
  18. implementation(libs.androidx.fragment)
  19. implementation(libs.androidx.appcompat)
  20. implementation(libs.androidx.coordinator)
  21. implementation(libs.androidx.recyclerview)
  22. implementation(libs.google.material)
  23. }
  24. tasks.getByName("clean", type = Delete::class) {
  25. delete(file("release"))
  26. }
  27. val geoFilesDownloadDir = "src/main/assets"
  28. task("downloadGeoFiles") {
  29. val geoFilesUrls = mapOf(
  30. "https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip.metadb" to "geoip.metadb",
  31. "https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geosite.dat" to "geosite.dat",
  32. // "https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/country.mmdb" to "country.mmdb",
  33. )
  34. doLast {
  35. geoFilesUrls.forEach { (downloadUrl, outputFileName) ->
  36. val url = URL(downloadUrl)
  37. val outputPath = file("$geoFilesDownloadDir/$outputFileName")
  38. outputPath.parentFile.mkdirs()
  39. url.openStream().use { input ->
  40. Files.copy(input, outputPath.toPath(), StandardCopyOption.REPLACE_EXISTING)
  41. println("$outputFileName downloaded to $outputPath")
  42. }
  43. }
  44. }
  45. }
  46. afterEvaluate {
  47. val downloadGeoFilesTask = tasks["downloadGeoFiles"]
  48. tasks.forEach {
  49. if (it.name.startsWith("assemble")) {
  50. it.dependsOn(downloadGeoFilesTask)
  51. }
  52. }
  53. }
  54. tasks.getByName("clean", type = Delete::class) {
  55. delete(file(geoFilesDownloadDir))
  56. }