1 // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 3 4 buildscript { 5 repositories { 6 jcenter() 7 } 8 dependencies { 9 classpath 'com.android.tools.build:gradle:2.2.3' 10 11 // NOTE: Do not place your application dependencies here; they belong 12 // in the individual module build.gradle files 13 } 14 } 15 16 allprojects { 17 repositories { 18 jcenter() 19 } 20 } 21 22 def setupSkiaLibraryBuild(project, appVariants, appName) { 23 appVariants.all{ variant -> 24 def buildNativeLib = project.task("${variant.name}_BuildSkiaLib", type:Exec) { 25 workingDir '../../../..' // top-level skia directory 26 commandLine constructBuildCommand(project, variant, appName).split() 27 } 28 buildNativeLib.onlyIf { !project.hasProperty("suppressNativeBuild") } 29 30 def copyNativeLib = project.task("${variant.name}_CopySkiaLib", type:Copy) { 31 def fromDir = getVariantOutDir(project, variant).skiaOut 32 def intoDir = getVariantOutDir(project, variant).androidOut 33 from fromDir 34 into intoDir 35 include "${appName}.so" 36 } 37 38 TaskCollection<Task> compileTask = project.tasks.matching { 39 // println(it.name) 40 it.name.toLowerCase().contains("compile" + variant.name.toLowerCase()) && 41 it.name.toLowerCase().endsWith("ndk") 42 } 43 compileTask.findAll()*.dependsOn copyNativeLib 44 copyNativeLib.dependsOn buildNativeLib 45 } 46 } 47 48 def getLocalProperties() { 49 Properties properties = new Properties() 50 File propFile = project.rootProject.file('local.properties') 51 if (propFile.canRead()) { 52 properties.load(propFile.newDataInputStream()) 53 } 54 propFile = project.rootProject.file('gradle.properties') 55 if (propFile.canRead()) { 56 properties.load(propFile.newDataInputStream()) 57 } 58 return properties 59 } 60 61 def getVariantOutDir(project, variant) { 62 String variantPrefix = null 63 String androidLibDir = null 64 if (variant.name.startsWith("arm64")) { 65 variantPrefix = "arm64" 66 androidLibDir = "arm64-v8a" 67 } else if (variant.name.startsWith("arm")) { 68 variantPrefix = "arm" 69 androidLibDir = "armeabi-v7a" 70 } else if (variant.name.startsWith("x64")) { 71 variantPrefix = "x64" 72 androidLibDir = "x86_64" 73 } else if (variant.name.startsWith("x86")) { 74 variantPrefix = "x86" 75 androidLibDir = "x86" 76 } 77 78 String skiaOutDir = null 79 String propName = "${variantPrefix}.out.dir" 80 if (project.hasProperty(propName)) { 81 skiaOutDir = project.getProperties().getAt(propName) 82 } else { 83 skiaOutDir = getLocalProperties().getProperty(propName, "missing_variant_out") 84 } 85 86 return [skiaOut: skiaOutDir, 87 androidOut: "src/main/libs/${androidLibDir}"] 88 } 89 90 def constructBuildCommand(project, variant, appName) { 91 String depotToolsDir = null 92 for (String entry : System.getenv("PATH").split(":")) { 93 if (entry.contains("depot_tools")) { 94 depotToolsDir = entry; 95 break; 96 } 97 } 98 if (depotToolsDir == null) { 99 depotToolsDir = getLocalProperties().getProperty('depot_tools.dir', null) 100 } 101 102 if (depotToolsDir == null) { 103 throw GradleScriptException("Depot Tools not found! Please update your path to include" + 104 " depot_tools or define depot_tools.dir in local.properties") 105 } 106 107 String out_dir = getVariantOutDir(project, variant).skiaOut 108 return "${depotToolsDir}/ninja -C $out_dir $appName" 109 } 110