summaryrefslogtreecommitdiff
path: root/plugins/cordova-plugin-crosswalk-webview/src/android/xwalk.gradle
blob: 3c0a23eeebf9381792b46390ba423ce17028726e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
       Licensed to the Apache Software Foundation (ASF) under one
       or more contributor license agreements.  See the NOTICE file
       distributed with this work for additional information
       regarding copyright ownership.  The ASF licenses this file
       to you under the Apache License, Version 2.0 (the
       "License"); you may not use this file except in compliance
       with the License.  You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

       Unless required by applicable law or agreed to in writing,
       software distributed under the License is distributed on an
       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
       KIND, either express or implied.  See the License for the
       specific language governing permissions and limitations
       under the License.
*/

def DEFAULT_VERSION = "org.xwalk:xwalk_core_library_beta:13+"
def DEFAULT_COMMAND_LINE = "--disable-pull-to-refresh-effect"

repositories {
  maven {
    url 'https://download.01.org/crosswalk/releases/crosswalk/android/maven2'
  }
}

if (cdvBuildMultipleApks == null) {
    ext.cdvBuildMultipleApks = true
}
if (cdvMinSdkVersion == null) {
    ext.cdvMinSdkVersion = 14
}

def getConfigPreference(name, defaultValue) {
    name = name.toLowerCase()
    def xml = file("res/xml/config.xml").getText()
    // Disable namespace awareness since Cordova doesn't use them properly
    def root = new XmlParser(false, false).parseText(xml)

    def ret = defaultValue
    root.preference.each { it ->
        def attrName = it.attribute("name")
        if (attrName && attrName.toLowerCase() == name) {
            ret = it.attribute("value")
        }
    }
    return ret
}

// Set defaults before project's build-extras.gradle
if (!project.hasProperty('xwalkVersion')) {
    ext.xwalkVersion = getConfigPreference("xwalkversion", DEFAULT_VERSION)
}
if (!project.hasProperty('xwalkCommandLine')) {
    ext.xwalkCommandLine = getConfigPreference("xwalkcommandline", DEFAULT_COMMAND_LINE)
}

// Apply values after project's build-extras.gradle
cdvPluginPostBuildExtras.add({

    def xwalkSpec = xwalkVersion
    if ((xwalkSpec =~ /:/).count == 1) {
        xwalkSpec = "org.xwalk:${xwalkSpec}"
    } else if ((xwalkSpec =~ /:/).count == 0) {
        if (xwalkSpec ==~ /\d+/) {
            xwalkSpec = "${xwalkSpec}+"
        }
        xwalkSpec = "org.xwalk:xwalk_core_library_beta:${xwalkSpec}"
    }

    dependencies {
        compile xwalkSpec
    }

    if (file('assets/xwalk-command-line').exists()) {
        println('Not writing assets/xwalk-command-line since file already exists.')
        return
    }
    android.applicationVariants.all { variant ->
        def variantName = variant.name.capitalize()
        def mergeTask = tasks["merge${variantName}Assets"]
        def processTask = tasks["process${variantName}Resources"]
        def outFile = new File (mergeTask.outputDir, "xwalk-command-line")
        def newTask = project.task("createXwalkCommandLineFile${variantName}") << {
            mergeTask.outputDir.mkdirs()
            outFile.write("xwalk ${xwalkCommandLine}\n")
        }
        newTask.dependsOn(mergeTask)
        processTask.dependsOn(newTask)
    }
})