build.gradle.kts 4.5 KB

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