build.gradle 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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. // GENERATED FILE! DO NOT EDIT!
  18. apply plugin: 'android'
  19. buildscript {
  20. repositories {
  21. mavenCentral()
  22. }
  23. // Switch the Android Gradle plugin version requirement depending on the
  24. // installed version of Gradle. This dependency is documented at
  25. // http://tools.android.com/tech-docs/new-build-system/version-compatibility
  26. // and https://issues.apache.org/jira/browse/CB-8143
  27. if (gradle.gradleVersion >= "2.2") {
  28. dependencies {
  29. classpath 'com.android.tools.build:gradle:1.0.0+'
  30. }
  31. } else if (gradle.gradleVersion >= "2.1") {
  32. dependencies {
  33. classpath 'com.android.tools.build:gradle:0.14.0+'
  34. }
  35. } else {
  36. dependencies {
  37. classpath 'com.android.tools.build:gradle:0.12.0+'
  38. }
  39. }
  40. }
  41. // Allow plugins to declare Maven dependencies via build-extras.gradle.
  42. repositories {
  43. mavenCentral()
  44. }
  45. task wrapper(type: Wrapper) {
  46. gradleVersion = '2.2.1'
  47. }
  48. // Configuration properties. Set these via environment variables, build-extras.gradle, or gradle.properties.
  49. // Refer to: http://www.gradle.org/docs/current/userguide/tutorial_this_and_that.html
  50. ext {
  51. apply from: 'CordovaLib/cordova.gradle'
  52. // The value for android.compileSdkVersion.
  53. if (!project.hasProperty('cdvCompileSdkVersion')) {
  54. cdvCompileSdkVersion = null;
  55. }
  56. // The value for android.buildToolsVersion.
  57. if (!project.hasProperty('cdvBuildToolsVersion')) {
  58. cdvBuildToolsVersion = null;
  59. }
  60. // Sets the versionCode to the given value.
  61. if (!project.hasProperty('cdvVersionCode')) {
  62. cdvVersionCode = null
  63. }
  64. // Sets the minSdkVersion to the given value.
  65. if (!project.hasProperty('cdvMinSdkVersion')) {
  66. cdvMinSdkVersion = null
  67. }
  68. // Whether to build architecture-specific APKs.
  69. if (!project.hasProperty('cdvBuildMultipleApks')) {
  70. cdvBuildMultipleApks = null
  71. }
  72. // .properties files to use for release signing.
  73. if (!project.hasProperty('cdvReleaseSigningPropertiesFile')) {
  74. cdvReleaseSigningPropertiesFile = null
  75. }
  76. // .properties files to use for debug signing.
  77. if (!project.hasProperty('cdvDebugSigningPropertiesFile')) {
  78. cdvDebugSigningPropertiesFile = null
  79. }
  80. // Set by build.js script.
  81. if (!project.hasProperty('cdvBuildArch')) {
  82. cdvBuildArch = null
  83. }
  84. // Plugin gradle extensions can append to this to have code run at the end.
  85. cdvPluginPostBuildExtras = []
  86. }
  87. // PLUGIN GRADLE EXTENSIONS START
  88. // PLUGIN GRADLE EXTENSIONS END
  89. def hasBuildExtras = file('build-extras.gradle').exists()
  90. if (hasBuildExtras) {
  91. apply from: 'build-extras.gradle'
  92. }
  93. // Set property defaults after extension .gradle files.
  94. if (ext.cdvCompileSdkVersion == null) {
  95. ext.cdvCompileSdkVersion = privateHelpers.getProjectTarget()
  96. }
  97. if (ext.cdvBuildToolsVersion == null) {
  98. ext.cdvBuildToolsVersion = privateHelpers.findLatestInstalledBuildTools()
  99. }
  100. if (ext.cdvDebugSigningPropertiesFile == null && file('debug-signing.properties').exists()) {
  101. ext.cdvDebugSigningPropertiesFile = 'debug-signing.properties'
  102. }
  103. if (ext.cdvReleaseSigningPropertiesFile == null && file('release-signing.properties').exists()) {
  104. ext.cdvReleaseSigningPropertiesFile = 'release-signing.properties'
  105. }
  106. // Cast to appropriate types.
  107. ext.cdvBuildMultipleApks = cdvBuildMultipleApks == null ? false : cdvBuildMultipleApks.toBoolean();
  108. ext.cdvMinSdkVersion = cdvMinSdkVersion == null ? null : Integer.parseInt('' + cdvMinSdkVersion)
  109. ext.cdvVersionCode = cdvVersionCode == null ? null : Integer.parseInt('' + cdvVersionCode)
  110. def computeBuildTargetName(debugBuild) {
  111. def ret = 'assemble'
  112. if (cdvBuildMultipleApks && cdvBuildArch) {
  113. def arch = cdvBuildArch == 'arm' ? 'armv7' : cdvBuildArch
  114. ret += '' + arch.toUpperCase().charAt(0) + arch.substring(1);
  115. }
  116. return ret + (debugBuild ? 'Debug' : 'Release')
  117. }
  118. // Make cdvBuild a task that depends on the debug/arch-sepecific task.
  119. task cdvBuildDebug
  120. cdvBuildDebug.dependsOn {
  121. return computeBuildTargetName(true)
  122. }
  123. task cdvBuildRelease
  124. cdvBuildRelease.dependsOn {
  125. return computeBuildTargetName(false)
  126. }
  127. task cdvPrintProps << {
  128. println('cdvCompileSdkVersion=' + cdvCompileSdkVersion)
  129. println('cdvBuildToolsVersion=' + cdvBuildToolsVersion)
  130. println('cdvVersionCode=' + cdvVersionCode)
  131. println('cdvMinSdkVersion=' + cdvMinSdkVersion)
  132. println('cdvBuildMultipleApks=' + cdvBuildMultipleApks)
  133. println('cdvReleaseSigningPropertiesFile=' + cdvReleaseSigningPropertiesFile)
  134. println('cdvDebugSigningPropertiesFile=' + cdvDebugSigningPropertiesFile)
  135. println('cdvBuildArch=' + cdvBuildArch)
  136. println('computedVersionCode=' + android.defaultConfig.versionCode)
  137. android.productFlavors.each { flavor ->
  138. println('computed' + flavor.name.capitalize() + 'VersionCode=' + flavor.versionCode)
  139. }
  140. }
  141. android {
  142. sourceSets {
  143. main {
  144. manifest.srcFile 'AndroidManifest.xml'
  145. java.srcDirs = ['src']
  146. resources.srcDirs = ['src']
  147. aidl.srcDirs = ['src']
  148. renderscript.srcDirs = ['src']
  149. res.srcDirs = ['res']
  150. assets.srcDirs = ['assets']
  151. jniLibs.srcDirs = ['libs']
  152. }
  153. }
  154. defaultConfig {
  155. versionCode cdvVersionCode ?: Integer.parseInt("" + privateHelpers.extractIntFromManifest("versionCode") + "0")
  156. if (cdvMinSdkVersion != null) {
  157. minSdkVersion cdvMinSdkVersion
  158. }
  159. }
  160. compileSdkVersion cdvCompileSdkVersion
  161. buildToolsVersion cdvBuildToolsVersion
  162. if (Boolean.valueOf(cdvBuildMultipleApks)) {
  163. productFlavors {
  164. armv7 {
  165. versionCode cdvVersionCode ?: defaultConfig.versionCode + 2
  166. ndk {
  167. abiFilters "armeabi-v7a", ""
  168. }
  169. }
  170. x86 {
  171. versionCode cdvVersionCode ?: defaultConfig.versionCode + 4
  172. ndk {
  173. abiFilters "x86", ""
  174. }
  175. }
  176. all {
  177. ndk {
  178. abiFilters "all", ""
  179. }
  180. }
  181. }
  182. } else if (!cdvVersionCode) {
  183. def minSdkVersion = cdvMinSdkVersion ?: privateHelpers.extractIntFromManifest("minSdkVersion")
  184. // Vary versionCode by the two most common API levels:
  185. // 14 is ICS, which is the lowest API level for many apps.
  186. // 20 is Lollipop, which is the lowest API level for the updatable system webview.
  187. if (minSdkVersion >= 20) {
  188. defaultConfig.versionCode += 9
  189. } else if (minSdkVersion >= 14) {
  190. defaultConfig.versionCode += 8
  191. }
  192. }
  193. compileOptions {
  194. sourceCompatibility JavaVersion.VERSION_1_6
  195. targetCompatibility JavaVersion.VERSION_1_6
  196. }
  197. if (cdvReleaseSigningPropertiesFile) {
  198. signingConfigs {
  199. release {
  200. // These must be set or Gradle will complain (even if they are overridden).
  201. keyAlias = ""
  202. keyPassword = "__unset" // And these must be set to non-empty in order to have the signing step added to the task graph.
  203. storeFile = null
  204. storePassword = "__unset"
  205. }
  206. }
  207. buildTypes {
  208. release {
  209. signingConfig signingConfigs.release
  210. }
  211. }
  212. addSigningProps(cdvReleaseSigningPropertiesFile, signingConfigs.release)
  213. }
  214. if (cdvDebugSigningPropertiesFile) {
  215. addSigningProps(cdvDebugSigningPropertiesFile, signingConfigs.debug)
  216. }
  217. }
  218. dependencies {
  219. compile fileTree(dir: 'libs', include: '*.jar')
  220. // SUB-PROJECT DEPENDENCIES START
  221. debugCompile project(path: "CordovaLib", configuration: "debug")
  222. releaseCompile project(path: "CordovaLib", configuration: "release")
  223. // SUB-PROJECT DEPENDENCIES END
  224. }
  225. def promptForReleaseKeyPassword() {
  226. if (!cdvReleaseSigningPropertiesFile) {
  227. return;
  228. }
  229. if ('__unset'.equals(android.signingConfigs.release.storePassword)) {
  230. android.signingConfigs.release.storePassword = privateHelpers.promptForPassword('Enter key store password: ')
  231. }
  232. if ('__unset'.equals(android.signingConfigs.release.keyPassword)) {
  233. android.signingConfigs.release.keyPassword = privateHelpers.promptForPassword('Enter key password: ');
  234. }
  235. }
  236. gradle.taskGraph.whenReady { taskGraph ->
  237. taskGraph.getAllTasks().each() { task ->
  238. if (task.name == 'validateReleaseSigning') {
  239. promptForReleaseKeyPassword()
  240. }
  241. }
  242. }
  243. def addSigningProps(propsFilePath, signingConfig) {
  244. def propsFile = file(propsFilePath)
  245. def props = new Properties()
  246. propsFile.withReader { reader ->
  247. props.load(reader)
  248. }
  249. def storeFile = new File(props.get('key.store') ?: privateHelpers.ensureValueExists(propsFilePath, props, 'storeFile'))
  250. if (!storeFile.isAbsolute()) {
  251. storeFile = RelativePath.parse(true, storeFile.toString()).getFile(propsFile.getParentFile())
  252. }
  253. if (!storeFile.exists()) {
  254. throw new FileNotFoundException('Keystore file does not exist: ' + storeFile.getAbsolutePath())
  255. }
  256. signingConfig.keyAlias = props.get('key.alias') ?: privateHelpers.ensureValueExists(propsFilePath, props, 'keyAlias')
  257. signingConfig.keyPassword = props.get('keyPassword', props.get('key.alias.password', signingConfig.keyPassword))
  258. signingConfig.storeFile = storeFile
  259. signingConfig.storePassword = props.get('storePassword', props.get('key.store.password', signingConfig.storePassword))
  260. def storeType = props.get('storeType', props.get('key.store.type', ''))
  261. if (!storeType) {
  262. def filename = storeFile.getName().toLowerCase();
  263. if (filename.endsWith('.p12') || filename.endsWith('.pfx')) {
  264. storeType = 'pkcs12'
  265. } else {
  266. storeType = signingConfig.storeType // "jks"
  267. }
  268. }
  269. signingConfig.storeType = storeType
  270. }
  271. for (def func : cdvPluginPostBuildExtras) {
  272. func()
  273. }
  274. // This can be defined within build-extras.gradle as:
  275. // ext.postBuildExtras = { ... code here ... }
  276. if (hasProperty('postBuildExtras')) {
  277. postBuildExtras()
  278. }