build.gradle 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. apply plugin: 'com.android.application'
  2. android {
  3. /*******************************************************
  4. * The following variables:
  5. * - androidBuildToolsVersion,
  6. * - androidCompileSdkVersion
  7. * - qt5AndroidDir - holds the path to qt android files
  8. * needed to build any Qt application
  9. * on Android.
  10. *
  11. * are defined in gradle.properties file. This file is
  12. * updated by QtCreator and androiddeployqt tools.
  13. * Changing them manually might break the compilation!
  14. *******************************************************/
  15. ndkVersion '25.2.9519653'
  16. // Extract native libraries from the APK
  17. packagingOptions.jniLibs.useLegacyPackaging true
  18. defaultConfig {
  19. applicationId "is.xyz.vcmi"
  20. compileSdk = androidCompileSdkVersion.takeAfter("-") as Integer // has "android-" prepended
  21. minSdk = qtMinSdkVersion as Integer
  22. targetSdk = qtTargetSdkVersion as Integer // ANDROID_TARGET_SDK_VERSION in the CMake project
  23. versionCode 1530
  24. versionName "1.5.3"
  25. setProperty("archivesBaseName", "vcmi")
  26. }
  27. sourceSets {
  28. main {
  29. // Qt requires these to be in the android project root
  30. manifest.srcFile '../AndroidManifest.xml'
  31. jniLibs.srcDirs = ['../libs']
  32. java.srcDirs = [qt5AndroidDir + '/src', 'src', 'java']
  33. aidl.srcDirs = [qt5AndroidDir + '/src', 'src', 'aidl']
  34. res.srcDirs = [qt5AndroidDir + '/res', 'src/main/res', '../res']
  35. }
  36. }
  37. signingConfigs {
  38. releaseSigning
  39. dailySigning
  40. LoadSigningConfig("releaseSigning")
  41. LoadSigningConfig("dailySigning")
  42. }
  43. buildTypes {
  44. debug {
  45. debuggable true
  46. applicationIdSuffix '.debug'
  47. manifestPlaceholders = [
  48. applicationLabel: 'VCMI debug',
  49. ]
  50. ndk {
  51. debugSymbolLevel 'full'
  52. }
  53. }
  54. release {
  55. minifyEnabled false
  56. zipAlignEnabled true
  57. applicationIdSuffix = project.findProperty('applicationIdSuffix')
  58. signingConfig = signingConfigs[project.findProperty('signingConfig') ?: 'releaseSigning']
  59. proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
  60. manifestPlaceholders = [
  61. applicationLabel: project.findProperty('applicationLabel') ?: 'VCMI',
  62. ]
  63. ndk {
  64. debugSymbolLevel 'full'
  65. }
  66. }
  67. }
  68. tasks.withType(JavaCompile) {
  69. options.compilerArgs += ["-Xlint:deprecation"]
  70. }
  71. compileOptions {
  72. sourceCompatibility JavaVersion.VERSION_1_8
  73. targetCompatibility JavaVersion.VERSION_1_8
  74. }
  75. // Do not compress Qt binary resources file
  76. aaptOptions {
  77. noCompress 'rcc'
  78. }
  79. }
  80. def CommandOutput(final cmd, final arguments, final cwd) {
  81. try {
  82. new ByteArrayOutputStream().withStream { final os ->
  83. exec {
  84. executable cmd
  85. args arguments
  86. workingDir cwd
  87. standardOutput os
  88. }
  89. return os.toString().trim()
  90. }
  91. }
  92. catch (final Exception ex) {
  93. print("Broken: " + cmd + " " + arguments + " in " + cwd + " :: " + ex.toString())
  94. return ""
  95. }
  96. }
  97. def SigningPropertiesPath(final basePath, final signingConfigKey) {
  98. return file("${basePath}/${signingConfigKey}.properties")
  99. }
  100. def SigningKeystorePath(final basePath, final keystoreFileName) {
  101. return file("${basePath}/${keystoreFileName}")
  102. }
  103. def LoadSigningConfig(final signingConfigKey) {
  104. final def props = new Properties()
  105. final def propFile = SigningPropertiesPath(signingRoot, signingConfigKey)
  106. def signingConfig = android.signingConfigs.getAt(signingConfigKey)
  107. if (propFile.canRead()) {
  108. props.load(new FileInputStream(propFile))
  109. if (props != null
  110. && props.containsKey('STORE_FILE')
  111. && props.containsKey('KEY_ALIAS')) {
  112. signingConfig.storeFile = SigningKeystorePath(signingRoot, props['STORE_FILE'])
  113. signingConfig.storePassword = props['STORE_PASSWORD']
  114. signingConfig.keyAlias = props['KEY_ALIAS']
  115. if(props.containsKey('STORE_PASSWORD'))
  116. signingConfig.storePassword = props['STORE_PASSWORD']
  117. else
  118. signingConfig.storePassword = System.getenv("ANDROID_STORE_PASSWORD")
  119. if(props.containsKey('KEY_PASSWORD'))
  120. signingConfig.keyPassword = props['KEY_PASSWORD']
  121. else
  122. signingConfig.keyPassword = System.getenv("ANDROID_KEY_PASSWORD")
  123. } else {
  124. println("Some props from signing file are missing")
  125. android.signingConfigs.putAt(signingConfigKey, null)
  126. }
  127. } else {
  128. println("file with signing properties is missing")
  129. android.signingConfigs.putAt(signingConfigKey, null)
  130. }
  131. }
  132. dependencies {
  133. implementation fileTree(dir: '../libs', include: ['*.jar', '*.aar'])
  134. implementation 'androidx.annotation:annotation:1.7.1'
  135. implementation 'androidx.documentfile:documentfile:1.0.1'
  136. }