build.gradle.kts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
  26. versionCode = 68
  27. versionName = "0.12.2"
  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. // 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. }
  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. isShrinkResources = true
  51. isMinifyEnabled = true
  52. proguardFiles("proguard-android-optimize.txt", "proguard-rules.pro")
  53. }
  54. create("debugFull") { // Debug without R8
  55. initWith(getByName("debug"))
  56. isShrinkResources = false
  57. isMinifyEnabled = false
  58. }
  59. named("release") {
  60. isShrinkResources = true
  61. isMinifyEnabled = true
  62. proguardFiles("proguard-android-optimize.txt", "proguard-rules.pro")
  63. }
  64. }
  65. sourceSets {
  66. getByName("debugFull").res.srcDirs("src/debug/res")
  67. }
  68. flavorDimensions.add("default")
  69. productFlavors {
  70. create("standard") {
  71. buildConfigField("boolean", "INCLUDE_UPDATER", "true")
  72. dimension = "default"
  73. }
  74. create("dev") {
  75. resourceConfigurations.addAll(listOf("en", "xxhdpi"))
  76. dimension = "default"
  77. }
  78. }
  79. packagingOptions {
  80. resources.excludes.addAll(listOf(
  81. "META-INF/DEPENDENCIES",
  82. "LICENSE.txt",
  83. "META-INF/LICENSE",
  84. "META-INF/LICENSE.txt",
  85. "META-INF/NOTICE",
  86. "META-INF/*.kotlin_module",
  87. ))
  88. }
  89. dependenciesInfo {
  90. includeInApk = false
  91. }
  92. buildFeatures {
  93. viewBinding = true
  94. }
  95. lint {
  96. disable("MissingTranslation", "ExtraTranslation")
  97. isAbortOnError = false
  98. isCheckReleaseBuilds = false
  99. }
  100. compileOptions {
  101. sourceCompatibility = JavaVersion.VERSION_1_8
  102. targetCompatibility = JavaVersion.VERSION_1_8
  103. }
  104. kotlinOptions {
  105. jvmTarget = JavaVersion.VERSION_1_8.toString()
  106. }
  107. }
  108. dependencies {
  109. implementation(kotlin("reflect", version = BuildPluginsVersion.KOTLIN))
  110. val coroutinesVersion = "1.5.2"
  111. implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
  112. implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion")
  113. // Source models and interfaces from Tachiyomi 1.x
  114. implementation("org.tachiyomi:source-api:1.1")
  115. // AndroidX libraries
  116. implementation("androidx.annotation:annotation:1.3.0-alpha01")
  117. implementation("androidx.appcompat:appcompat:1.4.0-alpha03")
  118. implementation("androidx.biometric:biometric-ktx:1.2.0-alpha03")
  119. implementation("androidx.browser:browser:1.4.0-alpha01")
  120. implementation("androidx.constraintlayout:constraintlayout:2.1.0")
  121. implementation("androidx.coordinatorlayout:coordinatorlayout:1.1.0")
  122. implementation("androidx.core:core-ktx:1.7.0-beta01")
  123. implementation("androidx.core:core-splashscreen:1.0.0-alpha01")
  124. implementation("androidx.recyclerview:recyclerview:1.3.0-alpha01")
  125. implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.2.0-alpha01")
  126. implementation("androidx.viewpager:viewpager:1.1.0-alpha01")
  127. val lifecycleVersion = "2.4.0-beta01"
  128. implementation("androidx.lifecycle:lifecycle-common:$lifecycleVersion")
  129. implementation("androidx.lifecycle:lifecycle-process:$lifecycleVersion")
  130. implementation("androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleVersion")
  131. // Job scheduling
  132. implementation("androidx.work:work-runtime-ktx:2.6.0")
  133. // RX
  134. implementation("io.reactivex:rxandroid:1.2.1")
  135. implementation("io.reactivex:rxjava:1.3.8")
  136. implementation("com.jakewharton.rxrelay:rxrelay:1.2.0")
  137. implementation("ru.beryukhov:flowreactivenetwork:1.0.4")
  138. // Network client
  139. val okhttpVersion = "4.9.1"
  140. implementation("com.squareup.okhttp3:okhttp:$okhttpVersion")
  141. implementation("com.squareup.okhttp3:logging-interceptor:$okhttpVersion")
  142. implementation("com.squareup.okhttp3:okhttp-dnsoverhttps:$okhttpVersion")
  143. implementation("com.squareup.okio:okio:2.10.0")
  144. // TLS 1.3 support for Android < 10
  145. implementation("org.conscrypt:conscrypt-android:2.5.2")
  146. // Data serialization (JSON, protobuf)
  147. val kotlinSerializationVersion = "1.3.0-RC"
  148. implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinSerializationVersion")
  149. implementation("org.jetbrains.kotlinx:kotlinx-serialization-protobuf:$kotlinSerializationVersion")
  150. // TODO: remove these once they're no longer used in any extensions
  151. implementation("com.google.code.gson:gson:2.8.7")
  152. implementation("com.github.salomonbrys.kotson:kotson:2.5.0")
  153. // JavaScript engine
  154. implementation("com.squareup.duktape:duktape-android:1.4.0")
  155. // HTML parser
  156. implementation("org.jsoup:jsoup:1.14.2")
  157. // Disk
  158. implementation("com.jakewharton:disklrucache:2.0.2")
  159. implementation("com.github.tachiyomiorg:unifile:17bec43")
  160. implementation("com.github.junrar:junrar:7.4.0")
  161. // Database
  162. implementation("androidx.sqlite:sqlite-ktx:2.1.0")
  163. implementation("com.github.inorichi.storio:storio-common:8be19de@aar")
  164. implementation("com.github.inorichi.storio:storio-sqlite:8be19de@aar")
  165. implementation("com.github.requery:sqlite-android:3.36.0")
  166. // Preferences
  167. implementation("androidx.preference:preference-ktx:1.1.1")
  168. implementation("com.github.tfcporciuncula.flow-preferences:flow-preferences:1.4.0")
  169. // Model View Presenter
  170. val nucleusVersion = "3.0.0"
  171. implementation("info.android15.nucleus:nucleus:$nucleusVersion")
  172. implementation("info.android15.nucleus:nucleus-support-v7:$nucleusVersion")
  173. // Dependency injection
  174. implementation("com.github.inorichi.injekt:injekt-core:65b0440")
  175. // Image loading
  176. val coilVersion = "1.3.2"
  177. implementation("io.coil-kt:coil:$coilVersion")
  178. implementation("io.coil-kt:coil-gif:$coilVersion")
  179. implementation("com.github.tachiyomiorg:subsampling-scale-image-view:846abe0") {
  180. exclude(module = "image-decoder")
  181. }
  182. implementation("com.github.tachiyomiorg:image-decoder:7481a4a")
  183. // Sort
  184. implementation("com.github.gpanther:java-nat-sort:natural-comparator-1.1")
  185. // UI libraries
  186. implementation("com.google.android.material:material:1.5.0-alpha03")
  187. implementation("com.github.dmytrodanylyk.android-process-button:library:1.0.4")
  188. implementation("eu.davidea:flexible-adapter:5.1.0")
  189. implementation("eu.davidea:flexible-adapter-ui:1.0.0")
  190. implementation("com.nightlynexus.viewstatepageradapter:viewstatepageradapter:1.1.0")
  191. implementation("com.github.chrisbanes:PhotoView:2.3.0")
  192. implementation("com.github.tachiyomiorg:DirectionalViewPager:1.0.0") {
  193. exclude(group = "androidx.viewpager", module = "viewpager")
  194. }
  195. implementation("dev.chrisbanes.insetter:insetter:0.6.0")
  196. // Conductor
  197. val conductorVersion = "3.0.0"
  198. implementation("com.bluelinelabs:conductor:$conductorVersion")
  199. implementation("com.bluelinelabs:conductor-viewpager:$conductorVersion")
  200. implementation("com.github.tachiyomiorg:conductor-support-preference:$conductorVersion")
  201. // FlowBinding
  202. val flowbindingVersion = "1.2.0"
  203. implementation("io.github.reactivecircus.flowbinding:flowbinding-android:$flowbindingVersion")
  204. implementation("io.github.reactivecircus.flowbinding:flowbinding-appcompat:$flowbindingVersion")
  205. implementation("io.github.reactivecircus.flowbinding:flowbinding-recyclerview:$flowbindingVersion")
  206. implementation("io.github.reactivecircus.flowbinding:flowbinding-swiperefreshlayout:$flowbindingVersion")
  207. implementation("io.github.reactivecircus.flowbinding:flowbinding-viewpager:$flowbindingVersion")
  208. // Logging
  209. implementation("com.jakewharton.timber:timber:5.0.1")
  210. // Crash reports/analytics
  211. implementation("ch.acra:acra-http:5.8.1")
  212. "standardImplementation"("com.google.firebase:firebase-analytics:19.0.1")
  213. // Licenses
  214. implementation("com.mikepenz:aboutlibraries-core:${BuildPluginsVersion.ABOUTLIB_PLUGIN}")
  215. // Tests
  216. testImplementation("junit:junit:4.13.2")
  217. testImplementation("org.assertj:assertj-core:3.16.1")
  218. testImplementation("org.mockito:mockito-core:1.10.19")
  219. val robolectricVersion = "3.1.4"
  220. testImplementation("org.robolectric:robolectric:$robolectricVersion")
  221. testImplementation("org.robolectric:shadows-play-services:$robolectricVersion")
  222. // For detecting memory leaks; see https://square.github.io/leakcanary/
  223. // debugImplementation("com.squareup.leakcanary:leakcanary-android:2.7")
  224. }
  225. tasks {
  226. // See https://kotlinlang.org/docs/reference/experimental.html#experimental-status-of-experimental-api(-markers)
  227. withType<KotlinCompile> {
  228. kotlinOptions.freeCompilerArgs += listOf(
  229. "-Xopt-in=kotlin.Experimental",
  230. "-Xopt-in=kotlin.RequiresOptIn",
  231. "-Xuse-experimental=kotlin.ExperimentalStdlibApi",
  232. "-Xuse-experimental=kotlinx.coroutines.FlowPreview",
  233. "-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi",
  234. "-Xuse-experimental=kotlinx.coroutines.InternalCoroutinesApi",
  235. "-Xuse-experimental=kotlinx.serialization.ExperimentalSerializationApi",
  236. "-Xuse-experimental=coil.annotation.ExperimentalCoilApi",
  237. )
  238. }
  239. // Duplicating Hebrew string assets due to some locale code issues on different devices
  240. val copyHebrewStrings = task("copyHebrewStrings", type = Copy::class) {
  241. from("./src/main/res/values-he")
  242. into("./src/main/res/values-iw")
  243. include("**/*")
  244. }
  245. preBuild {
  246. dependsOn(formatKotlin, copyHebrewStrings)
  247. }
  248. }
  249. buildscript {
  250. repositories {
  251. mavenCentral()
  252. }
  253. dependencies {
  254. classpath(kotlin("gradle-plugin", version = BuildPluginsVersion.KOTLIN))
  255. }
  256. }
  257. // Git is needed in your system PATH for these commands to work.
  258. // If it's not installed, you can return a random value as a workaround
  259. fun getCommitCount(): String {
  260. return runCommand("git rev-list --count HEAD")
  261. // return "1"
  262. }
  263. fun getGitSha(): String {
  264. return runCommand("git rev-parse --short HEAD")
  265. // return "1"
  266. }
  267. fun getBuildTime(): String {
  268. val df = SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'")
  269. df.timeZone = TimeZone.getTimeZone("UTC")
  270. return df.format(Date())
  271. }
  272. fun runCommand(command: String): String {
  273. val byteOut = ByteArrayOutputStream()
  274. project.exec {
  275. commandLine = command.split(" ")
  276. standardOutput = byteOut
  277. }
  278. return String(byteOut.toByteArray()).trim()
  279. }