build.gradle.kts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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 = 91
  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.material3.adapter)
  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.swiperefresh)
  154. implementation(compose.accompanist.flowlayout)
  155. implementation(compose.accompanist.permissions)
  156. implementation(androidx.paging.runtime)
  157. implementation(androidx.paging.compose)
  158. implementation(libs.bundles.sqlite)
  159. implementation(androidx.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. // Model View Presenter
  200. implementation(libs.bundles.nucleus)
  201. // Dependency injection
  202. implementation(libs.injekt.core)
  203. // Image loading
  204. implementation(libs.bundles.coil)
  205. implementation(libs.subsamplingscaleimageview) {
  206. exclude(module = "image-decoder")
  207. }
  208. implementation(libs.image.decoder)
  209. // Sort
  210. implementation(libs.natural.comparator)
  211. // UI libraries
  212. implementation(libs.material)
  213. implementation(libs.flexible.adapter.core)
  214. implementation(libs.flexible.adapter.ui)
  215. implementation(libs.photoview)
  216. implementation(libs.directionalviewpager) {
  217. exclude(group = "androidx.viewpager", module = "viewpager")
  218. }
  219. implementation(libs.insetter)
  220. implementation(libs.markwon)
  221. implementation(libs.aboutLibraries.compose)
  222. implementation(libs.cascade)
  223. implementation(libs.bundles.voyager)
  224. implementation(libs.wheelpicker)
  225. // Conductor
  226. implementation(libs.bundles.conductor)
  227. // FlowBinding
  228. implementation(libs.bundles.flowbinding)
  229. // Logging
  230. implementation(libs.logcat)
  231. // Crash reports/analytics
  232. implementation(libs.acra.http)
  233. "standardImplementation"(libs.firebase.analytics)
  234. // Shizuku
  235. implementation(libs.bundles.shizuku)
  236. // Tests
  237. testImplementation(libs.junit)
  238. // For detecting memory leaks; see https://square.github.io/leakcanary/
  239. // debugImplementation(libs.leakcanary.android)
  240. implementation(libs.leakcanary.plumber)
  241. }
  242. androidComponents {
  243. beforeVariants { variantBuilder ->
  244. // Disables standardBenchmark
  245. if (variantBuilder.buildType == "benchmark") {
  246. variantBuilder.enable = variantBuilder.productFlavors.containsAll(listOf("default" to "dev"))
  247. }
  248. }
  249. onVariants(selector().withFlavor("default" to "standard")) {
  250. // Only excluding in standard flavor because this breaks
  251. // Layout Inspector's Compose tree
  252. it.packaging.resources.excludes.add("META-INF/*.version")
  253. }
  254. }
  255. tasks {
  256. withType<Test> {
  257. useJUnitPlatform()
  258. testLogging {
  259. events(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED)
  260. }
  261. }
  262. withType<org.jmailen.gradle.kotlinter.tasks.LintTask>().configureEach {
  263. exclude { it.file.path.contains("generated[\\\\/]".toRegex()) }
  264. }
  265. // See https://kotlinlang.org/docs/reference/experimental.html#experimental-status-of-experimental-api(-markers)
  266. withType<KotlinCompile> {
  267. kotlinOptions.freeCompilerArgs += listOf(
  268. "-opt-in=coil.annotation.ExperimentalCoilApi",
  269. "-opt-in=com.google.accompanist.permissions.ExperimentalPermissionsApi",
  270. "-opt-in=androidx.compose.material.ExperimentalMaterialApi",
  271. "-opt-in=androidx.compose.material3.ExperimentalMaterial3Api",
  272. "-opt-in=androidx.compose.ui.ExperimentalComposeUiApi",
  273. "-opt-in=androidx.compose.foundation.ExperimentalFoundationApi",
  274. "-opt-in=androidx.compose.animation.ExperimentalAnimationApi",
  275. "-opt-in=androidx.compose.animation.graphics.ExperimentalAnimationGraphicsApi",
  276. "-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
  277. "-opt-in=kotlinx.coroutines.FlowPreview",
  278. "-opt-in=kotlinx.coroutines.InternalCoroutinesApi",
  279. "-opt-in=kotlinx.serialization.ExperimentalSerializationApi",
  280. )
  281. if (project.findProperty("tachiyomi.enableComposeCompilerMetrics") == "true") {
  282. kotlinOptions.freeCompilerArgs += listOf(
  283. "-P",
  284. "plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=" +
  285. project.buildDir.absolutePath + "/compose_metrics"
  286. )
  287. kotlinOptions.freeCompilerArgs += listOf(
  288. "-P",
  289. "plugin:androidx.compose.compiler.plugins.kotlin:metricsDestination=" +
  290. project.buildDir.absolutePath + "/compose_metrics"
  291. )
  292. }
  293. }
  294. preBuild {
  295. val ktlintTask = if (System.getenv("GITHUB_BASE_REF") == null) formatKotlin else lintKotlin
  296. dependsOn(ktlintTask)
  297. }
  298. }
  299. buildscript {
  300. dependencies {
  301. classpath(kotlinx.gradle)
  302. }
  303. }