adding a 'publishAndroid' task to generate the AAR with prebuilt .so files

This commit is contained in:
Nabil Hachicha 2016-02-10 02:03:33 +00:00 committed by Scott Kyle
parent 918b140030
commit 7afdbba2ed
27 changed files with 265 additions and 241 deletions

2
.gitignore vendored
View File

@ -99,7 +99,7 @@ node_modules/
npm-debug.log
# Android/IJ
#
/android/
.idea
.gradle
local.properties

View File

@ -74,5 +74,5 @@ android {
dependencies {
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.facebook.react:react-native:0.18.0-patched'
compile 'io.realm.react:realm-react-native:0.0.1-SNAPSHOT'
compile project(':realm')
}

View File

@ -1,3 +1,6 @@
rootProject.name = 'ReactExample'
include ':app'
include ':realm'
project(':realm').projectDir = new File(rootProject.projectDir, '../node_modules/realm/android')

View File

@ -4,6 +4,7 @@
"private": true,
"main": "lib/index.js",
"files": [
"android",
"lib",
"react-native",
"scripts",
@ -12,7 +13,7 @@
"RealmJS.xcodeproj"
],
"scripts": {
"postinstall": "scripts/create-symlinks.sh",
"test": "scripts/test.sh"
"test": "scripts/test.sh",
"prepublish": "rm -rf android && cd react-native/android && ./gradlew publishAndroid"
}
}

View File

@ -1,4 +1,4 @@
app/build/
build/
.idea
.gradle

View File

@ -1,175 +0,0 @@
// Copyright 2015-present Facebook. All Rights Reserved.
apply plugin: 'com.android.library'
apply plugin: 'maven'
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.
def downloadsDir = new File("$buildDir/downloads")
def jscDownloadDir = new File("$projectDir/src/main/jni/jsc")
def coreDownloadDir = new File("$projectDir/src/main/jni")
ext.coreVersion = '0.95.6'
def thirdPartyNdkDir = new File("$buildDir/third-party-ndk")
task createNativeDepsDirectories {
downloadsDir.mkdirs()
thirdPartyNdkDir.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) {
src "http://static.realm.io/downloads/core/realm-core-android-${project.coreVersion}.tar.gz"
onlyIfNewer true
overwrite false
dest new File(downloadsDir, "realm-core-android-${project.coreVersion}.tar.gz")
}
task prepareRealmCore(dependsOn: downloadRealmCore, type:Copy) {
from tarTree(downloadRealmCore.dest)
into "$coreDownloadDir/core"
//Fixing Core file naming 'arm-*' to 'armeabi-*'
doLast {
exec {
workingDir = "$coreDownloadDir/core"
commandLine = [
"bash",
"-c",
"find . -name \"*-arm-*\" -exec sh -c \"echo {} | sed -e s/arm/armeabi/g | xargs mv {} \" \\;"
]
}
}
}
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')
outputs.dir("$buildDir/react-ndk/all")
commandLine getNdkBuildFullPath(),
'NDK_PROJECT_PATH=null',
"NDK_APPLICATION_MK=$projectDir/src/main/jni/Application.mk",
'NDK_OUT=' + temporaryDir,
"NDK_LIBS_OUT=$buildDir/react-ndk/all",
"THIRD_PARTY_NDK_DIR=$buildDir/third-party-ndk",
'-C', file('src/main/jni').absolutePath,
'NDK_LOG=1',
'NDK_DEBUG=1',
'--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) {
from "$buildDir/react-ndk/all"
exclude '**/libjsc.so'
into "$buildDir/react-ndk/exported"
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
sourceSets.main {
jni.srcDirs = []
jniLibs.srcDir "$buildDir/react-ndk/exported"
res.srcDirs = ['src/main/res/devsupport', 'src/main/res/shell']
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn packageReactNdkLibs
}
clean.dependsOn cleanReactNdkLib
lintOptions {
abortOnError false
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'org.nanohttpd:nanohttpd:2.2.0'
compile 'com.facebook.react:react-native:0.18.0-patched'
}
apply from: 'release.gradle'

View File

@ -1,14 +0,0 @@
VERSION_NAME=0.0.1-SNAPSHOT
GROUP=io.realm.react
POM_NAME=RealmReactAndroid
POM_ARTIFACT_ID=realm-react-native
POM_PACKAGING=aar
android.useDeprecatedNdk=true
MOCKITO_CORE_VERSION=1.+
POWERMOCK_VERSION=1.6.2
ROBOLECTRIC_VERSION=3.0
JUNIT_VERSION=4.12
FEST_ASSERT_CORE_VERSION=2.0M10

View File

@ -1 +0,0 @@
../../../../../../src

View File

@ -1 +0,0 @@
../../../../../../vendor

View File

@ -1,7 +1,4 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
apply plugin: "java"
// Copyright 2015-present Facebook. All Rights Reserved.
buildscript {
repositories {
jcenter()
@ -21,3 +18,211 @@ allprojects {
jcenter()
}
}
apply plugin: 'com.android.library'
apply plugin: 'maven'
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.
def downloadsDir = new File("$buildDir/downloads")
def jscDownloadDir = new File("$projectDir/src/main/jni/jsc")
def coreDownloadDir = new File("$projectDir/src/main/jni")
ext.coreVersion = '0.95.6'
def thirdPartyNdkDir = new File("$buildDir/third-party-ndk")
def publishDir = new File("$projectDir/../../android/")
task publishAndroid(dependsOn: assembleDebug, type: Copy) {
// Copy task can only have one top level
into "$publishDir"
// copy java source
into ('/src/main') {
from "$projectDir/src/main"
exclude '**/jni/**'
}
// add compiled shared object
into ('/src/main/jniLibs') {
from "$buildDir/intermediates/bundles/debug/jni/"
}
// 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'
}
}
// Use a closure to map the file name
}
task createNativeDepsDirectories {
downloadsDir.mkdirs()
thirdPartyNdkDir.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) {
src "http://static.realm.io/downloads/core/realm-core-android-${project.coreVersion}.tar.gz"
onlyIfNewer true
overwrite false
dest new File(downloadsDir, "realm-core-android-${project.coreVersion}.tar.gz")
}
task prepareRealmCore(dependsOn: downloadRealmCore, type:Copy) {
from tarTree(downloadRealmCore.dest)
into "$coreDownloadDir/core"
//Fixing Core file naming 'arm-*' to 'armeabi-*'
doLast {
exec {
workingDir = "$coreDownloadDir/core"
commandLine = [
"bash",
"-c",
"find . -name \"*-arm-*\" -exec sh -c \"echo {} | sed -e s/arm/armeabi/g | xargs mv {} \" \\;"
]
}
}
}
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')
outputs.dir("$buildDir/react-ndk/all")
commandLine getNdkBuildFullPath(),
'NDK_PROJECT_PATH=null',
"NDK_APPLICATION_MK=$projectDir/src/main/jni/Application.mk",
'NDK_OUT=' + temporaryDir,
"NDK_LIBS_OUT=$buildDir/react-ndk/all",
"THIRD_PARTY_NDK_DIR=$buildDir/third-party-ndk",
'-C', file('src/main/jni').absolutePath,
'NDK_LOG=1',
'NDK_DEBUG=1',
'--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) {
from "$buildDir/react-ndk/all"
exclude '**/libjsc.so'
into "$buildDir/react-ndk/exported"
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
sourceSets.main {
jni.srcDirs = []
jniLibs.srcDir "$buildDir/react-ndk/exported"
res.srcDirs = ['src/main/res/devsupport', 'src/main/res/shell']
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn packageReactNdkLibs
}
clean.dependsOn cleanReactNdkLib
lintOptions {
abortOnError false
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'org.nanohttpd:nanohttpd:2.2.0'
compile 'com.facebook.react:react-native:0.18.0-patched'
}
apply from: 'release.gradle'

View File

@ -1,22 +1,14 @@
# Project-wide Gradle settings.
VERSION_NAME=0.0.1-SNAPSHOT
GROUP=io.realm.react
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
POM_NAME=RealmReactAndroid
POM_ARTIFACT_ID=realm-react-native
POM_PACKAGING=aar
android.useDeprecatedNdk=true
org.gradle.daemon=true
MOCKITO_CORE_VERSION=1.+
POWERMOCK_VERSION=1.6.2
ROBOLECTRIC_VERSION=3.0
JUNIT_VERSION=4.12
FEST_ASSERT_CORE_VERSION=2.0M10

View File

@ -1,5 +1,6 @@
#Wed Feb 10 01:35:36 GMT 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-bin.zip

View File

@ -0,0 +1,33 @@
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
}
}
allprojects {
repositories {
mavenLocal()
jcenter()
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
minSdkVersion 16
targetSdkVersion 22
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'org.nanohttpd:nanohttpd:2.2.0'
compile 'com.facebook.react:react-native:0.18.0-patched'
}

View File

@ -1,4 +0,0 @@
rootProject.name = 'RealmReactNative'
include ':app'
include ':react-native'

View File

@ -0,0 +1 @@
../../../../../src/

View File

@ -0,0 +1 @@
../../../../../vendor

Binary file not shown.

View File

@ -1,18 +0,0 @@
#!/bin/bash
set -e
set -o pipefail
symlink() {
[ -e "$(basename "$1")" ] || ln -s "$1"
}
cd "$(dirname "$0")/.."
# A top-level "android" directory is expected by `react-native link`
symlink react-native/android
# NPM doesn't support publishing symlinks, so these must be re-created
cd react-native/android/app/src/main/jni
symlink ../../../../../../src
symlink ../../../../../../vendor

0
tests/react-test-app/android/app/gradlew vendored Normal file → Executable file
View File