Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for NDK21 #6460

Merged
merged 136 commits into from
Feb 24, 2020
Merged

Add support for NDK21 #6460

merged 136 commits into from
Feb 24, 2020

Conversation

cmelchior
Copy link
Contributor

@cmelchior cmelchior commented Mar 12, 2019

This PR bumps the NDK support from r10e to r21

Closes #6408
Closes #3506
Closes #3623

It has the following impact:

  • minSdk is bumped from 9 to 16 (This will impact ~1% of current users)
  • MIPS support is dropped. Google already did this, and to our knowledge, no users would be affected.
  • Dropping MIPS will reduce universal APK size by ~1.5MB. People using App Split or App Bundle will not be affected.
  • Native code is now compiled with Clang instead of GCC.
  • OpenSSL is upgraded from 1.0.2 to 1.1.1.

TODO

  • Merge NDK 18 support in Object Store and redirect OS submodule.
  • Our prebuilt OpenSSL needs to be built without including ARM assembler code. It breaks Android.
  • OpenSSL was apparently built with minSDK 21. This was mostly done to include 64 bit support which was added in 21. But 32 bit builds should be done using minSdk 16.
  • Test size differences for both base and objectServer builds.
  • Performance benchmarks
  • Fix Core compiler flags
  • Fix Sync compiler flags
  • Fix OpenSSL compiler flags

See https://github.com/realm/openssl-android-termux

@cmelchior
Copy link
Contributor Author

cmelchior commented Feb 21, 2020

Comparing next-major built with NDK10 with this branch

NDK 21 - Default Linker (not LLD)

Analyzing Base...
Method count: 3490
AAR size: 8.161.817
3871584 ./unzippedBase/jni/armeabi-v7a/librealm-jni.so
5702688 ./unzippedBase/jni/x86/librealm-jni.so
5529928 ./unzippedBase/jni/arm64-v8a/librealm-jni.so
6120032 ./unzippedBase/jni/x86_64/librealm-jni.so

Analyzing ObjectServer...
Method count: 4742
AAR size: 11.280.391
5119940 ./unzippedObjectServer/jni/armeabi-v7a/librealm-jni.so
7590088 ./unzippedObjectServer/jni/x86/librealm-jni.so
7318024 ./unzippedObjectServer/jni/arm64-v8a/librealm-jni.so
8055616 ./unzippedObjectServer/jni/x86_64/librealm-jni.so

NDK r10e

Analyzing Base...
Method count: 3490
AAR size: 6.882.507
3118736 ./unzippedBase/jni/armeabi-v7a/librealm-jni.so
5040132 ./unzippedBase/jni/x86/librealm-jni.so
4568464 ./unzippedBase/jni/arm64-v8a/librealm-jni.so
4897488 ./unzippedBase/jni/x86_64/librealm-jni.so

Analyzing ObjectServer...
Method count: 4742
AAR size: 10.202.000
4521908 ./unzippedObjectServer/jni/armeabi-v7a/librealm-jni.so
7018692 ./unzippedObjectServer/jni/x86/librealm-jni.so
6432032 ./unzippedObjectServer/jni/arm64-v8a/librealm-jni.so
6816144 ./unzippedObjectServer/jni/x86_64/librealm-jni.so

Flag notes

Adding -fno-stack-protector saves about 60Kb. Worth thinking about.

@cmelchior
Copy link
Contributor Author

cmelchior commented Feb 21, 2020

@nhachicha this PR is now ready for review.
Note there are two outstanding issues with an issue tracking them here: #6754

But I don't think they should stop us from merging this PR as NDK21 support is required to adopt any of the new datatypes being developed in Core/ObjectStore.

Copy link
Collaborator

@nhachicha nhachicha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor things 👍

set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
#-ggdb doesn't play well with -flto
set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG -Oz")
# -ggdb doesn't play well with -flto
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb -Og")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similarly, should we suppress optimisation for glldb as well?

@@ -157,8 +157,8 @@ JNIEXPORT jboolean JNICALL Java_io_realm_SyncSession_nativeWaitForDownloadComple
static JavaClass java_sync_session_class(env, "io/realm/SyncSession");
static JavaMethod java_notify_result_method(env, java_sync_session_class, "notifyAllChangesSent",
"(ILjava/lang/Long;Ljava/lang/String;)V");
JavaGlobalRef java_session_object_ref(env, session_object);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw JavaGlobalRef has move assignment operator so

session->wait_for_download_completion([java_session_object_ref=std::move(java_session_object_ref), callback_id](std::error_code error) {

should work I think, since the moved java_session_object_ref will be deleted inside the callback scope

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting the following error no matter what I do. Even using your approach. I'm suspecting it is somehow related to how the JavaGlobalRef class is defined, but no idea how to fix it

 /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_SyncSession.cpp:194:49: note: candidate constructor (the implicit move constructor) not viable: 1st argument ('const (lambda at /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_SyncSession.cpp:194:49)') would lose const qualifier

@@ -291,7 +291,7 @@ JNIEXPORT jstring JNICALL Java_io_realm_internal_OsRealmConfig_nativeCreateAndSe
case ECONNABORTED: error_code = 113; break;
default:
/* Do nothing */
error_code = error_code;
(void)0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could use REALM_UNREACHABLE(); instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't unreachable, you might end up here, but if there is no code here it will trigger a warning which breaks compilation

@@ -300,7 +300,7 @@ JNIEXPORT jstring JNICALL Java_io_realm_internal_OsRealmConfig_nativeCreateAndSe
case util::MiscExtErrors::delim_not_found: error_code = 3; break;
default:
/* Do nothing */
error_code = error_code;
(void)0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@@ -38,6 +38,9 @@
* @return
*/
public static Permission findOrCreatePermissionForRole(RealmObject container, RealmList<Permission> permissions, String roleName) {
if (roleName == null) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (roleName == null) {
if (Util.isEmptyString(roleName)) {

# To run it:
# 1. Make sure that $D8 is defined in your environment, e.g. `D8="$ANDROID_SDK_ROOT/build-tools/29.0.2/d8"`
# 2. Make sure that you have built the library artifacts using `./gradlew assembleRelease` from the realm folder.
# 3. Run the script: `> sh ./analyze_realm_metrics.sh`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, running this from tools or <root> or <root/realm> always report cat: ./unzippedBase/classes.dex: No such file or directory

Analyzing Base...
AAR size: 2476366
cat: ./unzippedBase/classes.dex: No such file or directory
5641248 ./unzippedBase/jni/x86/librealm-jni.so

Analyzing ObjectServer...
AAR size: 3476405
cat: ./unzippedObjectServer/classes.dex: No such file or directory

@nhachicha nhachicha assigned cmelchior and unassigned nhachicha Feb 24, 2020
@cmelchior cmelchior merged commit a0aa3b9 into next-major Feb 24, 2020
@cmelchior cmelchior deleted the cm/ndk18 branch February 24, 2020 22:11
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants