build.gradle.kts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. if (findProperty("signingConfig") == "release") {
  39. signingConfig = signingConfigs.create("release") {
  40. storeFile(file(System.getenv("SIGNING_KEYSTORE_FILE")))
  41. storePassword(System.getenv("SIGNING_KEYSTORE_PASSWORD"))
  42. keyAlias(System.getenv("SIGNING_KEY_ALIAS"))
  43. keyPassword(System.getenv("SIGNING_KEY_PASSWORD"))
  44. }
  45. }
  46. }
  47. getByName("debug") {
  48. applicationIdSuffix = ".debug"
  49. }
  50. }
  51. compileOptions {
  52. sourceCompatibility = JavaVersion.VERSION_1_8
  53. targetCompatibility = JavaVersion.VERSION_1_8
  54. }
  55. kotlinOptions {
  56. jvmTarget = "1.8"
  57. allWarningsAsErrors = true
  58. }
  59. lint {
  60. warningsAsErrors = true
  61. }
  62. buildFeatures {
  63. buildConfig = true
  64. viewBinding = true
  65. }
  66. }
  67. dependencies {
  68. // androidx libraries
  69. implementation("androidx.appcompat:appcompat:1.6.1")
  70. implementation("androidx.constraintlayout:constraintlayout:2.1.4")
  71. implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0")
  72. implementation("androidx.browser:browser:1.6.0")
  73. // rxjava
  74. implementation("io.reactivex.rxjava2:rxjava:2.2.21")
  75. implementation("io.reactivex.rxjava2:rxkotlin:2.4.0")
  76. implementation("io.reactivex.rxjava2:rxandroid:2.1.1")
  77. // retrofit
  78. implementation("com.squareup.retrofit2:retrofit:2.9.0")
  79. implementation("com.squareup.retrofit2:adapter-rxjava2:2.9.0")
  80. implementation("com.squareup.retrofit2:converter-gson:2.9.0")
  81. // okhttp
  82. @Suppress("GradleDependency")
  83. implementation("com.squareup.okhttp3:logging-interceptor:3.14.9")
  84. // etc
  85. implementation("com.google.android.material:material:1.9.0")
  86. implementation("com.github.bumptech.glide:glide:4.16.0")
  87. // todo: crash reporting
  88. // implementation("ch.acra:acra-http:5.11.1")
  89. // tests
  90. androidTestImplementation("androidx.test.ext:junit:1.1.5")
  91. androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
  92. androidTestImplementation("androidx.test.uiautomator:uiautomator:2.2.0")
  93. }
  94. versionCheckerOptions {
  95. "com.squareup.okhttp3:logging-interceptor" lessThan "4.0"
  96. }
  97. task("updateReadme") {
  98. dependsOn("assembleRelease")
  99. doLast {
  100. val releaseVariant = android.applicationVariants.first { it.name == "release" }
  101. val releaseFiles = releaseVariant.outputs.map { it.outputFile }
  102. val apkFile = releaseFiles.single { it.exists() && it.extension == "apk" }
  103. val defaultConfig = android.defaultConfig
  104. val properties = mapOf(
  105. "apkSize" to "%.2f".format(apkFile.length().toFloat() / 1024 / 1024),
  106. "applicationId" to defaultConfig.applicationId,
  107. "versionName" to defaultConfig.versionName,
  108. "versionCode" to defaultConfig.versionCode?.toString(),
  109. "minSdkVersion" to defaultConfig.minSdkVersion?.apiLevel?.toString(),
  110. "targetSdkVersion" to defaultConfig.targetSdkVersion?.apiLevel?.toString(),
  111. "repository" to "sirekanian/knigopis",
  112. )
  113. properties.forEach { (key, value) ->
  114. if (value.isNullOrBlank()) {
  115. logger.warn("Readme property '$key' is empty")
  116. }
  117. }
  118. rootProject.file("README.md").printWriter().use { readme ->
  119. rootProject.file("readme.md").forEachLine { inputLine ->
  120. readme.appendLine(
  121. properties.entries.fold(inputLine) { line, (key, value) ->
  122. line.replace("{{$key}}", value.orEmpty())
  123. }
  124. )
  125. }
  126. }
  127. }
  128. }