build.gradle.kts 5.0 KB

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