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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
import org.apache.tools.ant.taskdefs.condition.Os
// Avoid conflicts with Bazel on case-insensitive filesystems
buildDir = 'gradle_build'
repositories {
jcenter()
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.2'
}
}
////////////////////////////////////////////////////////////////////////////////
// Use gradle's native C++ plugin to build the Halide generator.
//
// sources: defines all the C++ source files. We only have one SourceSet called
// halide_generator.
//
// executables: we only make one binary called halide_generator. Here is where
// we pass compiler and linker flags.
//
// binaries.withType: binaries is a collection, which in our case is just the
// halide_generator executable. withType() filters the collection by type.
// binary is the iteration variable. -> defines the body of the lambda:
// for each binary:
// for each halide_target / Android ABI mapping:
// for each generator:
// run the generator with -g and target set
// make the later ndkBuild task depend on this task.
apply plugin: "cpp"
sources {
halide_generator {
cpp(CppSourceSet) {
source {
srcDirs "jni/"
include "deinterleave_generator.cpp"
include "edge_detect_generator.cpp"
}
source {
srcDirs "../../tools"
include "GenGen.cpp"
}
}
}
}
executables {
halide_generator {
binaries.all {
cppCompiler.args "-std=c++17", "-g", "-Wall", "-fno-rtti", "-I", "${projectDir}/../../include", "-I", "${projectDir}/../../build/include"
// "/bin" assumes Makefile build for Halide; "/build/lib" assumes CMake build
linker.args "-lHalide", "-ldl", "-lpthread", "-lz", "-L", "${projectDir}/../../bin", "-L", "${projectDir}/../../build/lib"
}
}
}
binaries.withType(NativeExecutableBinary) { binary ->
def bin = "${projectDir}/bin"
def linkTask = binary.tasks.link
println "linktask output file is " + linkTask.outputFile
Map<String, String> archs = [
// armeabi and armeabi-v7a are the same as far as Halide is concerned
"armeabi": "arm-32-android",
"armeabi-v7a": "arm-32-android",
"arm64-v8a": "arm-64-android",
"x86_64": "x86-64-android-sse41",
"x86": "x86-32-android"
]
def generators = ["deinterleave", "edge_detect"]
archs.each {
arch -> println "creating task for: " + arch.key + " -> " + arch.value
def android_abi = arch.key
def hl_target = arch.value
def task_name = "generate_halide_binary_${binary.name.capitalize()}_${android_abi}"
def destDir = new File(bin, "${android_abi}")
def generateHalideTask = task(task_name) {
dependsOn linkTask
doFirst {
println "Executing: " + linkTask.outputFile + " ..."
destDir.mkdirs()
def envVars = [ "DYLD_LIBRARY_PATH=${projectDir}/../../bin", "LD_LIBRARY_PATH=${projectDir}/../../bin" ]
generators.each { generator ->
def proc = [linkTask.outputFile, "-g", generator, "-o", ".", "target=$hl_target"]
.execute(envVars, destDir)
proc.waitFor()
if (proc.exitValue() != 0) {
println "return code: ${proc.exitValue()}"
println "stderr: ${proc.err.text}"
println "stdout: ${proc.in.text}"
}
}
}
}
// Call this task generateHalideTask.
binary.builtBy generateHalideTask
// Tell gradle that the task called "ndkBuild" below depends
// on generateHalideTask.
ndkBuild.dependsOn generateHalideTask
}
println "done with archs"
}
////////////////////////////////////////////////////////////////////////////////
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.helloandroidcamera2"
minSdkVersion 21
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
sourceSets {
main {
java.srcDirs = ["src/"]
// Setting jni.srcDirs to [] disables the automatic ndk-build call
// which would use parameters defined in build.gradle. Use our own
// task (ndkBuild) below.
jni.srcDirs = []
jniLibs.srcDirs = ["bin/lib/"] // default is src/main/jniLibs
manifest.srcFile "AndroidManifest.xml"
res.srcDirs = ["res/"] // default is src/main/res
}
}
// Call regular ndk-build (ndk-build.cmd on Windows) script from
// app directory.
task ndkBuild(type: Exec) {
def ndkDir = project.android.ndkDirectory
def ndkBuildCmd = ""
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
ndkBuildCmd = "ndk-build.cmd"
} else {
ndkBuildCmd = "ndk-build"
}
commandLine "$ndkDir/$ndkBuildCmd", "NDK_GEN_OUT=./bin/gen", "NDK_LIBS_OUT=./bin/lib", "NDK_OUT=./bin/obj"
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.2'
}
|