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