blob: ec0a3fdaf6f6c037bad34f46a30182ff99497388 [file] [log] [blame]
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
}
}
allprojects {
repositories {
jcenter()
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
minSdkVersion 21
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'io.v:vanadium-android:2.1.4'
testCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support.test:runner:0.4.1'
androidTestCompile 'com.android.support.test:rules:0.4.1'
}
task clean(type: Delete) {
delete rootProject.buildDir
delete "src/main/jniLibs/"
}
class VanadiumEnvironment {
File jiriRoot;
public static getVanadiumEnvironment() {
VanadiumEnvironment result = new VanadiumEnvironment()
if (!System.getenv().containsKey('JIRI_ROOT')) {
throw new InvalidUserDataException("JIRI_ROOT is not set. "
+ "Please follow the Vanadium installation instructions at "
+ "https://vanadium.github.io/installation/")
}
result.jiriRoot = new File(System.getenv()['JIRI_ROOT'])
return result
}
}
def addSyncbaseLib(Map args) {
def abiName = args.abiName
def goArch = args.goArch
def jiriRoot = ""
try {
jiriRoot = VanadiumEnvironment.getVanadiumEnvironment().jiriRoot.getAbsolutePath()
} catch (InvalidUserDataException e) {
return
}
def check = task("checkVanadiumAndroidEnvironment-${goArch}", type: Exec) {
commandLine 'jiri', 'profile', 'list',
'--info=Target.InstallationDir',
"--target=${goArch}-android", 'v23:android'
standardOutput = new ByteArrayOutputStream()
doLast {
def androidOutputDir = new File(standardOutput.toString().trim())
if (!androidOutputDir.exists() || !androidOutputDir.isDirectory()) {
throw new InvalidUserDataException(
androidOutputDir.toString() + " does not exist or is not a directory. "
+ "The android base profile is probably missing. Try running\n\n"
+ "jiri profile install --target=${goArch}-android v23:android\n\n"
+ "and then building again."
)
}
}
}
def goBuild = task("buildSyncbaseLib-${goArch}", type: Exec, dependsOn: check) {
environment 'GOOS', 'android'
environment 'GOARCH', goArch
commandLine 'jiri', 'go', "--target=${goArch}-android", 'install',
'-buildmode=c-shared', '-v', '-tags', 'android',
'v.io/x/ref/services/syncbase/bridge/cgo'
}
// Copy the shared library to its ultimate destination.
def copyLib = task("copySyncbaseLib-${goArch}", type: Copy, dependsOn: goBuild) {
from jiriRoot + "/release/go/pkg/android_${goArch}_shared/v.io/x/ref/services/syncbase/bridge/"
into "src/main/jniLibs/${abiName}"
include 'cgo.a'
rename 'cgo.a', 'libsyncbase.so'
}
tasks.copySyncbaseLib.dependsOn(copyLib)
}
task(copySyncbaseLib)
addSyncbaseLib abiName: 'x86_64', goArch: 'amd64'
addSyncbaseLib abiName: 'armeabi-v7a', goArch: 'arm'