build.gradle 10 KB

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