aboutsummaryrefslogtreecommitdiffhomepage
path: root/platform_tools/android/apps/build.gradle
blob: 901e3295eae0f23e87a11fd8b43115a1f83cae95 (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Top-level build file where you can add configuration options common to all sub-projects/modules.


buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

def setupSkiaLibraryBuild(project, appVariants, buildCmd, requireCMake = false) {
    appVariants.all{ variant ->
        def buildNativeLib = project.task("${variant.name}_SkiaNativeLib", type:Exec) {
            workingDir '../../../..' // top-level skia directory
            commandLine constructBuildCommand(variant, buildCmd).split()
            environment PATH: getPathWithDeps(requireCMake)
            environment ANDROID_SDK_ROOT: getSDKPath()
        }
        buildNativeLib.onlyIf { !project.hasProperty("suppressNativeBuild") }
        TaskCollection<Task> compileTask = project.tasks.matching {
            //  println(it.name)
            it.name.toLowerCase().contains("compile" + variant.name.toLowerCase()) &&
                    it.name.toLowerCase().endsWith("ndk")
        }
        compileTask.getAt(0).dependsOn buildNativeLib
    }
}

def getLocalProperties() {
    Properties properties = new Properties()
    File propFile = project.rootProject.file('local.properties')
    if (propFile.canRead()) {
        properties.load(propFile.newDataInputStream())
    }
    propFile = project.rootProject.file('gradle.properties')
    if (propFile.canRead()) {
        properties.load(propFile.newDataInputStream())
    }
    return properties
}

def getSDKPath() {
    String path = System.getenv("ANDROID_SDK_ROOT")
    if (path == null) {
        path = getLocalProperties().getProperty('sdk.dir', null)
    }

    if (path == null) {
        throw new GradleScriptException("Android SDK not found! Please set ANDROID_SDK_ROOT to" +
                                        " your path or define sdk.dir in gradle.properties")
    }
    return path
}

def getPathWithDeps(requireCMake = false) {
    String path = System.getenv("PATH")
    if (!path.contains("depot_tools")) {
        path += ":" + getLocalProperties().getProperty('depot_tools.dir', null)
    }

    if (!path.contains("depot_tools")) {
        throw GradleScriptException("Depot Tools not found! Please update your path to include" +
                                    " depot_tools or define depot_tools.dir in gradle.properties")
    }

    if (requireCMake) {
        String cmakePath = getSDKPath() + "/cmake/bin"
        if (!file(cmakePath).exists()) {
            logger.warn("cmake not found! Please install the android SDK version of cmake.");
        }
        if (!path.contains(cmakePath)) {
            path = cmakePath + ":" + path
        }
    }

    return path
}

def constructBuildCommand(variant, buildTarget) {
    String cmdLine = "./platform_tools/android/bin/android_ninja $buildTarget"
    String deviceType = null
    if (variant.name.startsWith("arm64")) {
        deviceType = "arm64"
    } else if (variant.name.startsWith("arm")) {
        deviceType = "arm_v7_neon"
    } else if (variant.name.startsWith("x86_64")) {
        deviceType = "x86_64"
    } else if (variant.name.startsWith("x86")) {
        deviceType = "x86"
    } else if (variant.name.startsWith("mips")) {
        deviceType = "mips"
    } else if (variant.name.startsWith("mips64")) {
        deviceType = "mips64"
    }

    if (deviceType != null) {
        cmdLine += " -d " + deviceType
    }

    if (variant.name.endsWith("Release")) {
        cmdLine += " --release"
    }
    return cmdLine
}