2015-12-10 02:47:50 +00:00
|
|
|
buildscript {
|
|
|
|
repositories {
|
|
|
|
jcenter()
|
|
|
|
}
|
|
|
|
dependencies {
|
|
|
|
classpath 'com.android.tools.build:gradle:1.3.1'
|
2015-12-10 22:12:45 +00:00
|
|
|
classpath 'de.undercouch:gradle-download-task:1.2'
|
2015-12-10 02:47:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
allprojects {
|
|
|
|
repositories {
|
|
|
|
mavenLocal()
|
|
|
|
jcenter()
|
2016-03-10 23:16:31 +00:00
|
|
|
maven {
|
|
|
|
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
|
|
|
|
url "$projectDir/../../tests/react-test-app/node_modules/react-native/android"
|
|
|
|
}
|
2015-12-10 02:47:50 +00:00
|
|
|
}
|
|
|
|
}
|
2016-02-10 02:03:33 +00:00
|
|
|
|
|
|
|
apply plugin: 'com.android.library'
|
|
|
|
apply plugin: 'maven'
|
2016-02-11 15:42:10 +00:00
|
|
|
apply plugin: 'signing'
|
2016-02-10 02:03:33 +00:00
|
|
|
apply plugin: 'de.undercouch.download'
|
|
|
|
|
|
|
|
import de.undercouch.gradle.tasks.download.Download
|
|
|
|
import org.apache.tools.ant.taskdefs.condition.Os
|
|
|
|
import org.apache.tools.ant.filters.ReplaceTokens
|
|
|
|
|
|
|
|
// We download various C++ open-source dependencies into downloads.
|
|
|
|
// We then copy both the downloaded code and our custom makefiles and headers into third-party-ndk.
|
|
|
|
// After that we build native code from src/main/jni with module path pointing at third-party-ndk.
|
|
|
|
|
2017-04-20 20:58:16 +00:00
|
|
|
|
2017-04-19 04:28:42 +00:00
|
|
|
ext.coreVersion = getDependenciesVersion("REALM_CORE_VERSION").trim()
|
|
|
|
ext.syncVersion = getDependenciesVersion("REALM_SYNC_VERSION").trim()
|
|
|
|
def currentVersion = getDependenciesVersion("VERSION").trim()
|
2017-04-03 20:33:12 +00:00
|
|
|
println "Realm Core Version: $ext.coreVersion"
|
|
|
|
println "Realm Sync Version: $ext.syncVersion"
|
|
|
|
|
2016-02-11 15:42:10 +00:00
|
|
|
def downloadsDir = new File("$projectDir/downloads")
|
2016-02-10 02:03:33 +00:00
|
|
|
def jscDownloadDir = new File("$projectDir/src/main/jni/jsc")
|
|
|
|
def coreDownloadDir = new File("$projectDir/src/main/jni")
|
|
|
|
def publishDir = new File("$projectDir/../../android/")
|
2016-11-14 13:26:33 +00:00
|
|
|
// to build with sync run: ./gradlew assembleDebug -PbuildWithSync=true
|
2017-03-17 14:37:35 +00:00
|
|
|
ext.buildSync = project.hasProperty('buildWithSync') ? project.getProperty('buildWithSync').toBoolean() : true
|
2016-02-10 02:03:33 +00:00
|
|
|
|
2016-02-17 06:29:39 +00:00
|
|
|
task generateVersionClass(type: Copy) {
|
|
|
|
from 'src/main/templates/Version.java'
|
|
|
|
into 'build/generated-src/main/java/io/realm/react'
|
|
|
|
filter(ReplaceTokens, tokens: [version: currentVersion])
|
|
|
|
outputs.upToDateWhen { false }
|
|
|
|
}
|
|
|
|
|
2016-02-10 02:03:33 +00:00
|
|
|
task createNativeDepsDirectories {
|
|
|
|
downloadsDir.mkdirs()
|
|
|
|
}
|
|
|
|
|
|
|
|
task downloadJSCHeaders(type: Download) {
|
|
|
|
def jscAPIBaseURL = 'https://svn.webkit.org/repository/webkit/!svn/bc/174650/trunk/Source/JavaScriptCore/API/'
|
|
|
|
def jscHeaderFiles = ['JSBase.h', 'JSContextRef.h', 'JSObjectRef.h', 'JSRetainPtr.h', 'JSStringRef.h', 'JSValueRef.h', 'WebKitAvailability.h']
|
|
|
|
|
|
|
|
def output = new File(jscDownloadDir, 'JavaScriptCore')
|
|
|
|
output.mkdirs()
|
|
|
|
src(jscHeaderFiles.collect { headerName -> "$jscAPIBaseURL$headerName" })
|
|
|
|
onlyIfNewer true
|
|
|
|
overwrite false
|
|
|
|
dest output
|
|
|
|
}
|
|
|
|
|
|
|
|
task downloadRealmCore(type: Download) {
|
2016-11-14 13:26:33 +00:00
|
|
|
if (project.buildSync) {
|
|
|
|
src "https://static.realm.io/downloads/sync/realm-sync-android-${project.syncVersion}.tar.gz"
|
|
|
|
} else {
|
|
|
|
src "https://static.realm.io/downloads/core/realm-core-android-${project.coreVersion}.tar.gz"
|
|
|
|
}
|
2016-02-10 02:03:33 +00:00
|
|
|
onlyIfNewer true
|
2016-11-14 13:26:33 +00:00
|
|
|
overwrite true
|
|
|
|
if (project.buildSync) {
|
|
|
|
dest new File(downloadsDir, "realm-core-android-${project.syncVersion}.tar.gz")
|
|
|
|
} else {
|
|
|
|
dest new File(downloadsDir, "realm-core-android-${project.coreVersion}.tar.gz")
|
|
|
|
}
|
2016-02-10 02:03:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
task prepareRealmCore(dependsOn: downloadRealmCore, type:Copy) {
|
|
|
|
from tarTree(downloadRealmCore.dest)
|
|
|
|
into "$coreDownloadDir/core"
|
2017-03-10 19:37:42 +00:00
|
|
|
rename { String fileName ->
|
|
|
|
fileName.replace("-arm-", "-armeabi-")
|
2016-02-10 02:03:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 04:31:22 +00:00
|
|
|
def getDependenciesVersion(keyName) {
|
|
|
|
def inputFile = new File(buildscript.sourceFile.getParent() + "/../../dependencies.list")
|
|
|
|
def line
|
|
|
|
inputFile.withReader { reader ->
|
|
|
|
while ((line = reader.readLine())!=null) {
|
|
|
|
def (key, value) = line.tokenize('=')
|
|
|
|
if (keyName == key) {
|
|
|
|
return value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new GradleException("${keyName} not found in dependencies.list.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-10 02:03:33 +00:00
|
|
|
def getNdkBuildName() {
|
|
|
|
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
|
|
|
|
return "ndk-build.cmd"
|
|
|
|
} else {
|
|
|
|
return "ndk-build"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def findNdkBuildFullPath() {
|
|
|
|
// we allow to provide full path to ndk-build tool
|
|
|
|
if (hasProperty('ndk.command')) {
|
|
|
|
return property('ndk.command')
|
|
|
|
}
|
|
|
|
// or just a path to the containing directory
|
|
|
|
if (hasProperty('ndk.path')) {
|
|
|
|
def ndkDir = property('ndk.path')
|
|
|
|
return new File(ndkDir, getNdkBuildName()).getAbsolutePath()
|
|
|
|
}
|
|
|
|
if (System.getenv('ANDROID_NDK') != null) {
|
|
|
|
def ndkDir = System.getenv('ANDROID_NDK')
|
|
|
|
return new File(ndkDir, getNdkBuildName()).getAbsolutePath()
|
|
|
|
}
|
|
|
|
def ndkDir = android.hasProperty('plugin') ? android.plugin.ndkFolder :
|
|
|
|
plugins.getPlugin('com.android.library').sdkHandler.getNdkFolder()
|
|
|
|
if (ndkDir) {
|
|
|
|
return new File(ndkDir, getNdkBuildName()).getAbsolutePath()
|
|
|
|
}
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
def getNdkBuildFullPath() {
|
|
|
|
def ndkBuildFullPath = findNdkBuildFullPath()
|
|
|
|
if (ndkBuildFullPath == null) {
|
|
|
|
throw new GradleScriptException(
|
|
|
|
"ndk-build binary cannot be found, check if you've set " +
|
|
|
|
"\$ANDROID_NDK environment variable correctly or if ndk.dir is " +
|
|
|
|
"setup in local.properties",
|
|
|
|
null)
|
|
|
|
}
|
|
|
|
if (!new File(ndkBuildFullPath).canExecute()) {
|
|
|
|
throw new GradleScriptException(
|
|
|
|
"ndk-build binary " + ndkBuildFullPath + " doesn't exist or isn't executable.\n" +
|
|
|
|
"Check that the \$ANDROID_NDK environment variable, or ndk.dir in local.proerties, is set correctly.\n" +
|
|
|
|
"(On Windows, make sure you escape backslashes in local.properties or use forward slashes, e.g. C:\\\\ndk or C:/ndk rather than C:\\ndk)",
|
|
|
|
null)
|
|
|
|
}
|
|
|
|
return ndkBuildFullPath
|
|
|
|
}
|
|
|
|
|
|
|
|
task buildReactNdkLib(dependsOn: [downloadJSCHeaders,prepareRealmCore], type: Exec) {
|
|
|
|
inputs.file('src/main/jni')
|
2016-02-11 15:42:10 +00:00
|
|
|
outputs.dir("$buildDir/realm-react-ndk/all")
|
2016-02-10 02:03:33 +00:00
|
|
|
commandLine getNdkBuildFullPath(),
|
2016-11-14 13:26:33 +00:00
|
|
|
'-e',
|
|
|
|
project.buildSync ? 'BUILD_TYPE_SYNC=1' : 'BUILD_TYPE_SYNC=0',
|
2016-02-10 02:03:33 +00:00
|
|
|
'NDK_PROJECT_PATH=null',
|
|
|
|
"NDK_APPLICATION_MK=$projectDir/src/main/jni/Application.mk",
|
|
|
|
'NDK_OUT=' + temporaryDir,
|
2016-02-11 15:42:10 +00:00
|
|
|
"NDK_LIBS_OUT=$buildDir/realm-react-ndk/all",
|
2016-02-10 02:03:33 +00:00
|
|
|
'-C', file('src/main/jni').absolutePath,
|
|
|
|
'NDK_LOG=1',
|
2016-02-11 15:42:10 +00:00
|
|
|
'NDK_DEBUG=' + (DEBUG_BUILD.toBoolean() ? '1' : '0'),
|
2016-02-10 02:03:33 +00:00
|
|
|
'--jobs', Runtime.runtime.availableProcessors(),
|
|
|
|
'V=1'
|
|
|
|
}
|
|
|
|
|
|
|
|
task cleanReactNdkLib(type: Exec) {
|
|
|
|
commandLine getNdkBuildFullPath(),
|
|
|
|
'-C', file('src/main/jni').absolutePath,
|
|
|
|
'clean'
|
|
|
|
}
|
|
|
|
|
|
|
|
task packageReactNdkLibs(dependsOn: buildReactNdkLib, type: Copy) {
|
2016-02-11 15:42:10 +00:00
|
|
|
from "$buildDir/realm-react-ndk/all"
|
2016-02-10 02:03:33 +00:00
|
|
|
exclude '**/libjsc.so'
|
2016-02-11 15:42:10 +00:00
|
|
|
exclude '**/gdbserver'
|
|
|
|
exclude '**/gdb.setup'
|
|
|
|
into "$buildDir/realm-react-ndk/exported"
|
2016-02-10 02:03:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
android {
|
|
|
|
compileSdkVersion 23
|
|
|
|
buildToolsVersion "23.0.1"
|
|
|
|
|
|
|
|
defaultConfig {
|
|
|
|
minSdkVersion 16
|
2016-02-11 15:42:10 +00:00
|
|
|
targetSdkVersion 23
|
2016-02-10 02:03:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sourceSets.main {
|
2016-02-17 06:29:39 +00:00
|
|
|
java.srcDir "$buildDir/generated-src/main/java"
|
2016-02-10 02:03:33 +00:00
|
|
|
jni.srcDirs = []
|
2016-02-11 15:42:10 +00:00
|
|
|
jniLibs.srcDir "$buildDir/realm-react-ndk/exported"
|
2016-02-10 02:03:33 +00:00
|
|
|
res.srcDirs = ['src/main/res/devsupport', 'src/main/res/shell']
|
|
|
|
}
|
|
|
|
|
|
|
|
tasks.withType(JavaCompile) {
|
2016-02-17 06:29:39 +00:00
|
|
|
compileTask -> compileTask.dependsOn generateVersionClass, packageReactNdkLibs
|
2016-02-10 02:03:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
clean.dependsOn cleanReactNdkLib
|
|
|
|
|
|
|
|
lintOptions {
|
|
|
|
abortOnError false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-17 06:29:39 +00:00
|
|
|
task publishAndroid(dependsOn: [generateVersionClass, packageReactNdkLibs], type: Sync) {
|
2016-02-11 15:42:10 +00:00
|
|
|
// Copy task can only have one top level
|
|
|
|
into "$publishDir"
|
|
|
|
|
|
|
|
// copy java source
|
|
|
|
into ('/src/main') {
|
2016-02-17 06:29:39 +00:00
|
|
|
from "$projectDir/src/main", "$buildDir/generated-src/main"
|
|
|
|
exclude '**/jni/**', '**/templates/**'
|
2016-02-11 15:42:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// add compiled shared object
|
|
|
|
into ('/src/main/jniLibs') {
|
|
|
|
from "$buildDir/realm-react-ndk/exported/"
|
|
|
|
}
|
|
|
|
|
|
|
|
// copy gradle wrapper files
|
|
|
|
FileTree gradleWrapper = fileTree(projectDir).include('gradlew*').include('gradle/**')
|
|
|
|
into ('/') {
|
|
|
|
from gradleWrapper
|
|
|
|
}
|
|
|
|
|
|
|
|
// copy and rename template build.gradle
|
|
|
|
into ('/') {
|
|
|
|
from "$projectDir/publish_android_template"
|
|
|
|
rename { String fileName ->
|
|
|
|
'build.gradle'
|
|
|
|
}
|
2016-06-30 12:26:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// copy analytics script
|
|
|
|
into ('/') {
|
|
|
|
from "$projectDir/analytics_template"
|
|
|
|
rename { String fileName ->
|
|
|
|
'analytics.gradle'
|
|
|
|
}
|
2016-02-11 15:42:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// publishing into maven local
|
|
|
|
|
|
|
|
def configureRealmReactNativePom(def pom) {
|
|
|
|
pom.project {
|
|
|
|
name POM_NAME
|
|
|
|
artifactId POM_ARTIFACT_ID
|
|
|
|
packaging POM_PACKAGING
|
|
|
|
description POM_DESCRIPTION
|
|
|
|
url 'https://github.com/realm/realm-js'
|
|
|
|
|
|
|
|
issueManagement {
|
|
|
|
system 'github'
|
|
|
|
url 'https://github.com/realm/realm-js/issues'
|
|
|
|
}
|
|
|
|
|
|
|
|
scm {
|
|
|
|
url 'scm:https://github.com/realm/realm-js'
|
|
|
|
connection 'scm:git@github.com:realm/realm-js.git'
|
|
|
|
developerConnection 'scm:git@github.com:realm/realm-js.git'
|
|
|
|
}
|
|
|
|
|
|
|
|
licenses {
|
|
|
|
license {
|
|
|
|
name 'The Apache Software License, Version 2.0'
|
|
|
|
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
|
|
|
|
distribution 'repo'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
afterEvaluate { project ->
|
|
|
|
task androidSourcesJar(type: Jar) {
|
|
|
|
classifier = 'sources'
|
|
|
|
from android.sourceSets.main.java.srcDirs
|
|
|
|
include '**/*.java'
|
|
|
|
}
|
|
|
|
|
|
|
|
android.libraryVariants.all { variant ->
|
|
|
|
def name = variant.name.capitalize()
|
|
|
|
task "jar${name}"(type: Jar, dependsOn: variant.javaCompile) {
|
|
|
|
from variant.javaCompile.destinationDir
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
artifacts {
|
|
|
|
archives androidSourcesJar
|
|
|
|
}
|
|
|
|
|
2016-02-17 06:29:39 +00:00
|
|
|
version = currentVersion
|
2016-02-11 15:42:10 +00:00
|
|
|
group = GROUP
|
|
|
|
|
|
|
|
signing {
|
|
|
|
required { false }
|
|
|
|
sign configurations.archives
|
|
|
|
}
|
|
|
|
|
|
|
|
task installArchives(type: Upload) {
|
|
|
|
configuration = configurations.archives
|
|
|
|
repositories.mavenDeployer {
|
|
|
|
beforeDeployment {
|
|
|
|
MavenDeployment deployment -> signing.signPom(deployment)
|
|
|
|
}
|
|
|
|
|
|
|
|
repository url: "file://${System.properties['user.home']}/.m2/repository"
|
|
|
|
configureRealmReactNativePom pom
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-10 02:03:33 +00:00
|
|
|
dependencies {
|
|
|
|
compile fileTree(dir: 'libs', include: ['*.jar'])
|
|
|
|
compile 'org.nanohttpd:nanohttpd:2.2.0'
|
2016-03-10 23:16:31 +00:00
|
|
|
compile 'com.facebook.react:react-native:+' // From node_modules
|
2016-02-10 02:03:33 +00:00
|
|
|
}
|