build.gradle 13 KB

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