66@ ApiStatus .Internal
77public final class SentryNdk {
88
9- static {
10- // On older Android versions, it was necessary to manually call "`System.loadLibrary` on all
11- // transitive dependencies before loading [the] main library."
12- // The dependencies of `libsentry.so` are currently `lib{c,m,dl,log}.so`.
13- // See
14- // https://android.googlesource.com/platform/bionic/+/master/android-changes-for-ndk-developers.md#changes-to-library-dependency-resolution
15- System .loadLibrary ("log" );
16- System .loadLibrary ("sentry" );
17- System .loadLibrary ("sentry-android" );
18- }
9+ private static volatile boolean nativeLibrariesLoaded ;
1910
2011 private SentryNdk () {}
2112
@@ -29,11 +20,31 @@ private SentryNdk() {}
2920 * @param options the SentryAndroidOptions
3021 */
3122 public static void init (@ NotNull final NdkOptions options ) {
23+ loadNativeLibraries ();
3224 initSentryNative (options );
3325 }
3426
3527 /** Closes the NDK integration */
3628 public static void close () {
29+ loadNativeLibraries ();
3730 shutdown ();
3831 }
32+
33+ /**
34+ * Loads all required native libraries. This is automatically done by {@link #init(NdkOptions)},
35+ * but can be called manually in case you want to preload the libraries before calling #init.
36+ */
37+ public static synchronized void loadNativeLibraries () {
38+ if (!nativeLibrariesLoaded ) {
39+ // On older Android versions, it was necessary to manually call "`System.loadLibrary` on all
40+ // transitive dependencies before loading [the] main library."
41+ // The dependencies of `libsentry.so` are currently `lib{c,m,dl,log}.so`.
42+ // See
43+ // https://android.googlesource.com/platform/bionic/+/master/android-changes-for-ndk-developers.md#changes-to-library-dependency-resolution
44+ System .loadLibrary ("log" );
45+ System .loadLibrary ("sentry" );
46+ System .loadLibrary ("sentry-android" );
47+ nativeLibrariesLoaded = true ;
48+ }
49+ }
3950}
0 commit comments