build.gradle.kts 11 KB

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