From 270604a347022db6a87480dbfa315f80aac47096 Mon Sep 17 00:00:00 2001 From: Kenneth Geisshirt Date: Wed, 11 Oct 2017 21:58:27 +0200 Subject: [PATCH] RN Android uses OpenSSL package (#1405) --- CHANGELOG.md | 5 ++++ react-native/android/build.gradle | 29 ++++++++++++++++++- react-native/android/src/main/jni/Android.mk | 18 ++++++++++++ .../android/src/main/jni/Application.mk | 2 ++ 4 files changed, 53 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 554efc68..0ae98936 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,11 @@ X.Y.Z Release notes * Upgrading to Realm Sync 2.0.0-rc28. * Upgrading to Realm Object Server 2.0.0-rc.4. +### Internal +* OpenSSL for Android is distributed in a separate package, and the build system needed updates to accommendate this. +* Added `-fvisibility=hidden` to Android builds (reduces size of `.so` file). + + 2.0.0-rc19 Release notes (2017-10-7) ============================================================= ### Breaking changes diff --git a/react-native/android/build.gradle b/react-native/android/build.gradle index 53fceccc..d939732c 100644 --- a/react-native/android/build.gradle +++ b/react-native/android/build.gradle @@ -92,6 +92,33 @@ task prepareRealmCore(dependsOn: downloadRealmCore, type:Copy) { } } +task downloadOpenSSL_x86(type: Download) { + src "https://static.realm.io/downloads/openssl/1.0.2k/Android/x86/openssl-release-1.0.2k-Android-x86.tar.gz" + onlyIfNewer true + overwrite true + dest new File(downloadsDir, "openssl-release-1.0.2k-Android-x86.tar.gz") +} + +task prepareOpenSSL_x86(dependsOn: downloadOpenSSL_x86, type:Copy) { + from tarTree(downloadOpenSSL_x86.dest) + into "$coreDownloadDir/core" +} + +task downloadOpenSSL_arm(type: Download) { + src "https://static.realm.io/downloads/openssl/1.0.2k/Android/armeabi-v7a/openssl-release-1.0.2k-Android-armeabi-v7a.tar.gz" + onlyIfNewer true + overwrite true + dest new File(downloadsDir, "openssl-release-1.0.2k-Android-armeabi-v7a.tar.gz") +} + +task prepareOpenSSL_arm(dependsOn: downloadOpenSSL_arm, type:Copy) { + from tarTree(downloadOpenSSL_arm.dest) + into "$coreDownloadDir/core" + rename { String fileName -> + fileName.replace("-arm-", "-armeabi-") + } +} + def getDependenciesVersion(keyName) { def inputFile = new File(buildscript.sourceFile.getParent() + "/../../dependencies.list") def line @@ -194,7 +221,7 @@ def getNdkBuildFullPath() { return ndkBuildFullPath } -task buildReactNdkLib(dependsOn: [downloadJSCHeaders,prepareRealmCore], type: Exec) { +task buildReactNdkLib(dependsOn: [downloadJSCHeaders,prepareRealmCore,prepareOpenSSL_x86,prepareOpenSSL_arm], type: Exec) { inputs.file('src/main/jni') outputs.dir("$buildDir/realm-react-ndk/all") commandLine getNdkBuildFullPath(), diff --git a/react-native/android/src/main/jni/Android.mk b/react-native/android/src/main/jni/Android.mk index dfbd3b84..46d88afc 100644 --- a/react-native/android/src/main/jni/Android.mk +++ b/react-native/android/src/main/jni/Android.mk @@ -6,6 +6,12 @@ LOCAL_MODULE := realm-android-sync-$(TARGET_ARCH_ABI) LOCAL_EXPORT_C_INCLUDES := core/include LOCAL_SRC_FILES := core/librealm-sync-android-$(TARGET_ARCH_ABI).a include $(PREBUILT_STATIC_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := crypto-$(TARGET_ARCH_ABI) +LOCAL_EXPORT_C_INCLUDES := core/openssl-release-1.0.2k-Android-$(TARGET_ARCH_ABI)/include +LOCAL_SRC_FILES := core/openssl-release-1.0.2k-Android-$(TARGET_ARCH_ABI)/lib/libcrypto.a +include $(PREBUILT_STATIC_LIBRARY) endif include $(CLEAR_VARS) @@ -19,6 +25,12 @@ LOCAL_MODULE := libjsc LOCAL_EXPORT_C_INCLUDES := jsc include $(BUILD_SHARED_LIBRARY) +include $(CLEAR_VARS) +LOCAL_MODULE := ssl-$(TARGET_ARCH_ABI) +LOCAL_EXPORT_C_INCLUDES := core/openssl-release-1.0.2k-Android-$(TARGET_ARCH_ABI)/include +LOCAL_SRC_FILES := core/openssl-release-1.0.2k-Android-$(TARGET_ARCH_ABI)/lib/libssl.a +include $(PREBUILT_STATIC_LIBRARY) + include $(CLEAR_VARS) LOCAL_MODULE := librealmreact @@ -43,6 +55,7 @@ LOCAL_SRC_FILES += src/object-store/src/impl/epoll/external_commit_helper.cpp LOCAL_SRC_FILES += src/object-store/src/parser/parser.cpp LOCAL_SRC_FILES += src/object-store/src/parser/query_builder.cpp LOCAL_SRC_FILES += src/object-store/src/util/format.cpp +LOCAL_SRC_FILES += src/object-store/src/util/uuid.cpp LOCAL_SRC_FILES += src/object-store/src/binding_callback_thread_observer.cpp LOCAL_SRC_FILES += src/object-store/src/collection_notifications.cpp LOCAL_SRC_FILES += src/object-store/src/index_set.cpp @@ -60,6 +73,7 @@ LOCAL_SRC_FILES += src/object-store/src/sync/sync_session.cpp LOCAL_SRC_FILES += src/object-store/src/sync/sync_user.cpp LOCAL_SRC_FILES += src/object-store/src/sync/sync_config.cpp LOCAL_SRC_FILES += src/object-store/src/sync/partial_sync.cpp +LOCAL_SRC_FILES += src/object-store/src/sync/sync_permission.cpp LOCAL_SRC_FILES += src/object-store/src/sync/impl/sync_file.cpp LOCAL_SRC_FILES += src/object-store/src/sync/impl/sync_metadata.cpp endif @@ -75,6 +89,7 @@ LOCAL_C_INCLUDES += $(JAVA_HOME)/include LOCAL_C_INCLUDES += $(JAVA_HOME)/include/darwin LOCAL_C_INCLUDES += $(JAVA_HOME)/include/linux LOCAL_C_INCLUDES += core/include +LOCAL_C_INCLUDES += core/openssl-release-1.0.2k-Android-$(TARGET_ARCH_ABI)/include ifeq ($(strip $(BUILD_TYPE_SYNC)),1) LOCAL_C_INCLUDES += src/object-store/src/sync endif @@ -83,8 +98,11 @@ LOCAL_ALLOW_UNDEFINED_SYMBOLS := true ifeq ($(strip $(BUILD_TYPE_SYNC)),1) LOCAL_STATIC_LIBRARIES := realm-android-sync-$(TARGET_ARCH_ABI) LOCAL_STATIC_LIBRARIES += realm-android-$(TARGET_ARCH_ABI) +LOCAL_STATIC_LIBRARIES += ssl-$(TARGET_ARCH_ABI) +LOCAL_STATIC_LIBRARIES += crypto-$(TARGET_ARCH_ABI) else LOCAL_STATIC_LIBRARIES := realm-android-$(TARGET_ARCH_ABI) +LOCAL_STATIC_LIBRARIES += crypto-$(TARGET_ARCH_ABI) endif diff --git a/react-native/android/src/main/jni/Application.mk b/react-native/android/src/main/jni/Application.mk index 2dee6afc..d925de04 100644 --- a/react-native/android/src/main/jni/Application.mk +++ b/react-native/android/src/main/jni/Application.mk @@ -13,11 +13,13 @@ APP_CPPFLAGS += -frtti APP_CPPFLAGS += -fexceptions APP_CPPFLAGS += -DREALM_HAVE_CONFIG APP_CPPFLAGS += -fomit-frame-pointer +APP_CPPFLAGS += -fvisibility=hidden # Make sure every shared lib includes a .note.gnu.build-id header APP_LDFLAGS := -Wl,--build-id APP_LDFLAGS += -llog APP_LDFLAGS += -landroid +APP_LDFLAGS += -fvisibility=hidden ifeq ($(strip $(BUILD_TYPE_SYNC)),1) APP_CPPFLAGS += -DREALM_ENABLE_SYNC=1