build.gradle.kts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.archivesName
  2. plugins {
  3. id("com.android.application")
  4. id("kotlin-android")
  5. id("kotlin-parcelize")
  6. id("org.sirekanyan.version-checker")
  7. }
  8. kotlin {
  9. jvmToolchain(17)
  10. }
  11. android {
  12. namespace = "org.sirekanyan.knigopis"
  13. compileSdk = 34
  14. defaultConfig {
  15. applicationId = "org.sirekanyan.knigopis"
  16. minSdk = 21
  17. targetSdk = 34
  18. versionCode = (property("appVersionCode") as String).toInt()
  19. versionName = property("appVersionName") as String
  20. archivesName.set("$applicationId-$versionName-$versionCode")
  21. manifestPlaceholders["LOGIN_CALLBACK_SCHEME"] = "e270636c0efc6cad95130113d3bbafc3"
  22. manifestPlaceholders["LOGIN_CALLBACK_HOST"] = "532b8e7fc54c52b6df5b55181acc241a"
  23. manifestPlaceholders["LOGIN_CALLBACK_PATH"] = "$versionCode"
  24. manifestPlaceholders.forEach { (key, value) ->
  25. buildConfigField("String", key, "\"$value\"")
  26. }
  27. vectorDrawables.useSupportLibrary = true
  28. testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
  29. System.getenv("TEST_TOKEN")?.let {
  30. testInstrumentationRunnerArguments["testToken"] = it
  31. }
  32. }
  33. buildTypes {
  34. getByName("release") {
  35. isMinifyEnabled = true
  36. isShrinkResources = true
  37. proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard")
  38. }
  39. getByName("debug") {
  40. applicationIdSuffix = ".debug"
  41. }
  42. }
  43. flavorDimensions += "store"
  44. productFlavors {
  45. create("fdroid") {
  46. dimension = "store"
  47. signingConfig = signingConfigs.create("release") {
  48. storeFile = System.getenv("SIGNING_KEYSTORE_FILE")?.let(::file)
  49. storePassword = System.getenv("SIGNING_KEYSTORE_PASSWORD")
  50. keyAlias = System.getenv("SIGNING_KEY_ALIAS")
  51. keyPassword = System.getenv("SIGNING_KEY_PASSWORD")
  52. }
  53. }
  54. create("play") {
  55. dimension = "store"
  56. listOf("ACRA_URI", "ACRA_LOGIN", "ACRA_PASSWORD").forEach { key ->
  57. buildConfigField("String", key, System.getenv(key)?.let { "\"$it\"" } ?: "null")
  58. }
  59. }
  60. }
  61. compileOptions {
  62. sourceCompatibility = JavaVersion.VERSION_1_8
  63. targetCompatibility = JavaVersion.VERSION_1_8
  64. }
  65. kotlinOptions {
  66. jvmTarget = "1.8"
  67. allWarningsAsErrors = true
  68. }
  69. lint {
  70. warningsAsErrors = true
  71. }
  72. buildFeatures {
  73. buildConfig = true
  74. viewBinding = true
  75. }
  76. }
  77. dependencies {
  78. // androidx libraries
  79. implementation("androidx.appcompat:appcompat:1.6.1")
  80. implementation("androidx.constraintlayout:constraintlayout:2.1.4")
  81. implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0")
  82. implementation("androidx.browser:browser:1.6.0")
  83. // rxjava
  84. implementation("io.reactivex.rxjava2:rxjava:2.2.21")
  85. implementation("io.reactivex.rxjava2:rxkotlin:2.4.0")
  86. implementation("io.reactivex.rxjava2:rxandroid:2.1.1")
  87. // retrofit
  88. implementation("com.squareup.retrofit2:retrofit:2.9.0")
  89. implementation("com.squareup.retrofit2:adapter-rxjava2:2.9.0")
  90. implementation("com.squareup.retrofit2:converter-gson:2.9.0")
  91. // okhttp
  92. @Suppress("GradleDependency")
  93. implementation("com.squareup.okhttp3:logging-interceptor:3.14.9")
  94. // etc
  95. implementation("com.google.android.material:material:1.9.0")
  96. implementation("com.github.bumptech.glide:glide:4.16.0")
  97. // crash reporting
  98. add("playImplementation", "ch.acra:acra-http:5.11.1")
  99. // tests
  100. androidTestImplementation("androidx.test.ext:junit:1.1.5")
  101. androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
  102. androidTestImplementation("androidx.test.uiautomator:uiautomator:2.2.0")
  103. }
  104. versionCheckerOptions {
  105. "com.squareup.okhttp3:logging-interceptor" lessThan "4.0"
  106. }
  107. task("updateReadme") {
  108. dependsOn("assembleRelease")
  109. doLast {
  110. val releaseVariant = android.applicationVariants.first { it.name == "release" }
  111. val releaseFiles = releaseVariant.outputs.map { it.outputFile }
  112. val apkFile = releaseFiles.single { it.exists() && it.extension == "apk" }
  113. val defaultConfig = android.defaultConfig
  114. val properties = mapOf(
  115. "apkSize" to "%.2f".format(apkFile.length().toFloat() / 1024 / 1024),
  116. "applicationId" to defaultConfig.applicationId,
  117. "versionName" to defaultConfig.versionName,
  118. "versionCode" to defaultConfig.versionCode?.toString(),
  119. "minSdkVersion" to defaultConfig.minSdkVersion?.apiLevel?.toString(),
  120. "targetSdkVersion" to defaultConfig.targetSdkVersion?.apiLevel?.toString(),
  121. "repository" to "sirekanian/knigopis",
  122. )
  123. properties.forEach { (key, value) ->
  124. if (value.isNullOrBlank()) {
  125. logger.warn("Readme property '$key' is empty")
  126. }
  127. }
  128. rootProject.file("README.md").printWriter().use { readme ->
  129. rootProject.file("readme.md").forEachLine { inputLine ->
  130. readme.appendLine(
  131. properties.entries.fold(inputLine) { line, (key, value) ->
  132. line.replace("{{$key}}", value.orEmpty())
  133. }
  134. )
  135. }
  136. }
  137. }
  138. }