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