Skip to content

Commit

Permalink
Add support for NDK21 (#6460)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmelchior authored Feb 24, 2020
1 parent d20ba5b commit a0aa3b9
Show file tree
Hide file tree
Showing 22 changed files with 147 additions and 1,841 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ NOTE: This version bumps the Realm file format to version 10. It is not possible
### Internal
* `OsSharedRealm.VersionID.hashCode()` was not implemented correctly and included the memory location in the hashcode.
* OKHttp was upgraded to 3.10.0 from 3.9.0.
* The NDK has been upgraded from r10e to r21.
* The compiler used for C++ code has changed from GCC to Clang.
* OpenSSL used by Realms encryption layer has been upgraded from 1.0.2k to 1.1.1b.


## 6.1.0(2020-01-17)
Expand Down
10 changes: 4 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,11 @@ RUN yes | sdkmanager \
# Install the NDK
RUN mkdir /opt/android-ndk-tmp && \
cd /opt/android-ndk-tmp && \
wget -q http://dl.google.com/android/ndk/android-ndk-r10e-linux-x86_64.bin -O android-ndk.bin && \
chmod a+x ./android-ndk.bin && \
./android-ndk.bin && \
mv android-ndk-r10e /opt/android-ndk && \
wget -q https://dl.google.com/android/repository/android-ndk-r21-linux-x86_64.zip -O android-ndk.zip && \
unzip android-ndk.zip && \
mv android-ndk-r21 /opt/android-ndk && \
rm -rf /opt/android-ndk-tmp && \
chmod -R a+rX /opt/android-ndk && \
echo "Pkg.Desc = Android NDK\nPkg.Revision = 10.0.0" > /opt/android-ndk/source.properties
chmod -R a+rX /opt/android-ndk

# Make the SDK universally writable
RUN chmod -R a+rwX ${ANDROID_HOME}
24 changes: 8 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,32 +67,24 @@ In case you don't want to use the precompiled version, you can build Realm yours
### Prerequisites

* Download the [**JDK 8**](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html) from Oracle and install it.
* The latest stable version of Android Studio. Currently [3.5.2](https://developer.android.com/studio/).
* The latest stable version of Android Studio. Currently [3.5.3](https://developer.android.com/studio/).
* Download & install the Android SDK **Build-Tools 27.0.2**, **Android Oreo (API 27)** (for example through Android Studio’s **Android SDK Manager**).
* Install CMake from SDK manager in Android Studio ("SDK Tools" -> "CMake").
* Install the NDK (currently r21) from the SDK Manager in Android Studio or using the [website](https://developer.android.com/ndk/downloads). If downloaded
You may unzip the file wherever you choose. For macOS, a suggested location is `~/Library`. The download will unzip as the directory `android-ndk-r21`.

* Realm currently requires version r10e of the NDK. Download the one appropriate for your development platform, from the NDK [archive](https://developer.android.com/ndk/downloads/older_releases.html).
You may unzip the file wherever you choose. For macOS, a suggested location is `~/Library/Android`. The download will unzip as the directory `android-ndk-r10e`.

* If you will be building with Android Studio, you will need to tell it to use the correct NDK. To do this, define the variable `ndk.dir` in `realm/local.properties` and assign it the full pathname of the directory that you unzipped above. Note that there is a `local.properites` in the root directory that is *not* the one that needs to be edited.

```
ndk.dir=/Users/brian/Library/Android/android-ndk-r10e
* If you will be building with Android Studio, you will need to tell it to use the correct NDK. If you installed it using the SDK Manager, it will automatically be detected. Otherwise, you need to define the variable `ndk.dir` in `realm/local.properties` and assign it the full pathname of the directory that you unzipped above. Note that there is a `local.properites` in the root directory that is *not* the one that needs to be edited.

```
ndk.dir=/Users/<username>/Library/android-sdk/ndk/21.0.6113669
* You also need a file called `source.properties` to the `android-ndk-r10e` folder with the following content:
```
Pkg.Desc = Android NDK
Pkg.Revision = 10.0.0
```
* Add two environment variables to your profile (presuming you installed the NDK in `~/Library/android-ndk-r10e`):
* Add two environment variables to your profile (presuming you installed the NDK using the SDK Manager):
```
export ANDROID_HOME=~/Library/Android/sdk
export ANDROID_NDK_HOME=~/Library/Android/android-ndk-r10e
export ANDROID_HOME=~/Library/android-sdk
export ANDROID_NDK_HOME=~/Library/android-sdk/ndk/21.0.6113669
```
* If you are launching Android Studio from the macOS Finder, you should also run the following two commands:
Expand Down
6 changes: 3 additions & 3 deletions dependencies.list
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Realm Sync release used by Realm Java (This includes Realm Core)
# https://github.com/realm/realm-sync/releases
REALM_SYNC_VERSION=5.0.0-beta.2
REALM_SYNC_SHA256=bbe58ad5110d66fe8c55a838486e09593e93ee96db8d07aa93a22abb52ead220
REALM_SYNC_VERSION=5.0.0
REALM_SYNC_SHA256=93825d20e47627eae314d0793380908a65d622c3cdddbc0ca30fce3bb39d21cd

# Object Server Release used by Integration tests. Installed using NPM.
# Use `npm view realm-object-server versions` to get a list of available versions.
Expand All @@ -14,6 +14,6 @@ ANDROID_BUILD_TOOLS=28.0.3
# Common classpath dependencies
# Gradle 5 is not supported yet: https://issuetracker.google.com/issues/126433059
gradleVersion=4.10.1
ndkVersion=r10e
ndkVersion=21.0.6113669
BUILD_INFO_EXTRACTOR_GRADLE=4.7.5
GRADLE_BINTRAY_PLUGIN=1.8.4
2 changes: 1 addition & 1 deletion examples/architectureComponentsExample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ android {
defaultConfig {
applicationId 'io.realm.examples.arch'
targetSdkVersion rootProject.sdkVersion
minSdkVersion 16
minSdkVersion rootProject.minSdkVersion
versionCode 1
versionName "1.0"

Expand Down
2 changes: 1 addition & 1 deletion examples/multiprocessExample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {
defaultConfig {
applicationId "io.realm.examples.realmmultiprocessexample"
targetSdkVersion rootProject.sdkVersion
minSdkVersion 16
minSdkVersion rootProject.minSdkVersion
versionCode 1
versionName "1.0"
}
Expand Down
12 changes: 3 additions & 9 deletions realm/realm-library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ ext.coreDir = file("${project.coreDistributionDir.getAbsolutePath()}/core-${proj
ext.ccachePath = project.findProperty('ccachePath') ?: System.getenv('NDK_CCACHE')
ext.lcachePath = project.findProperty('lcachePath') ?: System.getenv('NDK_LCACHE')
// Set to true to enable linking with debug core.
ext.enableDebugCore = project.hasProperty('enableDebugCore') ? project.getProperty('enableDebugCore') : false //FIXME Use 'false' as default until https://github.com/realm/realm-java/issues/5354 is fixed
ext.enableDebugCore = project.hasProperty('enableDebugCore') ? project.getProperty('enableDebugCore') : true

android {
compileSdkVersion rootProject.compileSdkVersion
Expand All @@ -50,20 +50,14 @@ android {
externalNativeBuild {
cmake {
arguments "-DREALM_CORE_DIST_DIR:STRING=${project.coreDir.getAbsolutePath()}",
// FIXME:
// This is copied from https://dl.google.com/android/repository/cmake-3.4.2909474-linux-x86_64.zip
// because of the android.toolchain.cmake shipped with Android SDK CMake 3.6 doesn't work with our
// JNI build currently (lack of lto linking support).
// This file should be removed and use the one from Android SDK cmake package when it supports lto.
"-DCMAKE_TOOLCHAIN_FILE=${project.file('src/main/cpp/android.toolchain.cmake').path}",
"-DENABLE_DEBUG_CORE=$project.enableDebugCore"
if (project.ccachePath) arguments "-DNDK_CCACHE=$project.ccachePath"
if (project.lcachePath) arguments "-DNDK_LCACHE=$project.lcachePath"
if (project.coreSourcePath) arguments "-DCORE_SOURCE_PATH=${project.coreSourcePath.getAbsolutePath()}"
if (project.hasProperty('buildTargetABIs') && !project.getProperty('buildTargetABIs').trim().isEmpty()) {
abiFilters(*project.getProperty('buildTargetABIs').trim().split('\\s*,\\s*'))
} else {
// armeabi is not supported anymore.
// "armeabi" and "mips" are no longer supported by the NDK
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
}
}
Expand Down Expand Up @@ -799,7 +793,7 @@ def checkNdk(String ndkPath) {
}
if (detectedNdkVersion != project.ndkVersion) {
throw new GradleException("Your NDK version: ${detectedNdkVersion}."
+ " Realm JNI must be compiled with the version ${project.ndkVersion} of NDK.")
+ " Realm JNI must be compiled with version ${project.ndkVersion} of the NDK.")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1774,18 +1774,16 @@ public void asJSON() throws JSONException {
" \"columnDate\": \"" + now + "\",\n" +
" \"columnBinary\": \"AQID\",\n" +
" \"columnMutableRealmInteger\": 0,\n" +
" \"columnRealmObject\": [\n" +
" {\n" +
" \"_key\": 100,\n" +
" \"name\": \"dog1\",\n" +
" \"age\": 1,\n" +
" \"height\": 1.1,\n" +
" \"weight\": 10.100000381469727,\n" +
" \"hasTail\": true,\n" +
" \"birthday\": \"" + now + "\",\n" +
" \"owner\": null\n" +
" }\n" +
" ],\n" +
" \"columnRealmObject\": {\n" +
" \"_key\": 100,\n" +
" \"name\": \"dog1\",\n" +
" \"age\": 1,\n" +
" \"height\": 1.1,\n" +
" \"weight\": 10.100000381469727,\n" +
" \"hasTail\": true,\n" +
" \"birthday\": \"" + now + "\",\n" +
" \"owner\": null\n" +
" },\n" +
" \"columnRealmList\": [\n" +
" {\n" +
" \"_key\": 101,\n" +
Expand All @@ -1805,14 +1803,12 @@ public void asJSON() throws JSONException {
" \"weight\": 30.100000381469727,\n" +
" \"hasTail\": true,\n" +
" \"birthday\": \"" + now + "\",\n" +
" \"owner\": [\n" +
" {\n" +
" \"_key\": 0,\n" +
" \"name\": \"Dog owner 1\",\n" +
" \"dogs\": [],\n" +
" \"cat\": null\n" +
" }\n" +
" ]\n" +
" \"owner\": {\n" +
" \"_key\": 0,\n" +
" \"name\": \"Dog owner 1\",\n" +
" \"dogs\": [],\n" +
" \"cat\": null\n" +
" }\n" +
" }\n" +
" ],\n" +
" \"columnStringList\": [\n" +
Expand Down Expand Up @@ -1876,20 +1872,18 @@ public void asJSON_cycles() throws JSONException {
" \"id\": 0,\n" +
" \"name\": \"One\",\n" +
" \"date\": \"" + now + "\",\n" +
" \"object\": [\n" +
" {\n" +
" \"_key\": 1,\n" +
" \"id\": 0,\n" +
" \"name\": \"Two\",\n" +
" \"date\": \"" + now + "\",\n" +
" \"object\": {\n" +
" \"table\": \"class_CyclicType\",\n" +
" \"key\": 0\n" +
" },\n" +
" \"otherObject\": null,\n" +
" \"objects\": []\n" +
" }\n" +
" ],\n" +
" \"object\": {\n" +
" \"_key\": 1,\n" +
" \"id\": 0,\n" +
" \"name\": \"Two\",\n" +
" \"date\": \"" + now + "\",\n" +
" \"object\": {\n" +
" \"table\": \"class_CyclicType\",\n" +
" \"key\": 0\n" +
" },\n" +
" \"otherObject\": null,\n" +
" \"objects\": []\n" +
" },\n" +
" \"otherObject\": null,\n" +
" \"objects\": []\n" +
" },\n" +
Expand All @@ -1898,20 +1892,18 @@ public void asJSON_cycles() throws JSONException {
" \"id\": 0,\n" +
" \"name\": \"Two\",\n" +
" \"date\": \"" + now + "\",\n" +
" \"object\": [\n" +
" {\n" +
" \"_key\": 0,\n" +
" \"id\": 0,\n" +
" \"name\": \"One\",\n" +
" \"date\": \"" + now + "\",\n" +
" \"object\": {\n" +
" \"table\": \"class_CyclicType\",\n" +
" \"key\": 1\n" +
" },\n" +
" \"otherObject\": null,\n" +
" \"objects\": []\n" +
" }\n" +
" ],\n" +
" \"object\": {\n" +
" \"_key\": 0,\n" +
" \"id\": 0,\n" +
" \"name\": \"One\",\n" +
" \"date\": \"" + now + "\",\n" +
" \"object\": {\n" +
" \"table\": \"class_CyclicType\",\n" +
" \"key\": 1\n" +
" },\n" +
" \"otherObject\": null,\n" +
" \"objects\": []\n" +
" },\n" +
" \"otherObject\": null,\n" +
" \"objects\": []\n" +
" }\n" +
Expand Down
59 changes: 22 additions & 37 deletions realm/realm-library/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,47 +101,31 @@ create_javah(TARGET jni_headers
)

include(RealmCore)

use_realm_core(${build_SYNC} "${REALM_CORE_DIST_DIR}" "${CORE_SOURCE_PATH}")

# Download openssl lib
#string(TOLOWER "${CMAKE_BUILD_TYPE}" openssl_build_TYPE)
set(openssl_build_TYPE "release")
# Download OpenSSL lib
# FIXME Read the openssl version from core when the core/sync release has that information.
set(openssl_VERSION "1.0.2k")
set(openssl_BUILD_NUMBER "1")
set(openssl_FILENAME "openssl-${openssl_build_TYPE}-${openssl_VERSION}-${openssl_BUILD_NUMBER}-Android-${ANDROID_ABI}")
set(openssl_URL "http://static.realm.io/downloads/openssl/${openssl_VERSION}/Android/${ANDROID_ABI}/${openssl_FILENAME}.tar.gz")
set(openssl_VERSION "1.1.1b")
set(openssl_FILENAME "openssl.tgz")
set(openssl_URL "https://static.realm.io/downloads/openssl/${openssl_VERSION}/Android/${ANDROID_ABI}/${openssl_FILENAME}")

message(STATUS "Downloading OpenSSL...")
file(DOWNLOAD "${openssl_URL}" "${PROJECT_BINARY_DIR}/${openssl_FILENAME}.tar.gz")

message(STATUS "Uncompressing OpenSSL...")
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xfz "${PROJECT_BINARY_DIR}/${openssl_FILENAME}.tar.gz"
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}")
file(DOWNLOAD "${openssl_URL}" "${PROJECT_BINARY_DIR}/${openssl_FILENAME}")

message(STATUS "Uncompressing OpenSSL: ${PROJECT_BINARY_DIR}/${openssl_FILENAME}")
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xfz "${openssl_FILENAME}" WORKING_DIRECTORY "${PROJECT_BINARY_DIR}")
message(STATUS "Importing OpenSSL...")
include(${PROJECT_BINARY_DIR}/${openssl_FILENAME}/openssl.cmake)
get_target_property(openssl_include_DIR crypto INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(crypto_LIB crypto IMPORTED_LOCATION)
get_target_property(ssl_LIB ssl IMPORTED_LOCATION)
include(${PROJECT_BINARY_DIR}/lib/cmake/OpenSSL/OpenSSLConfig.cmake)
get_target_property(openssl_include_DIR OpenSSL::Crypto INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(crypto_LIB OpenSSL::Crypto IMPORTED_LOCATION)
get_target_property(ssl_LIB OpenSSL::SSL IMPORTED_LOCATION)

# build application's shared lib
include_directories(
${CMAKE_SOURCE_DIR}
${jni_headers_PATH}
${CMAKE_SOURCE_DIR}/object-store/src)

set(ANDROID_STL "gnustl_static")
set(ANDROID_NO_UNDEFINED OFF)
set(ANDROID_SO_UNDEFINED ON)

if (ARMEABI)
set(ABI_CXX_FLAGS "-mthumb")
elseif (ARMEABI_V7A)
set(ABI_CXX_FLAGS "-mthumb -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16")
endif()

# Hack the memmove bug on Samsung device.
if (ARMEABI OR ARMEABI_V7A)
set(REALM_LINKER_FLAGS "${REALM_LINKER_FLAGS} -Wl,--wrap,memmove -Wl,--wrap,memcpy")
Expand All @@ -157,19 +141,20 @@ endif()
# -Wno-missing-field-initializers disable in object store as well.
set(WARNING_CXX_FLAGS "-Werror -Wall -Wextra -pedantic -Wmissing-declarations \
-Wempty-body -Wparentheses -Wunknown-pragmas -Wunreachable-code \
-Wno-missing-field-initializers -Wno-maybe-uninitialized -Wno-uninitialized")
set(REALM_COMMON_CXX_FLAGS "${REALM_COMMON_CXX_FLAGS} -DREALM_ANDROID -DREALM_HAVE_CONFIG -DPIC -pthread -fvisibility=hidden -std=c++14 -fsigned-char")
-Wno-missing-field-initializers -Wno-unevaluated-expression -Wno-unreachable-code")
set(REALM_COMMON_CXX_FLAGS "${REALM_COMMON_CXX_FLAGS} -DREALM_ANDROID -DREALM_HAVE_CONFIG -DPIC -fdata-sections -pthread -frtti -fvisibility=hidden -fsigned-char -fno-stack-protector -std=c++14")
if (build_SYNC)
set(REALM_COMMON_CXX_FLAGS "${REALM_COMMON_CXX_FLAGS} -DREALM_ENABLE_SYNC=1")
endif()
# There might be an issue with -Os of ndk gcc 4.9. It will hang the encryption related tests.
# And this issue doesn't seem to impact the core compiling.
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
#-ggdb doesn't play well with -flto
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb -Og")
set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG -Oz")
# -ggdb doesn't play well with -flto
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -glldb -g")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${REALM_COMMON_CXX_FLAGS} ${WARNING_CXX_FLAGS} ${ABI_CXX_FLAGS}")

# Set link flags
# Set Linker flags flags
if (CMAKE_BUILD_TYPE STREQUAL "Release")
set(REALM_LINKER_FLAGS "${REALM_LINKER_FLAGS} -Wl,-gc-sections")
endif()
if (build_SYNC)
set(REALM_LINKER_FLAGS "${REALM_LINKER_FLAGS} -lz")
endif()
Expand Down Expand Up @@ -215,9 +200,9 @@ add_library(realm-jni SHARED ${jni_SRC} ${objectstore_SRC} ${objectstore_sync_SR
add_dependencies(realm-jni jni_headers)

if (build_SYNC)
target_link_libraries(realm-jni log android lib_realm_sync crypto ssl)
target_link_libraries(realm-jni log android lib_realm_sync OpenSSL::SSL OpenSSL::Crypto)
else()
target_link_libraries(realm-jni log android lib_realm_core crypto)
target_link_libraries(realm-jni log android lib_realm_core OpenSSL::Crypto)
endif()

# Strip the release so files and backup the unstripped versions
Expand Down
Loading

0 comments on commit a0aa3b9

Please sign in to comment.