build.gradle.kts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
  2. import java.io.ByteArrayOutputStream
  3. import java.text.SimpleDateFormat
  4. import java.util.Date
  5. import java.util.TimeZone
  6. plugins {
  7. id("com.android.application")
  8. id("com.mikepenz.aboutlibraries.plugin")
  9. kotlin("android")
  10. kotlin("plugin.serialization")
  11. id("com.github.zellius.shortcut-helper")
  12. }
  13. if (gradle.startParameter.taskRequests.toString().contains("Standard")) {
  14. apply(plugin = "com.google.gms.google-services")
  15. }
  16. shortcutHelper.setFilePath("./shortcuts.xml")
  17. val SUPPORTED_ABIS = setOf("armeabi-v7a", "arm64-v8a", "x86")
  18. android {
  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 = 75
  26. versionName = "0.13.1"
  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. }
  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. }
  65. }
  66. sourceSets {
  67. getByName("preview").res.srcDirs("src/debug/res")
  68. }
  69. flavorDimensions.add("default")
  70. productFlavors {
  71. create("standard") {
  72. buildConfigField("boolean", "INCLUDE_UPDATER", "true")
  73. dimension = "default"
  74. }
  75. create("dev") {
  76. resourceConfigurations.addAll(listOf("en", "xxhdpi"))
  77. dimension = "default"
  78. }
  79. }
  80. packagingOptions {
  81. resources.excludes.addAll(listOf(
  82. "META-INF/DEPENDENCIES",
  83. "LICENSE.txt",
  84. "META-INF/LICENSE",
  85. "META-INF/LICENSE.txt",
  86. "META-INF/README.md",
  87. "META-INF/NOTICE",
  88. "META-INF/*.kotlin_module",
  89. "META-INF/*.version",
  90. ))
  91. }
  92. dependenciesInfo {
  93. includeInApk = false
  94. }
  95. buildFeatures {
  96. viewBinding = true
  97. // Disable some unused things
  98. aidl = false
  99. renderScript = false
  100. shaders = false
  101. }
  102. lint {
  103. disable.addAll(listOf("MissingTranslation", "ExtraTranslation"))
  104. abortOnError = false
  105. checkReleaseBuilds = false
  106. }
  107. compileOptions {
  108. sourceCompatibility = JavaVersion.VERSION_1_8
  109. targetCompatibility = JavaVersion.VERSION_1_8
  110. }
  111. kotlinOptions {
  112. jvmTarget = JavaVersion.VERSION_1_8.toString()
  113. }
  114. }
  115. dependencies {
  116. implementation(kotlin("reflect", version = BuildPluginsVersion.KOTLIN))
  117. val coroutinesVersion = "1.6.0"
  118. implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
  119. implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion")
  120. // Source models and interfaces from Tachiyomi 1.x
  121. implementation("org.tachiyomi:source-api:1.1")
  122. // AndroidX libraries
  123. implementation("androidx.annotation:annotation:1.4.0-alpha02")
  124. implementation("androidx.appcompat:appcompat:1.4.1")
  125. implementation("androidx.biometric:biometric-ktx:1.2.0-alpha04")
  126. implementation("androidx.browser:browser:1.4.0")
  127. implementation("androidx.constraintlayout:constraintlayout:2.1.3")
  128. implementation("androidx.coordinatorlayout:coordinatorlayout:1.2.0")
  129. implementation("androidx.core:core-ktx:1.8.0-alpha04")
  130. implementation("androidx.core:core-splashscreen:1.0.0-alpha02")
  131. implementation("androidx.recyclerview:recyclerview:1.3.0-alpha01")
  132. implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.2.0-alpha01")
  133. implementation("androidx.viewpager:viewpager:1.1.0-alpha01")
  134. val lifecycleVersion = "2.5.0-alpha02"
  135. implementation("androidx.lifecycle:lifecycle-common:$lifecycleVersion")
  136. implementation("androidx.lifecycle:lifecycle-process:$lifecycleVersion")
  137. implementation("androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleVersion")
  138. // Job scheduling
  139. implementation("androidx.work:work-runtime-ktx:2.6.0")
  140. // RX
  141. implementation("io.reactivex:rxandroid:1.2.1")
  142. implementation("io.reactivex:rxjava:1.3.8")
  143. implementation("com.jakewharton.rxrelay:rxrelay:1.2.0")
  144. implementation("ru.beryukhov:flowreactivenetwork:1.0.4")
  145. // Network client
  146. val okhttpVersion = "4.9.1"
  147. implementation("com.squareup.okhttp3:okhttp:$okhttpVersion")
  148. implementation("com.squareup.okhttp3:logging-interceptor:$okhttpVersion")
  149. implementation("com.squareup.okhttp3:okhttp-dnsoverhttps:$okhttpVersion")
  150. implementation("com.squareup.okio:okio:3.0.0")
  151. // TLS 1.3 support for Android < 10
  152. implementation("org.conscrypt:conscrypt-android:2.5.2")
  153. // Data serialization (JSON, protobuf)
  154. val kotlinSerializationVersion = "1.3.2"
  155. implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinSerializationVersion")
  156. implementation("org.jetbrains.kotlinx:kotlinx-serialization-protobuf:$kotlinSerializationVersion")
  157. // JavaScript engine
  158. implementation("app.cash.quickjs:quickjs-android:0.9.2")
  159. // TODO: remove Duktape once all extensions are using QuickJS
  160. implementation("com.squareup.duktape:duktape-android:1.4.0")
  161. // HTML parser
  162. implementation("org.jsoup:jsoup:1.14.3")
  163. // Disk
  164. implementation("com.jakewharton:disklrucache:2.0.2")
  165. implementation("com.github.tachiyomiorg:unifile:17bec43")
  166. implementation("com.github.junrar:junrar:7.4.0")
  167. // Database
  168. implementation("androidx.sqlite:sqlite-ktx:2.2.0")
  169. implementation("com.github.inorichi.storio:storio-common:8be19de@aar")
  170. implementation("com.github.inorichi.storio:storio-sqlite:8be19de@aar")
  171. implementation("com.github.requery:sqlite-android:3.36.0")
  172. // Preferences
  173. implementation("androidx.preference:preference-ktx:1.2.0")
  174. implementation("com.fredporciuncula:flow-preferences:1.6.0")
  175. // Model View Presenter
  176. val nucleusVersion = "3.0.0"
  177. implementation("info.android15.nucleus:nucleus:$nucleusVersion")
  178. implementation("info.android15.nucleus:nucleus-support-v7:$nucleusVersion")
  179. // Dependency injection
  180. implementation("com.github.inorichi.injekt:injekt-core:65b0440")
  181. // Image loading
  182. val coilVersion = "1.4.0"
  183. implementation("io.coil-kt:coil:$coilVersion")
  184. implementation("io.coil-kt:coil-gif:$coilVersion")
  185. implementation("com.github.tachiyomiorg:subsampling-scale-image-view:846abe0") {
  186. exclude(module = "image-decoder")
  187. }
  188. implementation("com.github.tachiyomiorg:image-decoder:7481a4a")
  189. // Sort
  190. implementation("com.github.gpanther:java-nat-sort:natural-comparator-1.1")
  191. // UI libraries
  192. implementation("com.google.android.material:material:1.6.0-alpha02")
  193. implementation("com.github.dmytrodanylyk.android-process-button:library:1.0.4")
  194. implementation("com.github.arkon.FlexibleAdapter:flexible-adapter:c8013533")
  195. implementation("com.github.arkon.FlexibleAdapter:flexible-adapter-ui:c8013533")
  196. implementation("com.nightlynexus.viewstatepageradapter:viewstatepageradapter:1.1.0")
  197. implementation("com.github.chrisbanes:PhotoView:2.3.0")
  198. implementation("com.github.tachiyomiorg:DirectionalViewPager:1.0.0") {
  199. exclude(group = "androidx.viewpager", module = "viewpager")
  200. }
  201. implementation("dev.chrisbanes.insetter:insetter:0.6.1")
  202. // Conductor
  203. val conductorVersion = "3.1.2"
  204. implementation("com.bluelinelabs:conductor:$conductorVersion")
  205. implementation("com.bluelinelabs:conductor-viewpager:$conductorVersion")
  206. implementation("com.github.tachiyomiorg:conductor-support-preference:$conductorVersion")
  207. // FlowBinding
  208. val flowbindingVersion = "1.2.0"
  209. implementation("io.github.reactivecircus.flowbinding:flowbinding-android:$flowbindingVersion")
  210. implementation("io.github.reactivecircus.flowbinding:flowbinding-appcompat:$flowbindingVersion")
  211. implementation("io.github.reactivecircus.flowbinding:flowbinding-recyclerview:$flowbindingVersion")
  212. implementation("io.github.reactivecircus.flowbinding:flowbinding-swiperefreshlayout:$flowbindingVersion")
  213. implementation("io.github.reactivecircus.flowbinding:flowbinding-viewpager:$flowbindingVersion")
  214. // Logging
  215. implementation("com.squareup.logcat:logcat:0.1")
  216. // Crash reports/analytics
  217. implementation("ch.acra:acra-http:5.8.4")
  218. "standardImplementation"("com.google.firebase:firebase-analytics-ktx:20.0.2")
  219. // Licenses
  220. implementation("com.mikepenz:aboutlibraries-core:${BuildPluginsVersion.ABOUTLIB_PLUGIN}")
  221. // Shizuku
  222. val shizukuVersion = "12.1.0"
  223. implementation("dev.rikka.shizuku:api:$shizukuVersion")
  224. implementation("dev.rikka.shizuku:provider:$shizukuVersion")
  225. // Tests
  226. testImplementation("junit:junit:4.13.2")
  227. testImplementation("org.assertj:assertj-core:3.16.1")
  228. testImplementation("org.mockito:mockito-core:1.10.19")
  229. val robolectricVersion = "3.1.4"
  230. testImplementation("org.robolectric:robolectric:$robolectricVersion")
  231. testImplementation("org.robolectric:shadows-play-services:$robolectricVersion")
  232. // For detecting memory leaks; see https://square.github.io/leakcanary/
  233. // debugImplementation("com.squareup.leakcanary:leakcanary-android:2.7")
  234. }
  235. tasks {
  236. // See https://kotlinlang.org/docs/reference/experimental.html#experimental-status-of-experimental-api(-markers)
  237. withType<KotlinCompile> {
  238. kotlinOptions.freeCompilerArgs += listOf(
  239. "-Xopt-in=kotlin.Experimental",
  240. "-Xopt-in=kotlin.RequiresOptIn",
  241. "-Xopt-in=kotlin.ExperimentalStdlibApi",
  242. "-Xopt-in=kotlinx.coroutines.FlowPreview",
  243. "-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
  244. "-Xopt-in=kotlinx.coroutines.InternalCoroutinesApi",
  245. "-Xopt-in=kotlinx.serialization.ExperimentalSerializationApi",
  246. "-Xopt-in=coil.annotation.ExperimentalCoilApi",
  247. )
  248. }
  249. // Duplicating Hebrew string assets due to some locale code issues on different devices
  250. val copyHebrewStrings = task("copyHebrewStrings", type = Copy::class) {
  251. from("./src/main/res/values-he")
  252. into("./src/main/res/values-iw")
  253. include("**/*")
  254. }
  255. preBuild {
  256. dependsOn(formatKotlin, copyHebrewStrings)
  257. }
  258. }
  259. buildscript {
  260. repositories {
  261. mavenCentral()
  262. }
  263. dependencies {
  264. classpath(kotlin("gradle-plugin", version = BuildPluginsVersion.KOTLIN))
  265. }
  266. }
  267. // Git is needed in your system PATH for these commands to work.
  268. // If it's not installed, you can return a random value as a workaround
  269. fun getCommitCount(): String {
  270. return runCommand("git rev-list --count HEAD")
  271. // return "1"
  272. }
  273. fun getGitSha(): String {
  274. return runCommand("git rev-parse --short HEAD")
  275. // return "1"
  276. }
  277. fun getBuildTime(): String {
  278. val df = SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'")
  279. df.timeZone = TimeZone.getTimeZone("UTC")
  280. return df.format(Date())
  281. }
  282. fun runCommand(command: String): String {
  283. val byteOut = ByteArrayOutputStream()
  284. project.exec {
  285. commandLine = command.split(" ")
  286. standardOutput = byteOut
  287. }
  288. return String(byteOut.toByteArray()).trim()
  289. }