2
0

androidApp.gradle.kts 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. plugins {
  2. alias(libs.plugins.android.application)
  3. alias(libs.plugins.compose)
  4. alias(libs.plugins.compose.compiler)
  5. }
  6. android {
  7. namespace = "org.mjdev.desktop"
  8. compileSdk = libs.versions.android.compile.sdk.get().toInt()
  9. // shared resources packaged into the APK (lost when composeApp was split):
  10. // - assets <- commonMain/resources (icon fonts, translations, widgets, …)
  11. // - resources <- commonMain/composeResources
  12. sourceSets["main"].assets.srcDirs(rootDir.resolve("shared/src/commonMain/resources"))
  13. sourceSets["main"].resources.srcDirs(rootDir.resolve("shared/src/commonMain/composeResources"))
  14. defaultConfig {
  15. applicationId = "org.mjdev.desktop"
  16. minSdk = libs.versions.android.min.sdk.get().toInt()
  17. targetSdk = libs.versions.android.target.sdk.get().toInt()
  18. versionCode = libs.versions.app.pkg.version.get().replace(".", "").toInt()
  19. versionName = libs.versions.app.pkg.version.get()
  20. resValue("string", "app_name", libs.versions.app.name.get())
  21. }
  22. packaging {
  23. resources {
  24. excludes += "META-INF/{AL2.0,LGPL2.1}"
  25. excludes += "META-INF/INDEX.LIST"
  26. excludes += "META-INF/DEPENDENCIES"
  27. excludes += "META-INF/io.netty.versions.properties"
  28. pickFirsts += "META-INF/native-image/**"
  29. }
  30. }
  31. // Release signing. Keystore + credentials come from env vars (CI secrets) or Gradle
  32. // properties (local ~/.gradle/gradle.properties) — never hardcoded. When no release
  33. // keystore is configured we fall back to the debug key so the release APK is still
  34. // *signed* and installable (an unsigned APK is rejected by Android on install).
  35. val releaseStoreFile = (providers.environmentVariable("ANDROID_KEYSTORE_FILE").orNull
  36. ?: providers.gradleProperty("android.keystore.file").orNull)?.let(::file)
  37. val releaseStorePassword = providers.environmentVariable("ANDROID_KEYSTORE_PASSWORD").orNull
  38. ?: providers.gradleProperty("android.keystore.password").orNull
  39. val releaseKeyAlias = providers.environmentVariable("ANDROID_KEY_ALIAS").orNull
  40. ?: providers.gradleProperty("android.key.alias").orNull
  41. val releaseKeyPassword = providers.environmentVariable("ANDROID_KEY_PASSWORD").orNull
  42. ?: providers.gradleProperty("android.key.password").orNull
  43. val hasReleaseKeystore = releaseStoreFile?.exists() == true &&
  44. !releaseStorePassword.isNullOrBlank() &&
  45. !releaseKeyAlias.isNullOrBlank() &&
  46. !releaseKeyPassword.isNullOrBlank()
  47. signingConfigs {
  48. if (hasReleaseKeystore) {
  49. create("release") {
  50. storeFile = releaseStoreFile
  51. storePassword = releaseStorePassword
  52. keyAlias = releaseKeyAlias
  53. keyPassword = releaseKeyPassword
  54. }
  55. }
  56. }
  57. buildTypes {
  58. getByName("release") {
  59. isDebuggable = true
  60. isJniDebuggable = true
  61. isMinifyEnabled = false
  62. isShrinkResources = false
  63. isPseudoLocalesEnabled = true
  64. // real keystore when provided, otherwise debug key (still a signed, installable APK)
  65. signingConfig = signingConfigs.getByName(if (hasReleaseKeystore) "release" else "debug")
  66. }
  67. }
  68. compileOptions {
  69. sourceCompatibility = JavaVersion.VERSION_17
  70. targetCompatibility = JavaVersion.VERSION_17
  71. }
  72. buildFeatures {
  73. compose = true
  74. buildConfig = true
  75. }
  76. }
  77. dependencies {
  78. implementation(projects.shared)
  79. implementation(compose.runtime)
  80. implementation(compose.foundation)
  81. implementation(compose.material3)
  82. implementation(compose.materialIconsExtended)
  83. implementation(compose.ui)
  84. implementation(compose.components.resources)
  85. implementation(compose.components.uiToolingPreview)
  86. implementation(libs.androidx.activity.compose)
  87. implementation(libs.androidx.core.ktx)
  88. implementation(libs.androidx.lifecycle.viewmodel)
  89. implementation(libs.androidx.lifecycle.runtime.compose)
  90. implementation(libs.androidx.core.splashscreen)
  91. implementation(libs.accompanist.permissions)
  92. implementation(libs.coil.compose)
  93. implementation(libs.napier)
  94. debugImplementation(libs.androidx.ui.tooling)
  95. }