build.gradle.kts 4.4 KB

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