Skip to content

Commit 9d08f69

Browse files
committed
perf(android): hide native symbols and consolidate compile flags
Only JNI_OnLoad has to leave the library - JNIEXPORT keeps it exported and fbjni registers all natives via RegisterNatives. Shrinks the stripped release .so by 42% (5.3 MB over all four ABIs, 5535 -> 87 exported symbols). The nested buildTypes block never scoped anything: -O1 -g and -O2 were appended to every variant, so debug was compiled with -O2. It now uses -O1.
1 parent 20c3a43 commit 9d08f69

3 files changed

Lines changed: 13 additions & 24 deletions

File tree

android/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ add_library(${PACKAGE_NAME} SHARED
1313
src/main/cpp/cpp-adapter.cpp
1414
)
1515

16+
# Compile options, only JNI_OnLoad has to be exported, hide every other symbol
17+
target_compile_options(${PACKAGE_NAME} PRIVATE
18+
-frtti
19+
-fexceptions
20+
-Wall
21+
-fstack-protector-all
22+
-fvisibility=hidden
23+
$<$<CONFIG:Debug>:-O1>
24+
)
25+
1626
# Add Nitrogen specs :)
1727
include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/RNGoogleMapsPlus+autolinking.cmake)
1828

android/build.gradle

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,8 @@ android {
4848

4949
externalNativeBuild {
5050
cmake {
51-
cppFlags "-frtti -fexceptions -Wall -fstack-protector-all"
5251
arguments "-DANDROID_STL=c++_shared", "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
5352
abiFilters (*reactNativeArchitectures())
54-
55-
buildTypes {
56-
debug {
57-
cppFlags "-O1 -g"
58-
}
59-
release {
60-
cppFlags "-O2"
61-
}
62-
}
6353
}
6454
}
6555
}

android/proguard-rules.pro

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
-keep class com.google.android.gms.** { *; }
2-
-keep interface com.google.android.gms.** { *; }
1+
-keep class com.google.android.gms.maps.** { *; }
2+
-keep interface com.google.android.gms.maps.** { *; }
33
-dontwarn com.google.android.gms.**
44
-dontnote com.google.android.gms.**
55

6-
-keep class * implements android.os.Parcelable { *; }
7-
8-
-keepclassmembers class **$Companion {
9-
public *;
10-
}
11-
126
-keep class com.google.maps.android.** { *; }
137
-keep interface com.google.maps.android.** { *; }
148
-dontwarn com.google.maps.android.**
@@ -18,12 +12,7 @@
1812
@androidx.annotation.Keep *;
1913
}
2014

21-
-keep class com.caverock.androidsvg.** { *; }
15+
-keep class com.caverock.androidsvg.SVG { *; }
2216
-dontwarn com.caverock.androidsvg.**
2317

24-
-keepclassmembers class com.caverock.androidsvg.** {
25-
public *;
26-
protected *;
27-
}
28-
2918
-keep class com.rngooglemapsplus.** { *; }

0 commit comments

Comments
 (0)