build.gradle.kts 5.4 KB

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