Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 1 addition & 34 deletions android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.9.0)

set (CMAKE_VERBOSE_MAKEFILE ON)
set (CMAKE_CXX_STANDARD 14)
set (CMAKE_CXX_FLAGS "-DFOLLY_NO_CONFIG=1 -DFOLLY_HAVE_CLOCK_GETTIME=1 -DFOLLY_HAVE_MEMRCHR=1 -DFOLLY_USE_LIBCPP=1 -DFOLLY_MOBILE=1 -DON_ANDROID -DONANDROID -DFOR_HERMES=${FOR_HERMES}")
#set (CMAKE_CXX_FLAGS "-DFOLLY_NO_CONFIG=1 -DFOLLY_HAVE_CLOCK_GETTIME=1 -DFOLLY_HAVE_MEMRCHR=1 -DFOLLY_USE_LIBCPP=1 -DFOLLY_MOBILE=1 -DON_ANDROID -DONANDROID -DFOR_HERMES=${FOR_HERMES}")

set (PACKAGE_NAME "react-native-quick-sqlite")
set (BUILD_DIR ${CMAKE_SOURCE_DIR}/build)
Expand Down Expand Up @@ -64,11 +64,6 @@ target_include_directories(
PRIVATE
# --- fbjni ---
"${LIBFBJNI_INCLUDE_DIR}"
# --- Third Party (required by RN) ---
"${BUILD_DIR}/third-party-ndk/boost"
"${BUILD_DIR}/third-party-ndk/double-conversion"
"${BUILD_DIR}/third-party-ndk/folly"
"${BUILD_DIR}/third-party-ndk/glog"
# --- React Native ---
"${NODE_MODULES_DIR}/react-native/React"
"${NODE_MODULES_DIR}/react-native/React/Base"
Expand All @@ -84,38 +79,12 @@ target_include_directories(

file (GLOB LIBRN_DIR "${BUILD_DIR}/react-native-0*/jni/${ANDROID_ABI}")

if(${FOR_HERMES})
file (GLOB LIBHERMES_DIR "${BUILD_DIR}/third-party-ndk/hermes/jni/${ANDROID_ABI}")
# Use Hermes
find_library(
JS_ENGINE_LIB
hermes
PATHS ${LIBHERMES_DIR}
NO_CMAKE_FIND_ROOT_PATH
)
else()
file (GLOB LIBJSC_DIR "${BUILD_DIR}/android-jsc*.aar/jni/${ANDROID_ABI}")
# Use JSC
find_library(
JS_ENGINE_LIB
jscexecutor
PATHS ${LIBRN_DIR}
NO_CMAKE_FIND_ROOT_PATH
)
endif()

find_library(
FBJNI_LIB
fbjni
PATHS ${LIBRN_DIR}
NO_CMAKE_FIND_ROOT_PATH
)
find_library(
FOLLY_JSON_LIB
folly_json
PATHS ${LIBRN_DIR}
NO_CMAKE_FIND_ROOT_PATH
)

find_library(
REACT_NATIVE_JNI_LIB
Expand Down Expand Up @@ -146,9 +115,7 @@ target_link_libraries(
${PACKAGE_NAME}
${LOG_LIB}
${JSI_LIB}
${JS_ENGINE_LIB} # <-- Hermes or JSC
${REACT_NATIVE_JNI_LIB}
${FBJNI_LIB}
${FOLLY_JSON_LIB}
android
)
199 changes: 2 additions & 197 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,6 @@ def reactProperties = new Properties()
file("$nodeModules/react-native/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
def REACT_NATIVE_VERSION = reactProperties.getProperty("VERSION_NAME").split("\\.")[1].toInteger()

def FOR_HERMES = System.getenv("FOR_HERMES") == "True"
rootProject.getSubprojects().forEach({ project ->
if (project.plugins.hasPlugin("com.android.application")) {
FOR_HERMES = project.ext.react.enableHermes
}
})
logger.warn("JSI-WS: Building with ${FOR_HERMES ? "Hermes" : "JSC"}...")

android {

compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
Expand All @@ -74,8 +66,7 @@ android {
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
arguments '-DANDROID_STL=c++_shared',
"-DREACT_NATIVE_VERSION=${REACT_NATIVE_VERSION}",
"-DNODE_MODULES_DIR=${nodeModules}",
"-DFOR_HERMES=${FOR_HERMES}"
"-DNODE_MODULES_DIR=${nodeModules}"
}
}

Expand Down Expand Up @@ -196,197 +187,14 @@ dependencies {
extractJNI(files(rnAAR, jscAAR))
}


// third-party-ndk deps headers
// mostly a copy of https://github.com/software-mansion/react-native-reanimated/blob/master/android/build.gradle#L115

def downloadsDir = new File("$buildDir/downloads")
def thirdPartyNdkDir = new File("$buildDir/third-party-ndk")
def thirdPartyVersionsFile = new File("${nodeModules}/react-native/ReactAndroid/gradle.properties")
def thirdPartyVersions = new Properties()
thirdPartyVersions.load(new FileInputStream(thirdPartyVersionsFile))

def BOOST_VERSION = thirdPartyVersions["BOOST_VERSION"]
def boost_file = new File(downloadsDir, "boost_${BOOST_VERSION}.tar.gz")
def DOUBLE_CONVERSION_VERSION = thirdPartyVersions["DOUBLE_CONVERSION_VERSION"]
def double_conversion_file = new File(downloadsDir, "double-conversion-${DOUBLE_CONVERSION_VERSION}.tar.gz")
def FOLLY_VERSION = thirdPartyVersions["FOLLY_VERSION"]
def folly_file = new File(downloadsDir, "folly-${FOLLY_VERSION}.tar.gz")
def GLOG_VERSION = thirdPartyVersions["GLOG_VERSION"]
def glog_file = new File(downloadsDir, "glog-${GLOG_VERSION}.tar.gz")

task createNativeDepsDirectories {
doLast {
downloadsDir.mkdirs()
thirdPartyNdkDir.mkdirs()
}
}

task downloadBoost(dependsOn: createNativeDepsDirectories, type: Download) {
src("https://github.com/react-native-community/boost-for-react-native/releases/download/v${BOOST_VERSION.replace("_", ".")}-0/boost_${BOOST_VERSION}.tar.gz")
onlyIfNewer(true)
overwrite(false)
dest(boost_file)
}

task prepareBoost(dependsOn: downloadBoost, type: Copy) {
from(tarTree(resources.gzip(downloadBoost.dest)))
from("src/main/jni/third-party/boost/Android.mk")
include("Android.mk", "boost_${BOOST_VERSION}/boost/**/*.hpp", "boost/boost/**/*.hpp")
includeEmptyDirs = false
into("$thirdPartyNdkDir") // /boost_X_XX_X
doLast {
file("$thirdPartyNdkDir/boost_${BOOST_VERSION}").renameTo("$thirdPartyNdkDir/boost")
}
}

task downloadDoubleConversion(dependsOn: createNativeDepsDirectories, type: Download) {
src("https://github.com/google/double-conversion/archive/v${DOUBLE_CONVERSION_VERSION}.tar.gz")
onlyIfNewer(true)
overwrite(false)
dest(double_conversion_file)
}

task prepareDoubleConversion(dependsOn: downloadDoubleConversion, type: Copy) {
from(tarTree(downloadDoubleConversion.dest))
from("src/main/jni/third-party/double-conversion/Android.mk")
include("double-conversion-${DOUBLE_CONVERSION_VERSION}/src/**/*", "Android.mk")
filesMatching("*/src/**/*", { fname -> fname.path = "double-conversion/${fname.name}" })
includeEmptyDirs = false
into("$thirdPartyNdkDir/double-conversion")
}

task downloadFolly(dependsOn: createNativeDepsDirectories, type: Download) {
src("https://github.com/facebook/folly/archive/v${FOLLY_VERSION}.tar.gz")
onlyIfNewer(true)
overwrite(false)
dest(folly_file)
}

task prepareFolly(dependsOn: downloadFolly, type: Copy) {
from(tarTree(downloadFolly.dest))
from("src/main/jni/third-party/folly/Android.mk")
include("folly-${FOLLY_VERSION}/folly/**/*", "Android.mk")
eachFile { fname -> fname.path = (fname.path - "folly-${FOLLY_VERSION}/") }
includeEmptyDirs = false
into("$thirdPartyNdkDir/folly")
}

task downloadGlog(dependsOn: createNativeDepsDirectories, type: Download) {
src("https://github.com/google/glog/archive/v${GLOG_VERSION}.tar.gz")
onlyIfNewer(true)
overwrite(false)
dest(glog_file)
}

task prepareGlog(dependsOn: downloadGlog, type: Copy) {
from(tarTree(downloadGlog.dest))
from("src/main/jni/third-party/glog/")
include("glog-${GLOG_VERSION}/src/**/*", "Android.mk", "config.h")
includeEmptyDirs = false
filesMatching("**/*.h.in") {
filter(ReplaceTokens, tokens: [
ac_cv_have_unistd_h : "1",
ac_cv_have_stdint_h : "1",
ac_cv_have_systypes_h : "1",
ac_cv_have_inttypes_h : "1",
ac_cv_have_libgflags : "0",
ac_google_start_namespace : "namespace google {",
ac_cv_have_uint16_t : "1",
ac_cv_have_u_int16_t : "1",
ac_cv_have___uint16 : "0",
ac_google_end_namespace : "}",
ac_cv_have___builtin_expect : "1",
ac_google_namespace : "google",
ac_cv___attribute___noinline : "__attribute__ ((noinline))",
ac_cv___attribute___noreturn : "__attribute__ ((noreturn))",
ac_cv___attribute___printf_4_5: "__attribute__((__format__ (__printf__, 4, 5)))"
])
it.path = (it.name - ".in")
}
into("$thirdPartyNdkDir/glog")

doLast {
copy {
from(fileTree(dir: "$thirdPartyNdkDir/glog", includes: ["stl_logging.h", "logging.h", "raw_logging.h", "vlog_is_on.h", "**/src/glog/log_severity.h"]).files)
includeEmptyDirs = false
into("$thirdPartyNdkDir/glog/exported/glog")
}
}
}

task prepareThirdPartyNdkHeaders {
if (!boost_file.exists()) {
dependsOn(prepareBoost)
}
if (!double_conversion_file.exists()) {
dependsOn(prepareDoubleConversion)
}
if (!folly_file.exists()) {
dependsOn(prepareFolly)
}
if (!glog_file.exists()) {
dependsOn(prepareGlog)
}
}

prepareThirdPartyNdkHeaders.mustRunAfter createNativeDepsDirectories

task prepareHermes() {
doLast {
def hermesPackagePath = file("${nodeModules}/hermes-engine")
if (!hermesPackagePath.exists()) {
throw new GradleScriptException("Could not find the hermes-engine npm package", null)
}

def hermesAAR = file("$hermesPackagePath/android/hermes-debug.aar")
if (!hermesAAR.exists()) {
throw new GradleScriptException("The hermes-engine npm package is missing \"android/hermes-debug.aar\"", null)
}

def soFiles = zipTree(hermesAAR).matching({ it.include "**/*.so" })

copy {
from soFiles
from "$reactNative/ReactAndroid/src/main/jni/first-party/hermes/Android.mk"
into "$thirdPartyNdkDir/hermes"
}
}
}

prepareHermes.mustRunAfter prepareThirdPartyNdkHeaders

task prepareJSC {
doLast {
def jscPackagePath = file("${nodeModules}/jsc-android")
if (!jscPackagePath.exists()) {
throw new GradleScriptException("Could not find the jsc-android npm package", null)
}

def jscDist = file("$jscPackagePath/dist")
if (!jscDist.exists()) {
throw new GradleScriptException("The jsc-android npm package is missing its \"dist\" directory", null)
}

def jscAAR = fileTree(jscDist).matching({ it.include "**/android-jsc/**/*.aar" }).singleFile
def soFiles = zipTree(jscAAR).matching({ it.include "**/*.so" })

def headerFiles = fileTree(jscDist).matching({ it.include "**/include/*.h" })

copy {
from(soFiles)
from(headerFiles)
from("$reactNative/ReactAndroid/src/main/jni/third-party/jsc/Android.mk")

filesMatching("**/*.h", { it.path = "JavaScriptCore/${it.name}" })

includeEmptyDirs(false)
into("$thirdPartyNdkDir/jsc")
}
}
}

prepareJSC.mustRunAfter prepareHermes

task extractAARHeaders {
doLast {
Expand All @@ -401,7 +209,7 @@ task extractAARHeaders {
}
}

extractAARHeaders.mustRunAfter prepareJSC
extractAARHeaders.mustRunAfter createNativeDepsDirectories

task extractJNIFiles {
doLast {
Expand All @@ -425,8 +233,5 @@ tasks.whenTaskAdded { task ->
if (!task.name.contains('Clean') && (task.name.contains('externalNative') || task.name.contains('CMake'))) {
task.dependsOn(extractAARHeaders)
task.dependsOn(extractJNIFiles)
task.dependsOn(prepareJSC)
task.dependsOn(prepareHermes)
task.dependsOn(prepareThirdPartyNdkHeaders)
}
}