build.gradle 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. plugins {
  2. id 'com.android.application'
  3. }
  4. android {
  5. compileSdk 31
  6. ndkVersion '25.2.9519653'
  7. defaultConfig {
  8. applicationId "is.xyz.vcmi"
  9. minSdk 19
  10. targetSdk 31
  11. versionCode 1103
  12. versionName "1.1"
  13. setProperty("archivesBaseName", "vcmi")
  14. }
  15. signingConfigs {
  16. releaseSigning
  17. LoadSigningConfig(PROJECT_PATH_BASE)
  18. }
  19. buildTypes {
  20. debug {
  21. debuggable true
  22. ndk {
  23. debugSymbolLevel 'full'
  24. }
  25. }
  26. release {
  27. minifyEnabled false
  28. zipAlignEnabled true
  29. signingConfig signingConfigs.releaseSigning
  30. proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
  31. ndk {
  32. debugSymbolLevel 'symbol_table'
  33. }
  34. }
  35. }
  36. applicationVariants.all { variant -> RenameOutput(project.archivesBaseName, variant) }
  37. tasks.withType(JavaCompile) {
  38. options.compilerArgs += ["-Xlint:deprecation"]
  39. }
  40. compileOptions {
  41. sourceCompatibility JavaVersion.VERSION_1_8
  42. targetCompatibility JavaVersion.VERSION_1_8
  43. }
  44. buildFeatures {
  45. viewBinding true
  46. dataBinding true
  47. }
  48. }
  49. def RenameOutput(final baseName, final variant) {
  50. final def buildTaskId = System.getenv("GITHUB_RUN_ID")
  51. ResolveGitInfo()
  52. def name = baseName + "-" + ext.gitInfoLauncher + "-" + ext.gitInfoVcmi
  53. if (buildTaskId != null && !buildTaskId.isEmpty()) {
  54. name = buildTaskId + "-" + name
  55. }
  56. if (!variant.buildType.name != "release") {
  57. name += "-" + variant.buildType.name
  58. }
  59. variant.outputs.each { output ->
  60. def oldPath = output.outputFile.getAbsolutePath()
  61. output.outputFileName = name + oldPath.substring(oldPath.lastIndexOf("."))
  62. }
  63. }
  64. def CommandOutput(final cmd, final arguments, final cwd) {
  65. try {
  66. new ByteArrayOutputStream().withStream { final os ->
  67. exec {
  68. executable cmd
  69. args arguments
  70. workingDir cwd
  71. standardOutput os
  72. }
  73. return os.toString().trim()
  74. }
  75. }
  76. catch (final Exception ex) {
  77. print("Broken: " + cmd + " " + arguments + " in " + cwd + " :: " + ex.toString())
  78. return ""
  79. }
  80. }
  81. def ResolveGitInfo() {
  82. if (ext.gitInfoLauncher != "none" && ext.gitInfoVcmi != "none") {
  83. return
  84. }
  85. ext.gitInfoLauncher = CommandOutput("git", ["describe", "--match=", "--always", "--abbrev=7"], PROJECT_PATH_BASE)
  86. ext.gitInfoVcmi =
  87. CommandOutput("git", ["log", "-1", "--pretty=%D", "--decorate-refs=refs/remotes/origin/*"], PROJECT_PATH_BASE + "/ext/vcmi").replace("origin/", "").replace(", HEAD", "").replaceAll("[^a-zA-Z0-9\\-_]", "_") +
  88. "-" +
  89. CommandOutput("git", ["describe", "--match=", "--always", "--abbrev=7"], PROJECT_PATH_BASE + "/ext/vcmi")
  90. }
  91. def SigningPropertiesPath(final basePath) {
  92. return file(basePath + "/.github/CI/signing.properties")
  93. }
  94. def SigningKeystorePath(final basePath, final keystoreFileName) {
  95. return file(basePath + "/.github/CI/" + keystoreFileName)
  96. }
  97. def LoadSigningConfig(final basePath) {
  98. final def props = new Properties()
  99. final def propFile = SigningPropertiesPath(basePath)
  100. if (propFile.canRead()) {
  101. props.load(new FileInputStream(propFile))
  102. if (props != null
  103. && props.containsKey('STORE_FILE')
  104. && props.containsKey('STORE_PASSWORD')
  105. && props.containsKey('KEY_ALIAS')
  106. && props.containsKey('KEY_PASSWORD')) {
  107. android.signingConfigs.releaseSigning.storeFile = SigningKeystorePath(basePath, props['STORE_FILE'])
  108. android.signingConfigs.releaseSigning.storePassword = props['STORE_PASSWORD']
  109. android.signingConfigs.releaseSigning.keyAlias = props['KEY_ALIAS']
  110. android.signingConfigs.releaseSigning.keyPassword = props['KEY_PASSWORD']
  111. } else {
  112. println("Some props from signing file are missing")
  113. android.buildTypes.release.signingConfig = null
  114. }
  115. } else {
  116. println("file with signing properties is missing")
  117. android.buildTypes.release.signingConfig = null
  118. }
  119. }
  120. dependencies {
  121. implementation 'androidx.appcompat:appcompat:1.2.0'
  122. implementation 'com.google.android.material:material:1.3.0'
  123. implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
  124. }