build.gradle.kts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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(androidx.sqlite)
  159. implementation(libs.sqldelight.android.driver)
  160. implementation(libs.sqldelight.coroutines)
  161. implementation(libs.sqldelight.android.paging)
  162. implementation(kotlinx.reflect)
  163. implementation(platform(kotlinx.coroutines.bom))
  164. implementation(kotlinx.bundles.coroutines)
  165. // AndroidX libraries
  166. implementation(androidx.annotation)
  167. implementation(androidx.appcompat)
  168. implementation(androidx.biometricktx)
  169. implementation(androidx.constraintlayout)
  170. implementation(androidx.coordinatorlayout)
  171. implementation(androidx.corektx)
  172. implementation(androidx.splashscreen)
  173. implementation(androidx.recyclerview)
  174. implementation(androidx.viewpager)
  175. implementation(androidx.glance)
  176. implementation(androidx.profileinstaller)
  177. implementation(androidx.bundles.lifecycle)
  178. // Job scheduling
  179. implementation(androidx.bundles.workmanager)
  180. // RX
  181. implementation(libs.bundles.reactivex)
  182. implementation(libs.flowreactivenetwork)
  183. // Network client
  184. implementation(libs.bundles.okhttp)
  185. implementation(libs.okio)
  186. // TLS 1.3 support for Android < 10
  187. implementation(libs.conscrypt.android)
  188. // Data serialization (JSON, protobuf)
  189. implementation(kotlinx.bundles.serialization)
  190. // HTML parser
  191. implementation(libs.jsoup)
  192. // Disk
  193. implementation(libs.disklrucache)
  194. implementation(libs.unifile)
  195. implementation(libs.junrar)
  196. // Preferences
  197. implementation(libs.preferencektx)
  198. // Model View Presenter
  199. implementation(libs.bundles.nucleus)
  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. // 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<org.jmailen.gradle.kotlinter.tasks.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. }