1 // Top-level build file where you can add configuration options common to all sub-projects/modules.
4 import java.nio.file.Paths
5 import org.apache.tools.ant.taskdefs.condition.Os
13 classpath 'com.android.tools.build:gradle:3.2.0'
15 // NOTE: Do not place your application dependencies here; they belong
16 // in the individual module build.gradle files
27 def setupSkiaLibraryBuild(project, appVariants, appName) {
28 appVariants.all{ variant ->
29 def buildNativeLib = project.task("${variant.name}_BuildSkiaLib", type:Exec) {
30 workingDir '../../../..' // top-level skia directory
31 final String cmd = constructBuildCommand(project, variant, appName)
32 if (Os.isFamily(Os.FAMILY_WINDOWS)) {
33 commandLine "cmd", "/c", cmd
35 commandLine cmd.split()
38 buildNativeLib.onlyIf { !project.hasProperty("suppressNativeBuild") }
40 def copyNativeLib = project.task("${variant.name}_CopySkiaLib", type:Copy) {
41 def fromDir = getVariantOutDir(project, variant).skiaOut
42 def intoDir = getVariantOutDir(project, variant).androidOut
45 include "${appName}.so"
48 TaskCollection<Task> compileTask = project.tasks.matching {
50 it.name.toLowerCase().contains("compile" + variant.name.toLowerCase()) &&
51 it.name.toLowerCase().endsWith("ndk")
53 compileTask.findAll()*.dependsOn copyNativeLib
54 copyNativeLib.dependsOn buildNativeLib
58 def getLocalProperties() {
59 Properties properties = new Properties()
60 File propFile = project.rootProject.file('local.properties')
61 if (propFile.canRead()) {
62 properties.load(propFile.newDataInputStream())
64 propFile = project.rootProject.file('gradle.properties')
65 if (propFile.canRead()) {
66 properties.load(propFile.newDataInputStream())
71 def getVariantOutDir(project, variant) {
72 String variantPrefix = null
73 String androidLibDir = null
74 if (variant.name.startsWith("arm64")) {
75 variantPrefix = "arm64"
76 androidLibDir = "arm64-v8a"
77 } else if (variant.name.startsWith("arm")) {
79 androidLibDir = "armeabi-v7a"
80 } else if (variant.name.startsWith("x64")) {
82 androidLibDir = "x86_64"
83 } else if (variant.name.startsWith("x86")) {
88 String skiaOutDir = null
89 String propName = "${variantPrefix}.out.dir"
90 if (project.hasProperty(propName)) {
91 skiaOutDir = project.getProperties().getAt(propName)
93 skiaOutDir = getLocalProperties().getProperty(propName, "missing_variant_out")
96 return [skiaOut: skiaOutDir,
97 androidOut: "src/main/libs/${androidLibDir}"]
100 def constructBuildCommand(project, variant, appName) {
101 String depotToolsDir = null
102 for (String entry : System.getenv("PATH").split(File.pathSeparator)) {
103 if (Paths.get(entry).endsWith("depot_tools")) {
104 depotToolsDir = entry;
108 if (depotToolsDir == null) {
109 depotToolsDir = getLocalProperties().getProperty('depot_tools.dir', null)
112 if (depotToolsDir == null) {
113 throw GradleScriptException("Depot Tools not found! Please update your path to include" +
114 " depot_tools or define depot_tools.dir in local.properties")
117 String ninja = Paths.get(depotToolsDir, "ninja")
118 String out_dir = getVariantOutDir(project, variant).skiaOut
119 return "$ninja -C $out_dir $appName"