blob: 6eac8e0ece07c34dd5f4ce735695d6761b47be38 [file] [log] [blame]
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.0'
classpath 'io.v:gradle-plugin:1.4'
}
}
apply plugin: 'android-sdk-manager'
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
apply plugin: 'wrapper'
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 = '1.5'
android {
buildToolsVersion '23.0.1'
compileSdkVersion 23
defaultConfig {
minSdkVersion 21
}
lintOptions {
abortOnError false
}
defaultConfig {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
}
repositories {
mavenCentral()
}
dependencies {
compile project(':lib')
compile 'com.android.support:support-v4:23.0.1'
compile 'com.android.support:appcompat-v7:23.0.1'
androidTestCompile 'junit:junit:4.12'
androidTestCompile 'com.google.truth:truth:0.25'
// This dependency exists only to work around an issue in the sdkmanager plugin v0.12.0. This
// should be fixed when http://git.io/vIXec is checked in and a release is made.
androidTestCompile 'com.android.support:appcompat-v7:23.0.1'
androidTestCompile('com.android.support.test:runner:0.3') {
exclude group: 'junit' // junit:junit-dep conflicts with junit:unit
}
}
vdl {
inputPaths += 'src/main/java'
}
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;
File jiriBin;
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'])
result.jiriBin = new File(result.jiriRoot, ['devtools', 'bin', 'jiri'].join(File.separator))
if (!result.jiriBin.exists() || !result.jiriBin.isFile() || !result.jiriBin.canExecute()) {
throw new InvalidUserDataException(
result.jiriBin.toString() + " does not exist or is not an executable file. "
+ "Please follow the Vanadium installation instructions at "
+ "https://vanadium.github.io/installation/")
}
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 jiriBin = VanadiumEnvironment.getVanadiumEnvironment().jiriBin.getAbsolutePath()
def check = task("checkVanadiumAndroidEnvironment-${arch.goArch}", type: Exec) {
commandLine jiriBin, 'v23-profile', 'list',
'--info', 'Target.InstallationDir', "--target=${arch.goArch}-android", '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 v23-profile install "
+ "--target=${arch.goArch}-android 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 jiriBin, '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)
}
}
}
}
wrapper {
gradleVersion = '2.4'
}
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']
}