build.gradle.kts 11 KB

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