pumpApp-xwalk.gradle 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. def EMBEDDED_MODE = "embedded"
  18. def SHARED_MODE = "shared"
  19. def LITE_MODE = "lite"
  20. def DEFAULT_GROUP_ID = "org.xwalk:"
  21. def SHARED_ARTIFACT_ID = "xwalk_shared_library:"
  22. def EMBEDD_ARTIFACT_ID = "xwalk_core_library:"
  23. def CANARY_ARTIFACT_ID = "xwalk_core_library_canary:"
  24. def BIT_64 = ":64bit@aar"
  25. def DEFAULT_MIN_SDK_VERSION = 14
  26. def getConfigPreference(name) {
  27. name = name.toLowerCase()
  28. def xml
  29. if (file("src/main/res/xml/config.xml").exists()) {
  30. // cordova-android >= 7.0.0
  31. xml = file("src/main/res/xml/config.xml").getText()
  32. } else {
  33. // cordova-android < 7.0.0
  34. xml = file("res/xml/config.xml").getText()
  35. }
  36. // Disable namespace awareness since Cordova doesn't use them properly
  37. def root = new XmlParser(false, false).parseText(xml)
  38. def ret, defaultValue
  39. root.preference.each { it ->
  40. def attrName = it.attribute("name")
  41. if (attrName && attrName.toLowerCase() == name) {
  42. if (it.attribute('default') != null) {
  43. defaultValue = it.attribute('default');
  44. } else {
  45. ret = it.attribute("value")
  46. }
  47. }
  48. }
  49. return ret ? ret : defaultValue
  50. }
  51. if (!project.hasProperty('xwalk64bit')) {
  52. ext.xwalk64bit = getConfigPreference("xwalk64bit");
  53. println xwalk64bit
  54. }
  55. if (cdvBuildMultipleApks == null) {
  56. ext.xwalkMultipleApk = getConfigPreference("xwalkMultipleApk").toBoolean();
  57. } else {
  58. ext.xwalkMultipleApk = cdvBuildMultipleApks.toBoolean();
  59. }
  60. def minSdk = getConfigPreference("android-minSdkVersion");
  61. if (cdvMinSdkVersion == null) {
  62. ext.cdvMinSdkVersion = minSdk && Integer.parseInt(minSdk) > DEFAULT_MIN_SDK_VERSION ? minSdk : DEFAULT_MIN_SDK_VERSION;
  63. } else if (Integer.parseInt('' + cdvMinSdkVersion) < Integer.parseInt(minSdk)) {
  64. ext.cdvMinSdkVersion = minSdk;
  65. }
  66. if (!project.hasProperty('xwalkMode')) {
  67. ext.xwalkMode = getConfigPreference("xwalkMode");
  68. }
  69. if (ext.xwalkMode == SHARED_MODE) {
  70. // Build one apk at shared mode because the value of
  71. // ext.cdvBuildMultipleApks is false by default.
  72. xwalk64bit = null;
  73. } else if (xwalk64bit == null) {
  74. // Build embedded 32 bit crosswalk will generate two apks by default.
  75. ext.cdvBuildMultipleApks = xwalkMultipleApk;
  76. }
  77. // Set defaults before project's build-extras.gradle
  78. if (!project.hasProperty('xwalkVersion')) {
  79. ext.xwalkVersion = getConfigPreference("xwalkVersion")
  80. }
  81. // Set defaults before project's build-extras.gradle
  82. if (!project.hasProperty('xwalkLiteVersion')) {
  83. ext.xwalkLiteVersion = getConfigPreference("xwalkLiteVersion")
  84. }
  85. if (!project.hasProperty('xwalkCommandLine')) {
  86. ext.xwalkCommandLine = getConfigPreference("xwalkCommandLine")
  87. }
  88. // Apply values after project's build-extras.gradle
  89. cdvPluginPostBuildExtras.add({
  90. def xwalkMavenRepo = 'https://download.01.org/crosswalk/releases/crosswalk/android/maven2';
  91. if (xwalkMode == LITE_MODE) {
  92. xwalkMavenRepo = 'https://download.01.org/crosswalk/releases/crosswalk-lite/android/maven2';
  93. }
  94. repositories {
  95. maven {
  96. url xwalkMavenRepo
  97. }
  98. }
  99. android {
  100. if (xwalk64bit != null) {
  101. productFlavors {
  102. x86_64 {
  103. versionCode defaultConfig.versionCode + 6
  104. ndk {
  105. abiFilters "x86_64", ""
  106. }
  107. }
  108. arm64 {
  109. versionCode defaultConfig.versionCode + 9
  110. ndk {
  111. abiFilters "arm64-v8a", ""
  112. }
  113. }
  114. }
  115. }
  116. }
  117. def xwalkSpec = xwalkVersion
  118. if (ext.xwalkMode == LITE_MODE) {
  119. xwalkSpec = xwalkLiteVersion;
  120. }
  121. if ((xwalkSpec =~ /:/).count == 1) {
  122. xwalkSpec = DEFAULT_GROUP_ID + xwalkSpec
  123. } else if ((xwalkSpec =~ /:/).count == 0) {
  124. if (xwalkSpec ==~ /\d+/) {
  125. xwalkSpec = "${xwalkSpec}+"
  126. }
  127. def artifactid = EMBEDD_ARTIFACT_ID;
  128. if (ext.xwalkMode == SHARED_MODE) {
  129. artifactid = SHARED_ARTIFACT_ID;
  130. } else if (ext.xwalkMode == LITE_MODE) {
  131. artifactid = CANARY_ARTIFACT_ID;
  132. }
  133. xwalkSpec = DEFAULT_GROUP_ID + artifactid + xwalkSpec
  134. }
  135. if (xwalk64bit != null) {
  136. xwalkSpec = xwalkSpec + BIT_64
  137. }
  138. println xwalkSpec
  139. dependencies {
  140. compile xwalkSpec
  141. }
  142. configurations.all {
  143. resolutionStrategy {
  144. force 'com.android.support:support-v4:27.1.0'
  145. }
  146. }
  147. if (file('assets/xwalk-command-line').exists()) {
  148. println('Not writing assets/xwalk-command-line since file already exists.')
  149. return
  150. }
  151. android.applicationVariants.all { variant ->
  152. def variantName = variant.name.capitalize()
  153. def mergeTask = tasks["merge${variantName}Assets"]
  154. def processTask = tasks["process${variantName}Resources"]
  155. def outFile = new File (mergeTask.outputDir, "xwalk-command-line")
  156. def newTask = project.task("createXwalkCommandLineFile${variantName}") << {
  157. mergeTask.outputDir.mkdirs()
  158. outFile.write("xwalk ${xwalkCommandLine}\n")
  159. }
  160. newTask.dependsOn(mergeTask)
  161. processTask.dependsOn(newTask)
  162. }
  163. })