build.gradle 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. /*
  2. Licensed to the Apache Software Foundation (ASF) under one
  3. or more contributor license agreements. See the NOTICE file
  4. distributed with this work for additional information
  5. regarding copyright ownership. The ASF licenses this file
  6. to you under the Apache License, Version 2.0 (the
  7. "License"); you may not use this file except in compliance
  8. with the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing,
  11. software distributed under the License is distributed on an
  12. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  13. KIND, either express or implied. See the License for the
  14. specific language governing permissions and limitations
  15. under the License.
  16. */
  17. apply plugin: 'com.android.application'
  18. buildscript {
  19. repositories {
  20. mavenCentral()
  21. google()
  22. jcenter()
  23. }
  24. dependencies {
  25. classpath 'com.android.tools.build:gradle:3.3.0'
  26. }
  27. }
  28. // Allow plugins to declare Maven dependencies via build-extras.gradle.
  29. allprojects {
  30. repositories {
  31. mavenCentral()
  32. jcenter()
  33. }
  34. }
  35. task wrapper(type: Wrapper) {
  36. gradleVersion = '4.10.3'
  37. }
  38. // Configuration properties. Set these via environment variables, build-extras.gradle, or gradle.properties.
  39. // Refer to: http://www.gradle.org/docs/current/userguide/tutorial_this_and_that.html
  40. ext {
  41. apply from: '../CordovaLib/cordova.gradle'
  42. // The value for android.compileSdkVersion.
  43. if (!project.hasProperty('cdvCompileSdkVersion')) {
  44. cdvCompileSdkVersion = null;
  45. }
  46. // The value for android.buildToolsVersion.
  47. if (!project.hasProperty('cdvBuildToolsVersion')) {
  48. cdvBuildToolsVersion = null;
  49. }
  50. // Sets the versionCode to the given value.
  51. if (!project.hasProperty('cdvVersionCode')) {
  52. cdvVersionCode = null
  53. }
  54. // Sets the minSdkVersion to the given value.
  55. if (!project.hasProperty('cdvMinSdkVersion')) {
  56. cdvMinSdkVersion = null
  57. }
  58. // Sets the maxSdkVersion to the given value.
  59. if (!project.hasProperty('cdvMaxSdkVersion')) {
  60. cdvMaxSdkVersion = null
  61. }
  62. // The value for android.targetSdkVersion.
  63. if (!project.hasProperty('cdvTargetSdkVersion')) {
  64. cdvTargetSdkVersion = null;
  65. }
  66. // Whether to build architecture-specific APKs.
  67. if (!project.hasProperty('cdvBuildMultipleApks')) {
  68. cdvBuildMultipleApks = null
  69. }
  70. // Whether to append a 0 "abi digit" to versionCode when only a single APK is build
  71. if (!project.hasProperty('cdvVersionCodeForceAbiDigit')) {
  72. cdvVersionCodeForceAbiDigit = null
  73. }
  74. // .properties files to use for release signing.
  75. if (!project.hasProperty('cdvReleaseSigningPropertiesFile')) {
  76. cdvReleaseSigningPropertiesFile = null
  77. }
  78. // .properties files to use for debug signing.
  79. if (!project.hasProperty('cdvDebugSigningPropertiesFile')) {
  80. cdvDebugSigningPropertiesFile = null
  81. }
  82. // Set by build.js script.
  83. if (!project.hasProperty('cdvBuildArch')) {
  84. cdvBuildArch = null
  85. }
  86. // Plugin gradle extensions can append to this to have code run at the end.
  87. cdvPluginPostBuildExtras = []
  88. }
  89. // PLUGIN GRADLE EXTENSIONS START
  90. apply from: "../com-sarriaroman-photoviewer/sgZongLi-photoviewer.gradle"
  91. apply from: "../cordova-plugin-badge/sgZongLi-badge.gradle"
  92. apply from: "../cordova-plugin-local-notification/sgZongLi-localnotification.gradle"
  93. apply from: "../phonegap-plugin-barcodescanner/sgZongLi-barcodescanner.gradle"
  94. // PLUGIN GRADLE EXTENSIONS END
  95. def hasBuildExtras1 = file('build-extras.gradle').exists()
  96. if (hasBuildExtras1) {
  97. apply from: 'build-extras.gradle'
  98. }
  99. def hasBuildExtras2 = file('../build-extras.gradle').exists()
  100. if (hasBuildExtras2) {
  101. apply from: '../build-extras.gradle'
  102. }
  103. // Set property defaults after extension .gradle files.
  104. ext.cdvCompileSdkVersion = cdvCompileSdkVersion == null ? (
  105. defaultCompileSdkVersion == null
  106. ? privateHelpers.getProjectTarget()
  107. : defaultCompileSdkVersion
  108. ) : Integer.parseInt('' + cdvCompileSdkVersion);
  109. if (ext.cdvBuildToolsVersion == null) {
  110. ext.cdvBuildToolsVersion = privateHelpers.findLatestInstalledBuildTools()
  111. //ext.cdvBuildToolsVersion = project.ext.defaultBuildToolsVersion
  112. }
  113. if (ext.cdvDebugSigningPropertiesFile == null && file('../debug-signing.properties').exists()) {
  114. ext.cdvDebugSigningPropertiesFile = '../debug-signing.properties'
  115. }
  116. if (ext.cdvReleaseSigningPropertiesFile == null && file('../release-signing.properties').exists()) {
  117. ext.cdvReleaseSigningPropertiesFile = '../release-signing.properties'
  118. }
  119. // Cast to appropriate types.
  120. ext.cdvBuildMultipleApks = cdvBuildMultipleApks == null ? false : cdvBuildMultipleApks.toBoolean();
  121. ext.cdvVersionCodeForceAbiDigit = cdvVersionCodeForceAbiDigit == null ? false : cdvVersionCodeForceAbiDigit.toBoolean();
  122. // minSdkVersion, maxSdkVersion and targetSdkVersion
  123. ext.cdvMinSdkVersion = cdvMinSdkVersion == null ? defaultMinSdkVersion : Integer.parseInt('' + cdvMinSdkVersion)
  124. if (cdvMaxSdkVersion != null) {
  125. ext.cdvMaxSdkVersion = Integer.parseInt('' + cdvMaxSdkVersion)
  126. }
  127. ext.cdvTargetSdkVersion = cdvTargetSdkVersion == null ? defaultTargetSdkVersion : Integer.parseInt('' + cdvTargetSdkVersion)
  128. ext.cdvVersionCode = cdvVersionCode == null ? null : Integer.parseInt('' + cdvVersionCode)
  129. def computeBuildTargetName(debugBuild) {
  130. def ret = 'assemble'
  131. if (cdvBuildMultipleApks && cdvBuildArch) {
  132. def arch = cdvBuildArch == 'arm' ? 'armv7' : cdvBuildArch
  133. ret += '' + arch.toUpperCase().charAt(0) + arch.substring(1);
  134. }
  135. return ret + (debugBuild ? 'Debug' : 'Release')
  136. }
  137. // Make cdvBuild a task that depends on the debug/arch-sepecific task.
  138. task cdvBuildDebug
  139. cdvBuildDebug.dependsOn {
  140. return computeBuildTargetName(true)
  141. }
  142. task cdvBuildRelease
  143. cdvBuildRelease.dependsOn {
  144. return computeBuildTargetName(false)
  145. }
  146. task cdvPrintProps {
  147. doLast {
  148. println('cdvCompileSdkVersion=' + cdvCompileSdkVersion)
  149. println('cdvBuildToolsVersion=' + cdvBuildToolsVersion)
  150. println('cdvVersionCode=' + cdvVersionCode)
  151. println('cdvVersionCodeForceAbiDigit=' + cdvVersionCodeForceAbiDigit)
  152. println('cdvMinSdkVersion=' + cdvMinSdkVersion)
  153. println('cdvMaxSdkVersion=' + cdvMaxSdkVersion)
  154. println('cdvTargetSdkVersion=' + cdvTargetSdkVersion)
  155. println('cdvBuildMultipleApks=' + cdvBuildMultipleApks)
  156. println('cdvReleaseSigningPropertiesFile=' + cdvReleaseSigningPropertiesFile)
  157. println('cdvDebugSigningPropertiesFile=' + cdvDebugSigningPropertiesFile)
  158. println('cdvBuildArch=' + cdvBuildArch)
  159. println('computedVersionCode=' + android.defaultConfig.versionCode)
  160. android.productFlavors.each { flavor ->
  161. println('computed' + flavor.name.capitalize() + 'VersionCode=' + flavor.versionCode)
  162. }
  163. }
  164. }
  165. android {
  166. defaultConfig {
  167. versionCode cdvVersionCode ?: new BigInteger("" + privateHelpers.extractIntFromManifest("versionCode"))
  168. applicationId privateHelpers.extractStringFromManifest("package")
  169. if (cdvMinSdkVersion != null) {
  170. minSdkVersion cdvMinSdkVersion
  171. }
  172. if (cdvMaxSdkVersion != null) {
  173. maxSdkVersion cdvMaxSdkVersion
  174. }
  175. if(cdvTargetSdkVersion != null) {
  176. targetSdkVersion cdvTargetSdkVersion
  177. }
  178. }
  179. lintOptions {
  180. abortOnError false;
  181. }
  182. compileSdkVersion cdvCompileSdkVersion
  183. buildToolsVersion cdvBuildToolsVersion
  184. // This code exists for Crosswalk and other Native APIs.
  185. // By default, we multiply the existing version code in the
  186. // Android Manifest by 10 and add a number for each architecture.
  187. // If you are not using Crosswalk or SQLite, you can
  188. // ignore this chunk of code, and your version codes will be respected.
  189. if (Boolean.valueOf(cdvBuildMultipleApks)) {
  190. flavorDimensions "default"
  191. productFlavors {
  192. armeabi {
  193. versionCode defaultConfig.versionCode*10 + 1
  194. ndk {
  195. abiFilters = ["armeabi"]
  196. }
  197. }
  198. armv7 {
  199. versionCode defaultConfig.versionCode*10 + 2
  200. ndk {
  201. abiFilters = ["armeabi-v7a"]
  202. }
  203. }
  204. arm64 {
  205. versionCode defaultConfig.versionCode*10 + 3
  206. ndk {
  207. abiFilters = ["arm64-v8a"]
  208. }
  209. }
  210. x86 {
  211. versionCode defaultConfig.versionCode*10 + 4
  212. ndk {
  213. abiFilters = ["x86"]
  214. }
  215. }
  216. x86_64 {
  217. versionCode defaultConfig.versionCode*10 + 5
  218. ndk {
  219. abiFilters = ["x86_64"]
  220. }
  221. }
  222. }
  223. } else if (Boolean.valueOf(cdvVersionCodeForceAbiDigit)) {
  224. // This provides compatibility to the default logic for versionCode before cordova-android 5.2.0
  225. defaultConfig {
  226. versionCode defaultConfig.versionCode*10
  227. }
  228. }
  229. compileOptions {
  230. sourceCompatibility JavaVersion.VERSION_1_8
  231. targetCompatibility JavaVersion.VERSION_1_8
  232. }
  233. if (cdvReleaseSigningPropertiesFile) {
  234. signingConfigs {
  235. release {
  236. // These must be set or Gradle will complain (even if they are overridden).
  237. keyAlias = ""
  238. keyPassword = "__unset" // And these must be set to non-empty in order to have the signing step added to the task graph.
  239. storeFile = null
  240. storePassword = "__unset"
  241. }
  242. }
  243. buildTypes {
  244. release {
  245. signingConfig signingConfigs.release
  246. }
  247. }
  248. addSigningProps(cdvReleaseSigningPropertiesFile, signingConfigs.release)
  249. }
  250. if (cdvDebugSigningPropertiesFile) {
  251. addSigningProps(cdvDebugSigningPropertiesFile, signingConfigs.debug)
  252. }
  253. }
  254. /*
  255. * WARNING: Cordova Lib and platform scripts do management inside of this code here,
  256. * if you are adding the dependencies manually, do so outside the comments, otherwise
  257. * the Cordova tools will overwrite them
  258. */
  259. dependencies {
  260. implementation fileTree(dir: 'libs', include: '*.jar')
  261. // SUB-PROJECT DEPENDENCIES START
  262. implementation(project(path: ":CordovaLib"))
  263. implementation "com.squareup.okhttp3:okhttp-urlconnection:3.10.0"
  264. implementation "com.android.support:support-v4:24.1.1+"
  265. implementation "com.android.support:support-v4:27.+"
  266. implementation "com.android.support:support-annotations:27.+"
  267. implementation "com.android.support:support-v4:26.+"
  268. // SUB-PROJECT DEPENDENCIES END
  269. }
  270. def promptForReleaseKeyPassword() {
  271. if (!cdvReleaseSigningPropertiesFile) {
  272. return;
  273. }
  274. if ('__unset'.equals(android.signingConfigs.release.storePassword)) {
  275. android.signingConfigs.release.storePassword = privateHelpers.promptForPassword('Enter key store password: ')
  276. }
  277. if ('__unset'.equals(android.signingConfigs.release.keyPassword)) {
  278. android.signingConfigs.release.keyPassword = privateHelpers.promptForPassword('Enter key password: ');
  279. }
  280. }
  281. gradle.taskGraph.whenReady { taskGraph ->
  282. taskGraph.getAllTasks().each() { task ->
  283. if(['validateReleaseSigning', 'validateSigningRelease', 'validateSigningArmv7Release', 'validateSigningX76Release'].contains(task.name)) {
  284. promptForReleaseKeyPassword()
  285. }
  286. }
  287. }
  288. def addSigningProps(propsFilePath, signingConfig) {
  289. def propsFile = file(propsFilePath)
  290. def props = new Properties()
  291. propsFile.withReader { reader ->
  292. props.load(reader)
  293. }
  294. def storeFile = new File(props.get('key.store') ?: privateHelpers.ensureValueExists(propsFilePath, props, 'storeFile'))
  295. if (!storeFile.isAbsolute()) {
  296. storeFile = RelativePath.parse(true, storeFile.toString()).getFile(propsFile.getParentFile())
  297. }
  298. if (!storeFile.exists()) {
  299. throw new FileNotFoundException('Keystore file does not exist: ' + storeFile.getAbsolutePath())
  300. }
  301. signingConfig.keyAlias = props.get('key.alias') ?: privateHelpers.ensureValueExists(propsFilePath, props, 'keyAlias')
  302. signingConfig.keyPassword = props.get('keyPassword', props.get('key.alias.password', signingConfig.keyPassword))
  303. signingConfig.storeFile = storeFile
  304. signingConfig.storePassword = props.get('storePassword', props.get('key.store.password', signingConfig.storePassword))
  305. def storeType = props.get('storeType', props.get('key.store.type', ''))
  306. if (!storeType) {
  307. def filename = storeFile.getName().toLowerCase();
  308. if (filename.endsWith('.p12') || filename.endsWith('.pfx')) {
  309. storeType = 'pkcs12'
  310. } else {
  311. storeType = signingConfig.storeType // "jks"
  312. }
  313. }
  314. signingConfig.storeType = storeType
  315. }
  316. for (def func : cdvPluginPostBuildExtras) {
  317. func()
  318. }
  319. // This can be defined within build-extras.gradle as:
  320. // ext.postBuildExtras = { ... code here ... }
  321. if (hasProperty('postBuildExtras')) {
  322. postBuildExtras()
  323. }