blob: faeb2ed8e00295d9d5d975ab3e885013c364a00b [file] [log] [blame]
buildscript {
repositories {
mavenCentral()
jcenter()
maven { url 'https://jitpack.io' }
}
dependencies {
classpath (
'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6',
'com.android.tools.build:gradle:2.1.0',
// http://stackoverflow.com/questions/33881984/errorcause-com-android-sdklib-repository-fullrevision
'com.github.JakeWharton:sdk-manager-plugin:220bf7a88a7072df3ed16dc8466fb144f2817070',
'io.v:gradle-plugin:1.7',
'me.tatarka:gradle-retrolambda:3.2.4'
)
}
}
apply plugin: 'android-sdk-manager'
apply plugin: 'com.android.library'
/*
You might have to download JDK8 and set JAVA8_HOME (or set the jdk to Java 8 via Project Structure).
For detailed instructions, see https://github.com/evant/gradle-retrolambda
*/
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.bintray'
apply plugin: 'io.v.vdl'
// You should change this after releasing a new version of the library. See the
// list of published versions at https://repo1.maven.org/maven2/io/v/vanadium-android.
def releaseVersion = '2.2.2'
android {
buildToolsVersion '23.0.1'
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
compileSdkVersion 23
defaultConfig {
minSdkVersion 21
}
lintOptions {
abortOnError false
}
defaultConfig {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
}
repositories {
mavenCentral()
}
dependencies {
// https://projectlombok.org/setup/android.html
// Follow Android Studio instructions at the bottom of the page to install the Lombok Plugin.
provided 'org.projectlombok:lombok:1.16.8'
compile project(':lib')
compile (
'com.android.support:support-v4:23.3.0',
'com.android.support:appcompat-v7:23.3.0',
'com.google.android.gms:play-services:8.4.0',
'io.reactivex:rxandroid:1.1.0',
'io.reactivex:rxjava:1.1.3',
'net.sourceforge.streamsupport:streamsupport:1.4.3'
)
testCompile 'com.google.truth:truth:0.28'
androidTestCompile 'junit:junit:4.12'
androidTestCompile('com.android.support.test:runner:0.3') {
exclude group: 'junit' // junit:junit-dep conflicts with junit:unit
}
}
def jiriRoot = VanadiumEnvironment.getVanadiumEnvironment().jiriRoot.getAbsolutePath()
vdl {
inputPaths += 'src/main/java'
vdlToolPath = 'vdl'
if (exec() {
commandLine "which", vdlToolPath
ignoreExitValue true
}.getExitValue() != 0) {
// If vdl is not found in the path, use the one in $JIRI_ROOT.
vdlToolPath = [jiriRoot, '.jiri_root', 'bin', 'vdl'].join(File.separator)
}
}
public static isDarwin() {
return getOS().contains("os x")
}
public static isLinux() {
return getOS().contains("linux")
}
public static isAmd64() {
return getArch().contains("x86_64") || getArch().contains("amd64")
}
public static getArch() {
return System.properties['os.arch'].toLowerCase()
}
public static getOS() {
return System.properties['os.name'].toLowerCase()
}
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
}
}
enum VanadiumSupportedArchitecture {
X86_64('x86_64', 'amd64'),
ARM_V7A('armeabi-v7a', 'arm');
public final String abiName
public final String goArch
private VanadiumSupportedArchitecture(String abiName, String goArch) {
this.abiName = abiName
this.goArch = goArch
}
}
// Returns a task that will build the Vanadium native library for the given architecture.
def buildVanadiumLib(VanadiumSupportedArchitecture arch) {
def jiriRoot = VanadiumEnvironment.getVanadiumEnvironment().jiriRoot.getAbsolutePath()
def check = task("checkVanadiumAndroidEnvironment-${arch.goArch}", type: Exec) {
commandLine 'jiri', 'profile', 'list',
'--info', 'Target.InstallationDir', "--target=${arch.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. "
+ "You probably didn't install the android base profile. Try running\n\n"
+ "jiri profile install "
+ "--target=${arch.goArch}-android v23:android\n\n"
+ "and then try building again"
)
}
}
}
def goBuild = task("goBuildVanadiumLib-${arch.goArch}", type: Exec, dependsOn: check) {
// NOTE(spetrovic): we add the '-installsuffix=' flag as a safe measure, because the build
// without it doesn't work on linux/arm. (It does work on android/arm, but we are playing it
// safe here.)
environment "GOOS", "android"
environment "GOARCH", "${arch.goArch}"
commandLine 'jiri', 'go', "--target=${arch.goArch}-android", 'install',
'-buildmode=c-shared', '-v', '-tags', 'android',
'-installsuffix=shared', 'v.io/x/jni/main'
}
// Copy the shared library to its ultimate destination.
def copyLib = task("copyVanadiumLib-${arch.goArch}", type: Copy, dependsOn: goBuild) {
from jiriRoot + "/release/go/pkg/android_${arch.goArch}_shared_shared/v.io/x/jni"
into "src/main/jniLibs/${arch.abiName}"
include 'main.a'
rename 'main.a', 'libv23.so'
}
tasks.preBuild.dependsOn(copyLib)
}
VanadiumSupportedArchitecture.values().each { arch ->
buildVanadiumLib(arch)
}
clean {
VanadiumSupportedArchitecture.values().each() { arch ->
delete "src/main/jniLibs/${arch.abiName}/libv23.so"
}
}
task sourceJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier "sources"
}
// Adds XML nodes representing fields required for publication to Maven central to the given node.
def addMavenCentralMetadata(Node node) {
node.appendNode('name', 'Vanadium Android library')
node.appendNode('description',
'Java libraries for writing Vanadium Android applications')
node.appendNode('url', 'https://github.com/vanadium/java/tree/master/android-lib')
def license = node.appendNode('licenses').appendNode('license')
license.appendNode('name', 'New BSD License')
license.appendNode('url', 'https://github.com/vanadium/java/blob/master/LICENSE')
license.appendNode('distribution', 'repo')
node.appendNode('scm').appendNode('url',
'https://github.com/vanadium/java.git')
def developerInfo = node.appendNode('developers').appendNode('developer')
developerInfo.appendNode('id', 'vanadium')
developerInfo.appendNode('name', 'The Vanadium Contributors')
developerInfo.appendNode('email', 'vanadium-discuss@v.io')
}
def pomDependencyText = """
<dependencies>
<dependency>
<groupId>io.v</groupId>
<artifactId>vanadium-without-natives</artifactId>
<version>${releaseVersion}</version>
</dependency>
</dependencies>
"""
def pomDependencies = new XmlParser().parseText(pomDependencyText)
// Add compile time dependencies to the list.
configurations.compile.allDependencies.withType(ExternalDependency).each {
def dependencyNode = pomDependencies.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
publishing {
publications {
androidLibrary(MavenPublication) {
groupId 'io.v'
artifactId 'vanadium-android'
version releaseVersion
artifact sourceJar
artifact "$buildDir/outputs/aar/android-lib-release.aar"
pom.withXml {
addMavenCentralMetadata(asNode())
asNode().append(pomDependencies)
}
}
}
}
tasks.publishToMavenLocal.dependsOn(tasks.assemble)
tasks.bintrayUpload.dependsOn(tasks.assemble)
bintray {
user = project.properties.bintrayUsername
key = project.properties.bintrayApiKey
pkg {
desc = 'Java libraries for writing Vanadium Android applications'
websiteUrl = 'https://github.com/vanadium/java'
repo = 'io.v'
name = 'vanadium-android'
licenses = ['BSD New']
vcsUrl = 'https://github.com/vanadium/java.git'
version {
name = releaseVersion
gpg {
sign = true
}
}
userOrg = 'vanadium'
}
publications = ['androidLibrary']
}