build.gradle.kts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. import org.gradle.api.tasks.testing.logging.TestLogEvent
  2. import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
  3. plugins {
  4. id("com.android.application")
  5. id("com.mikepenz.aboutlibraries.plugin")
  6. kotlin("android")
  7. kotlin("plugin.serialization")
  8. id("com.github.zellius.shortcut-helper")
  9. id("com.squareup.sqldelight")
  10. }
  11. if (gradle.startParameter.taskRequests.toString().contains("Standard")) {
  12. apply<com.google.gms.googleservices.GoogleServicesPlugin>()
  13. }
  14. shortcutHelper.setFilePath("./shortcuts.xml")
  15. val SUPPORTED_ABIS = setOf("armeabi-v7a", "arm64-v8a", "x86", "x86_64")
  16. android {
  17. namespace = "eu.kanade.tachiyomi"
  18. compileSdk = AndroidConfig.compileSdk
  19. ndkVersion = AndroidConfig.ndk
  20. defaultConfig {
  21. applicationId = "eu.kanade.tachiyomi"
  22. minSdk = AndroidConfig.minSdk
  23. targetSdk = AndroidConfig.targetSdk
  24. versionCode = 92
  25. versionName = "0.14.2"
  26. buildConfigField("String", "COMMIT_COUNT", "\"${getCommitCount()}\"")
  27. buildConfigField("String", "COMMIT_SHA", "\"${getGitSha()}\"")
  28. buildConfigField("String", "BUILD_TIME", "\"${getBuildTime()}\"")
  29. buildConfigField("boolean", "INCLUDE_UPDATER", "false")
  30. buildConfigField("boolean", "PREVIEW", "false")
  31. // Please disable ACRA or use your own instance in forked versions of the project
  32. buildConfigField("String", "ACRA_URI", "\"https://tachiyomi.kanade.eu/crash_report\"")
  33. ndk {
  34. abiFilters += SUPPORTED_ABIS
  35. }
  36. testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
  37. }
  38. splits {
  39. abi {
  40. isEnable = true
  41. reset()
  42. include(*SUPPORTED_ABIS.toTypedArray())
  43. isUniversalApk = true
  44. }
  45. }
  46. buildTypes {
  47. named("debug") {
  48. versionNameSuffix = "-${getCommitCount()}"
  49. applicationIdSuffix = ".debug"
  50. isPseudoLocalesEnabled = true
  51. }
  52. named("release") {
  53. isShrinkResources = true
  54. isMinifyEnabled = true
  55. proguardFiles("proguard-android-optimize.txt", "proguard-rules.pro")
  56. }
  57. create("preview") {
  58. initWith(getByName("release"))
  59. buildConfigField("boolean", "PREVIEW", "true")
  60. val debugType = getByName("debug")
  61. signingConfig = debugType.signingConfig
  62. versionNameSuffix = debugType.versionNameSuffix
  63. applicationIdSuffix = debugType.applicationIdSuffix
  64. matchingFallbacks.add("release")
  65. }
  66. create("benchmark") {
  67. initWith(getByName("release"))
  68. signingConfig = signingConfigs.getByName("debug")
  69. matchingFallbacks.add("release")
  70. isDebuggable = false
  71. versionNameSuffix = "-benchmark"
  72. applicationIdSuffix = ".benchmark"
  73. }
  74. }
  75. sourceSets {
  76. getByName("preview").res.srcDirs("src/debug/res")
  77. getByName("benchmark").res.srcDirs("src/debug/res")
  78. }
  79. flavorDimensions.add("default")
  80. productFlavors {
  81. create("standard") {
  82. buildConfigField("boolean", "INCLUDE_UPDATER", "true")
  83. dimension = "default"
  84. }
  85. create("dev") {
  86. // Include pseudolocales: https://developer.android.com/guide/topics/resources/pseudolocales
  87. resourceConfigurations.addAll(listOf("en", "en_XA", "ar_XB", "xxhdpi"))
  88. dimension = "default"
  89. }
  90. }
  91. packagingOptions {
  92. resources.excludes.addAll(listOf(
  93. "META-INF/DEPENDENCIES",
  94. "LICENSE.txt",
  95. "META-INF/LICENSE",
  96. "META-INF/LICENSE.txt",
  97. "META-INF/README.md",
  98. "META-INF/NOTICE",
  99. "META-INF/*.kotlin_module",
  100. ))
  101. }
  102. dependenciesInfo {
  103. includeInApk = false
  104. }
  105. buildFeatures {
  106. viewBinding = true
  107. compose = true
  108. // Disable some unused things
  109. aidl = false
  110. renderScript = false
  111. shaders = false
  112. }
  113. lint {
  114. abortOnError = false
  115. checkReleaseBuilds = false
  116. }
  117. composeOptions {
  118. kotlinCompilerExtensionVersion = compose.versions.compiler.get()
  119. }
  120. compileOptions {
  121. sourceCompatibility = JavaVersion.VERSION_1_8
  122. targetCompatibility = JavaVersion.VERSION_1_8
  123. isCoreLibraryDesugaringEnabled = true
  124. }
  125. kotlinOptions {
  126. jvmTarget = JavaVersion.VERSION_1_8.toString()
  127. }
  128. sqldelight {
  129. database("Database") {
  130. packageName = "eu.kanade.tachiyomi"
  131. dialect = "sqlite:3.24"
  132. }
  133. }
  134. }
  135. dependencies {
  136. implementation(project(":i18n"))
  137. implementation(project(":core"))
  138. implementation(project(":source-api"))
  139. coreLibraryDesugaring(libs.desugar)
  140. // Compose
  141. implementation(platform(compose.bom))
  142. implementation(compose.activity)
  143. implementation(compose.foundation)
  144. implementation(compose.material3.core)
  145. implementation(compose.material.core)
  146. implementation(compose.material.icons)
  147. implementation(compose.animation)
  148. implementation(compose.animation.graphics)
  149. implementation(compose.ui.tooling)
  150. implementation(compose.ui.util)
  151. implementation(compose.accompanist.webview)
  152. implementation(compose.accompanist.flowlayout)
  153. implementation(compose.accompanist.permissions)
  154. implementation(compose.accompanist.themeadapter)
  155. implementation(androidx.paging.runtime)
  156. implementation(androidx.paging.compose)
  157. implementation(libs.bundles.sqlite)
  158. implementation(libs.sqldelight.android.driver)
  159. implementation(libs.sqldelight.coroutines)
  160. implementation(libs.sqldelight.android.paging)
  161. implementation(kotlinx.reflect)
  162. implementation(platform(kotlinx.coroutines.bom))
  163. implementation(kotlinx.bundles.coroutines)
  164. // AndroidX libraries
  165. implementation(androidx.annotation)
  166. implementation(androidx.appcompat)
  167. implementation(androidx.biometricktx)
  168. implementation(androidx.constraintlayout)
  169. implementation(androidx.coordinatorlayout)
  170. implementation(androidx.corektx)
  171. implementation(androidx.splashscreen)
  172. implementation(androidx.recyclerview)
  173. implementation(androidx.viewpager)
  174. implementation(androidx.glance)
  175. implementation(androidx.profileinstaller)
  176. implementation(androidx.bundles.lifecycle)
  177. // Job scheduling
  178. implementation(androidx.bundles.workmanager)
  179. // RX
  180. implementation(libs.bundles.reactivex)
  181. implementation(libs.flowreactivenetwork)
  182. // Network client
  183. implementation(libs.bundles.okhttp)
  184. implementation(libs.okio)
  185. // TLS 1.3 support for Android < 10
  186. implementation(libs.conscrypt.android)
  187. // Data serialization (JSON, protobuf)
  188. implementation(kotlinx.bundles.serialization)
  189. // HTML parser
  190. implementation(libs.jsoup)
  191. // Disk
  192. implementation(libs.disklrucache)
  193. implementation(libs.unifile)
  194. implementation(libs.junrar)
  195. // Preferences
  196. implementation(libs.preferencektx)
  197. // Dependency injection
  198. implementation(libs.injekt.core)
  199. // Image loading
  200. implementation(libs.bundles.coil)
  201. implementation(libs.subsamplingscaleimageview) {
  202. exclude(module = "image-decoder")
  203. }
  204. implementation(libs.image.decoder)
  205. // Sort
  206. implementation(libs.natural.comparator)
  207. // UI libraries
  208. implementation(libs.material)
  209. implementation(libs.flexible.adapter.core)
  210. implementation(libs.flexible.adapter.ui)
  211. implementation(libs.photoview)
  212. implementation(libs.directionalviewpager) {
  213. exclude(group = "androidx.viewpager", module = "viewpager")
  214. }
  215. implementation(libs.insetter)
  216. implementation(libs.bundles.richtext)
  217. implementation(libs.aboutLibraries.compose)
  218. implementation(libs.cascade)
  219. implementation(libs.bundles.voyager)
  220. implementation(libs.wheelpicker)
  221. // Logging
  222. implementation(libs.logcat)
  223. // Crash reports/analytics
  224. implementation(libs.acra.http)
  225. "standardImplementation"(libs.firebase.analytics)
  226. // Shizuku
  227. implementation(libs.bundles.shizuku)
  228. // Tests
  229. testImplementation(libs.junit)
  230. // For detecting memory leaks; see https://square.github.io/leakcanary/
  231. // debugImplementation(libs.leakcanary.android)
  232. implementation(libs.leakcanary.plumber)
  233. }
  234. androidComponents {
  235. beforeVariants { variantBuilder ->
  236. // Disables standardBenchmark
  237. if (variantBuilder.buildType == "benchmark") {
  238. variantBuilder.enable = variantBuilder.productFlavors.containsAll(listOf("default" to "dev"))
  239. }
  240. }
  241. onVariants(selector().withFlavor("default" to "standard")) {
  242. // Only excluding in standard flavor because this breaks
  243. // Layout Inspector's Compose tree
  244. it.packaging.resources.excludes.add("META-INF/*.version")
  245. }
  246. }
  247. tasks {
  248. withType<Test> {
  249. useJUnitPlatform()
  250. testLogging {
  251. events(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED)
  252. }
  253. }
  254. withType<org.jmailen.gradle.kotlinter.tasks.LintTask>().configureEach {
  255. exclude { it.file.path.contains("generated[\\\\/]".toRegex()) }
  256. }
  257. // See https://kotlinlang.org/docs/reference/experimental.html#experimental-status-of-experimental-api(-markers)
  258. withType<KotlinCompile> {
  259. kotlinOptions.freeCompilerArgs += listOf(
  260. "-opt-in=coil.annotation.ExperimentalCoilApi",
  261. "-opt-in=com.google.accompanist.permissions.ExperimentalPermissionsApi",
  262. "-opt-in=androidx.compose.foundation.layout.ExperimentalLayoutApi",
  263. "-opt-in=androidx.compose.material.ExperimentalMaterialApi",
  264. "-opt-in=androidx.compose.material3.ExperimentalMaterial3Api",
  265. "-opt-in=androidx.compose.material.ExperimentalMaterialApi",
  266. "-opt-in=androidx.compose.ui.ExperimentalComposeUiApi",
  267. "-opt-in=androidx.compose.foundation.ExperimentalFoundationApi",
  268. "-opt-in=androidx.compose.animation.ExperimentalAnimationApi",
  269. "-opt-in=androidx.compose.animation.graphics.ExperimentalAnimationGraphicsApi",
  270. "-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
  271. "-opt-in=kotlinx.coroutines.FlowPreview",
  272. "-opt-in=kotlinx.coroutines.InternalCoroutinesApi",
  273. "-opt-in=kotlinx.serialization.ExperimentalSerializationApi",
  274. )
  275. if (project.findProperty("tachiyomi.enableComposeCompilerMetrics") == "true") {
  276. kotlinOptions.freeCompilerArgs += listOf(
  277. "-P",
  278. "plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=" +
  279. project.buildDir.absolutePath + "/compose_metrics"
  280. )
  281. kotlinOptions.freeCompilerArgs += listOf(
  282. "-P",
  283. "plugin:androidx.compose.compiler.plugins.kotlin:metricsDestination=" +
  284. project.buildDir.absolutePath + "/compose_metrics"
  285. )
  286. }
  287. }
  288. preBuild {
  289. val ktlintTask = if (System.getenv("GITHUB_BASE_REF") == null) formatKotlin else lintKotlin
  290. dependsOn(ktlintTask)
  291. }
  292. }
  293. buildscript {
  294. dependencies {
  295. classpath(kotlinx.gradle)
  296. }
  297. }