build.gradle 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 1620
  24. versionName "1.6.2"
  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. applicationVariant: 'debug',
  50. ]
  51. ndk {
  52. debugSymbolLevel 'full'
  53. }
  54. }
  55. release {
  56. minifyEnabled false
  57. zipAlignEnabled true
  58. applicationIdSuffix = project.findProperty('applicationIdSuffix')
  59. signingConfig = signingConfigs[project.findProperty('signingConfig') ?: 'releaseSigning']
  60. proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
  61. manifestPlaceholders = [
  62. applicationLabel: project.findProperty('applicationLabel') ?: 'VCMI',
  63. applicationVariant: project.findProperty('applicationVariant') ?: '',
  64. ]
  65. ndk {
  66. debugSymbolLevel 'full'
  67. }
  68. }
  69. }
  70. tasks.withType(JavaCompile) {
  71. options.compilerArgs += ["-Xlint:deprecation"]
  72. }
  73. compileOptions {
  74. sourceCompatibility JavaVersion.VERSION_1_8
  75. targetCompatibility JavaVersion.VERSION_1_8
  76. }
  77. // Do not compress Qt binary resources file
  78. aaptOptions {
  79. noCompress 'rcc'
  80. }
  81. }
  82. def CommandOutput(final cmd, final arguments, final cwd) {
  83. try {
  84. new ByteArrayOutputStream().withStream { final os ->
  85. exec {
  86. executable cmd
  87. args arguments
  88. workingDir cwd
  89. standardOutput os
  90. }
  91. return os.toString().trim()
  92. }
  93. }
  94. catch (final Exception ex) {
  95. print("Broken: " + cmd + " " + arguments + " in " + cwd + " :: " + ex.toString())
  96. return ""
  97. }
  98. }
  99. def SigningPropertiesPath(final basePath, final signingConfigKey) {
  100. return file("${basePath}/${signingConfigKey}.properties")
  101. }
  102. def SigningKeystorePath(final basePath, final keystoreFileName) {
  103. return file("${basePath}/${keystoreFileName}")
  104. }
  105. def LoadSigningConfig(final signingConfigKey) {
  106. final def props = new Properties()
  107. final def propFile = SigningPropertiesPath(signingRoot, signingConfigKey)
  108. def signingConfig = android.signingConfigs.getAt(signingConfigKey)
  109. if (propFile.canRead()) {
  110. props.load(new FileInputStream(propFile))
  111. if (props != null
  112. && props.containsKey('STORE_FILE')
  113. && props.containsKey('KEY_ALIAS')) {
  114. signingConfig.storeFile = SigningKeystorePath(signingRoot, props['STORE_FILE'])
  115. signingConfig.storePassword = props['STORE_PASSWORD']
  116. signingConfig.keyAlias = props['KEY_ALIAS']
  117. if(props.containsKey('STORE_PASSWORD'))
  118. signingConfig.storePassword = props['STORE_PASSWORD']
  119. else
  120. signingConfig.storePassword = System.getenv("ANDROID_STORE_PASSWORD")
  121. if(props.containsKey('KEY_PASSWORD'))
  122. signingConfig.keyPassword = props['KEY_PASSWORD']
  123. else
  124. signingConfig.keyPassword = System.getenv("ANDROID_KEY_PASSWORD")
  125. } else {
  126. println("Some props from signing file are missing")
  127. android.signingConfigs.putAt(signingConfigKey, null)
  128. }
  129. } else {
  130. println("file with signing properties is missing")
  131. android.signingConfigs.putAt(signingConfigKey, null)
  132. }
  133. }
  134. dependencies {
  135. implementation fileTree(dir: '../libs', include: ['*.jar', '*.aar'])
  136. implementation 'androidx.annotation:annotation:1.7.1'
  137. implementation 'androidx.documentfile:documentfile:1.0.1'
  138. }