build.gradle.kts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. import com.google.protobuf.gradle.*
  2. plugins {
  3. alias(libs.plugins.agp.app)
  4. alias(libs.plugins.kotlin)
  5. alias(libs.plugins.protobuf)
  6. alias(libs.plugins.lsplugin.resopt)
  7. alias(libs.plugins.lsplugin.jgit)
  8. alias(libs.plugins.lsplugin.apksign)
  9. alias(libs.plugins.lsplugin.apktransform)
  10. alias(libs.plugins.lsplugin.cmaker)
  11. }
  12. val appVerCode = jgit.repo()?.commitCount("refs/remotes/origin/master") ?: 0
  13. val appVerName: String by rootProject
  14. apksign {
  15. storeFileProperty = "releaseStoreFile"
  16. storePasswordProperty = "releaseStorePassword"
  17. keyAliasProperty = "releaseKeyAlias"
  18. keyPasswordProperty = "releaseKeyPassword"
  19. }
  20. apktransform {
  21. copy {
  22. when (it.buildType) {
  23. "release" -> file("${it.name}/BiliRoaming_${appVerName}.apk")
  24. else -> null
  25. }
  26. }
  27. }
  28. cmaker {
  29. default {
  30. targets("biliroaming")
  31. abiFilters("armeabi-v7a", "arm64-v8a", "x86")
  32. arguments += arrayOf(
  33. "-DANDROID_STL=none",
  34. "-DCMAKE_CXX_STANDARD=23",
  35. "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON",
  36. )
  37. cFlags += "-flto"
  38. cppFlags += "-flto"
  39. }
  40. buildTypes {
  41. arguments += "-DDEBUG_SYMBOLS_PATH=${layout.buildDirectory.file("symbols/${it.name}").get().asFile.absolutePath}"
  42. }
  43. }
  44. android {
  45. namespace = "me.iacn.biliroaming"
  46. compileSdk = 35
  47. buildToolsVersion = "35.0.0"
  48. ndkVersion = "29.0.14206865"
  49. buildFeatures {
  50. prefab = true
  51. buildConfig = true
  52. }
  53. defaultConfig {
  54. applicationId = "me.iacn.biliroaming"
  55. minSdk = 24
  56. targetSdk = 35 // Target Android U
  57. versionCode = appVerCode
  58. versionName = appVerName
  59. }
  60. buildTypes {
  61. release {
  62. isMinifyEnabled = true
  63. isShrinkResources = true
  64. proguardFiles("proguard-rules.pro")
  65. }
  66. }
  67. compileOptions {
  68. sourceCompatibility(JavaVersion.VERSION_11)
  69. targetCompatibility(JavaVersion.VERSION_11)
  70. }
  71. kotlinOptions {
  72. jvmTarget = "11"
  73. freeCompilerArgs = listOf(
  74. "-Xno-param-assertions",
  75. "-Xno-call-assertions",
  76. "-Xno-receiver-assertions",
  77. "-language-version=2.0",
  78. )
  79. }
  80. sourceSets {
  81. named("main") {
  82. proto {
  83. srcDir("src/main/proto")
  84. include("**/*.proto")
  85. }
  86. }
  87. }
  88. packaging {
  89. resources {
  90. excludes += "**"
  91. }
  92. }
  93. lint {
  94. checkReleaseBuilds = false
  95. }
  96. dependenciesInfo {
  97. includeInApk = false
  98. }
  99. androidResources {
  100. additionalParameters += arrayOf("--allow-reserved-package-id", "--package-id", "0x23")
  101. }
  102. externalNativeBuild {
  103. cmake {
  104. path("src/main/jni/CMakeLists.txt")
  105. version = "4.1.0+"
  106. }
  107. }
  108. }
  109. protobuf {
  110. protoc {
  111. artifact = libs.protobuf.protoc.get().toString()
  112. }
  113. generateProtoTasks {
  114. all().forEach { task ->
  115. task.builtins {
  116. id("java") {
  117. option("lite")
  118. }
  119. id("kotlin") {
  120. option("lite")
  121. }
  122. }
  123. }
  124. }
  125. }
  126. configurations.all {
  127. exclude("org.jetbrains.kotlin", "kotlin-stdlib-jdk7")
  128. exclude("org.jetbrains.kotlin", "kotlin-stdlib-jdk8")
  129. }
  130. dependencies {
  131. compileOnly(libs.xposed)
  132. implementation(libs.protobuf.kotlin)
  133. implementation(libs.protobuf.java)
  134. compileOnly(libs.protobuf.protoc)
  135. implementation(libs.kotlin.stdlib)
  136. implementation(libs.kotlin.coroutines.android)
  137. implementation(libs.kotlin.coroutines.jdk)
  138. implementation(libs.androidx.documentfile)
  139. implementation(libs.cxx)
  140. implementation(libs.okhttp)
  141. }
  142. val adbExecutable: String = androidComponents.sdkComponents.adb.get().asFile.absolutePath
  143. val restartBiliBili = task("restartBiliBili").apply {
  144. doLast {
  145. exec {
  146. commandLine(adbExecutable, "shell", "am", "force-stop", "tv.danmaku.bili")
  147. }
  148. exec {
  149. commandLine(
  150. adbExecutable,
  151. "shell",
  152. "am",
  153. "start",
  154. "$(pm resolve-activity --components tv.danmaku.bili)"
  155. )
  156. }
  157. }
  158. }
  159. afterEvaluate {
  160. tasks.getByPath("installDebug").finalizedBy(restartBiliBili)
  161. }