build.gradle 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. plugins {
  2. // id "com.android.application"
  3. // id 'org.jetbrains.kotlin.android'
  4. // id 'kotlin-parcelize'
  5. // //id 'kotlin-kapt'
  6. // id 'com.google.devtools.ksp'
  7. // id "com.google.gms.google-services"
  8. alias libs.plugins.android.application
  9. alias libs.plugins.kotlin.android
  10. alias libs.plugins.kotlin.parcelize
  11. alias libs.plugins.room
  12. alias libs.plugins.ksp
  13. alias libs.plugins.google.services
  14. }
  15. apply from: 'download.gradle'
  16. def versionPropsFile = file("version.properties")
  17. def versionProps = new Properties()
  18. versionProps.load(new FileInputStream(versionPropsFile))
  19. ext {
  20. versionMajor = versionProps['VERSION_MAJOR'].toInteger()
  21. versionMinor = versionProps['VERSION_MINOR'].toInteger()
  22. versionPatch = versionProps['VERSION_PATCH'].toInteger()
  23. versionSuffix = versionProps['VERSION_SUFFIX'] ?: ""
  24. }
  25. def name = "legado"
  26. def gitCommits = Integer.parseInt('git rev-list HEAD --count'.execute().text.trim())
  27. ext.versionBuild = gitCommits
  28. ext.versionName = "${ext.versionMajor}.${ext.versionMinor}.${ext.versionPatch}${ext.versionSuffix}"
  29. def getGitCommitHash() {
  30. try {
  31. def stdout = new ByteArrayOutputStream()
  32. exec {
  33. commandLine 'git', 'rev-parse', '--short', 'HEAD'
  34. standardOutput = stdout
  35. }
  36. return stdout.toString().trim()
  37. } catch (Exception ignored) {
  38. return "unknown"
  39. }
  40. }
  41. android {
  42. compileSdk = compile_sdk_version
  43. namespace 'io.legato.kazusa'
  44. kotlin {
  45. jvmToolchain {
  46. languageVersion.set(JavaLanguageVersion.of(17))
  47. }
  48. }
  49. signingConfigs {
  50. if (project.hasProperty("RELEASE_STORE_FILE")) {
  51. myConfig {
  52. storeFile file(RELEASE_STORE_FILE)
  53. storePassword RELEASE_STORE_PASSWORD
  54. keyAlias RELEASE_KEY_ALIAS
  55. keyPassword RELEASE_KEY_PASSWORD
  56. v1SigningEnabled true
  57. v2SigningEnabled true
  58. enableV3Signing = true
  59. enableV4Signing = true
  60. }
  61. }
  62. }
  63. defaultConfig {
  64. applicationId "io.legato.kazusa"
  65. minSdk 26
  66. targetSdk 36
  67. versionCode 10000 + gitCommits
  68. versionName project.ext.versionName
  69. testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
  70. project.ext.set("archivesBaseName", name + "_" + versionName)
  71. buildConfigField "String", "Cronet_Version", "\"$CronetVersion\""
  72. buildConfigField "String", "Cronet_Main_Version", "\"$CronetMainVersion\""
  73. javaCompileOptions {
  74. annotationProcessorOptions {
  75. arguments += [
  76. "room.incremental" : "true",
  77. "room.expandProjection": "true",
  78. "room.schemaLocation" : "$projectDir/schemas".toString()
  79. ]
  80. }
  81. }
  82. def buildTime = new Date().format("yyyy-MM-dd HH:mm:ss", TimeZone.getTimeZone("UTC"))
  83. buildConfigField "String", "BUILD_TIME", "\"${buildTime}\""
  84. }
  85. buildFeatures {
  86. buildConfig true
  87. viewBinding true
  88. }
  89. buildTypes {
  90. release {
  91. if (project.hasProperty("RELEASE_STORE_FILE")) {
  92. signingConfig signingConfigs.myConfig
  93. }
  94. //applicationIdSuffix '.release'
  95. manifestPlaceholders.put("app_name", "@string/app_name")
  96. minifyEnabled true
  97. shrinkResources true
  98. proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro', 'cronet-proguard-rules.pro'
  99. }
  100. debug {
  101. applicationIdSuffix ".debug"
  102. if (project.hasProperty("RELEASE_STORE_FILE")) {
  103. signingConfig signingConfigs.myConfig
  104. }
  105. manifestPlaceholders.put("app_name", "@string/app_name")
  106. //applicationIdSuffix '.debug'
  107. versionNameSuffix "_debug+${getGitCommitHash()}"
  108. minifyEnabled false
  109. proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro', 'cronet-proguard-rules.pro'
  110. }
  111. }
  112. splits {
  113. abi {
  114. enable true
  115. reset()
  116. //noinspection ChromeOsAbiSupport
  117. include 'armeabi-v7a', 'arm64-v8a'
  118. universalApk true
  119. }
  120. }
  121. //noinspection GrDeprecatedAPIUsage
  122. flavorDimensions = ['mode']
  123. productFlavors {
  124. app {
  125. dimension "mode"
  126. manifestPlaceholders.put("APP_CHANNEL_VALUE", "app")
  127. }
  128. }
  129. android.applicationVariants.configureEach { variant ->
  130. variant.outputs.configureEach { output ->
  131. def abi = output.getFilter(com.android.build.OutputFile.ABI)
  132. def flavor = variant.productFlavors[0].name
  133. def baseVersionName = variant.versionName
  134. def apkName = "${name}_${flavor}_${baseVersionName}"
  135. if (abi != null) {
  136. apkName += "_${abi}"
  137. }
  138. apkName += ".apk"
  139. output.outputFileName = apkName
  140. }
  141. }
  142. room {
  143. schemaDirectory "$projectDir/schemas"
  144. }
  145. // 设定Room的KSP参数
  146. ksp {
  147. arg("room.incremental", "true")
  148. arg("room.expandProjection", "true")
  149. arg("room.generateKotlin", "false")
  150. //arg("room.schemaLocation", "$projectDir/schemas")
  151. }
  152. compileOptions {
  153. // Flag to enable support for the new language APIs
  154. coreLibraryDesugaringEnabled true
  155. // Sets Java compatibility
  156. sourceCompatibility JavaVersion.VERSION_17
  157. targetCompatibility JavaVersion.VERSION_17
  158. }
  159. packaging {
  160. resources.excludes.add('META-INF/*')
  161. }
  162. sourceSets {
  163. // Adds exported schema location as test app assets.
  164. androidTest.assets.srcDirs += files("$projectDir/schemas".toString())
  165. }
  166. lint {
  167. checkDependencies true
  168. }
  169. tasks.withType(JavaCompile).tap {
  170. configureEach {
  171. //options.compilerArgs << "-Xlint:unchecked"
  172. }
  173. }
  174. }
  175. dependencies {
  176. //compileOnly "com.android.tools.build:gradle:$agp_version"
  177. //noinspection GradleDependency,GradlePackageUpdate
  178. //coreLibraryDesugaring('com.android.tools:desugar_jdk_libs_nio:2.0.4')
  179. coreLibraryDesugaring(libs.desugar)
  180. testImplementation(libs.junit)
  181. androidTestImplementation(libs.bundles.androidTest)
  182. //kotlin
  183. //noinspection GradleDependency,DifferentStdlibGradleVersion
  184. implementation(libs.kotlin.stdlib)
  185. //Kotlin反射
  186. //noinspection GradleDependency,DifferentStdlibGradleVersion
  187. //implementation(libs.kotlin.reflect)
  188. //协程
  189. //def coroutines_version = '1.7.3'
  190. implementation(libs.bundles.coroutines)
  191. //androidX
  192. implementation(libs.core.ktx)
  193. implementation(libs.appcompat.appcompat)
  194. implementation(libs.activity.ktx)
  195. implementation(libs.fragment.ktx)
  196. implementation(libs.preference.ktx)
  197. implementation(libs.androidx.constraintlayout)
  198. implementation(libs.androidx.swiperefreshlayout)
  199. implementation(libs.androidx.recyclerview)
  200. implementation(libs.androidx.viewpager2)
  201. implementation(libs.androidx.webkit)
  202. //google
  203. implementation(libs.material)
  204. implementation(libs.flexbox)
  205. implementation(libs.gson)
  206. //lifecycle
  207. implementation(libs.lifecycle.common.java8)
  208. implementation(libs.lifecycle.service)
  209. //media
  210. implementation(libs.media.media)
  211. // For media playback using ExoPlayer
  212. implementation(libs.media3.exoplayer)
  213. // For loading data using the OkHttp network stack
  214. implementation(libs.media3.datasource.okhttp)
  215. // For exposing and controlling media sessions
  216. //implementation "androidx.media3:media3-session:$media3_version"
  217. //Splitties
  218. implementation(libs.splitties.appctx)
  219. implementation(libs.splitties.systemservices)
  220. implementation(libs.splitties.views)
  221. //room sql语句不高亮解决方法https://issuetracker.google.com/issues/234612964#comment6
  222. implementation(libs.room.runtime)
  223. implementation(libs.room.ktx)
  224. //kapt("androidx.room:room-compiler:$room_version")
  225. ksp(libs.room.compiler)
  226. androidTestImplementation(libs.room.testing)
  227. //liveEventBus
  228. implementation(libs.liveeventbus)
  229. //规则相关
  230. implementation(libs.jsoup)
  231. implementation(libs.json.path)
  232. implementation(libs.jsoupxpath)
  233. implementation(project(path: ':modules:book'))
  234. implementation(project(path: ':modules:rhino'))
  235. //JS rhino
  236. //网络
  237. implementation(libs.okhttp)
  238. implementation(fileTree(dir: 'cronetlib', include: ['*.jar', '*.aar']))
  239. implementation(libs.protobuf.javalite)
  240. //Glide
  241. implementation(libs.glide.glide)
  242. implementation(libs.glide.okhttp)
  243. ksp(libs.glide.ksp)
  244. //Svg
  245. implementation(libs.androidsvg)
  246. //Glide svg plugin
  247. implementation(libs.glide.svg)
  248. //webServer
  249. implementation(libs.nanohttpd.nanohttpd)
  250. implementation(libs.nanohttpd.websocket)
  251. //二维码
  252. //noinspection GradleDependency
  253. implementation(libs.zxing.lite)
  254. //颜色选择
  255. implementation(libs.colorpicker)
  256. //压缩解压
  257. implementation libs.libarchive
  258. //apache
  259. implementation(libs.commons.text)
  260. //MarkDown
  261. implementation(libs.markwon.core)
  262. implementation(libs.markwon.image.glide)
  263. implementation(libs.markwon.ext.tables)
  264. implementation(libs.markwon.html)
  265. //转换繁体
  266. implementation(libs.quick.chinese.transfer.core)
  267. //加解密类库,有些书源使用
  268. //noinspection GradleDependency,GradlePackageUpdate
  269. implementation(libs.hutool.crypto)
  270. //firebase, 崩溃统计和性能统计
  271. implementation platform(libs.firebase.bom)
  272. implementation libs.firebase.analytics
  273. implementation libs.firebase.perf
  274. implementation libs.glide.recyclerview
  275. //LeakCanary, 内存泄露检测
  276. //debugImplementation('com.squareup.leakcanary:leakcanary-android:2.7')
  277. //com.github.AmrDeveloper:CodeView代码编辑已集成到应用内
  278. //epubLib集成到应用内
  279. implementation libs.androidx.datastore.preferences
  280. implementation libs.androidx.palette
  281. implementation libs.androidx.core.splashscreen
  282. implementation libs.androidx.startup.runtime
  283. }