File tree Expand file tree Collapse file tree 3 files changed +28
-9
lines changed
objectbox-java/src/main/java/io/objectbox Expand file tree Collapse file tree 3 files changed +28
-9
lines changed Original file line number Diff line number Diff line change 5959@ ThreadSafe
6060public class BoxStore implements Closeable {
6161
62- /** Android Context used for native library loading. */
62+ /** On Android used for native library loading. */
6363 @ Nullable public static Object context ;
64+ @ Nullable public static Object relinker ;
6465
6566 private static final String VERSION = "2.4.0-2019-01-08" ;
6667 private static BoxStore defaultStore ;
@@ -190,6 +191,7 @@ public static boolean isObjectBrowserAvailable() {
190191
191192 BoxStore (BoxStoreBuilder builder ) {
192193 context = builder .context ;
194+ relinker = builder .relinker ;
193195 NativeLibraryLoader .ensureLoaded ();
194196
195197 directory = builder .directory ;
Original file line number Diff line number Diff line change @@ -66,9 +66,9 @@ public class BoxStoreBuilder {
6666 /** BoxStore uses this */
6767 File directory ;
6868
69- /** Android Context used for native library loading. */
70- @ Nullable
71- Object context ;
69+ /** On Android used for native library loading. */
70+ @ Nullable Object context ;
71+ @ Nullable Object relinker ;
7272
7373 /** Ignored by BoxStore */
7474 private File baseDirectory ;
@@ -195,6 +195,18 @@ public BoxStoreBuilder androidContext(Object context) {
195195 return this ;
196196 }
197197
198+ /**
199+ * Pass a custom ReLinkerInstance, for example {@code ReLinker.log(logger)} to use for loading the native library
200+ * on Android devices. Note that setting {@link #androidContext(Object)} is required for ReLinker to work.
201+ */
202+ public BoxStoreBuilder androidReLinker (Object reLinkerInstance ) {
203+ if (reLinkerInstance == null ) {
204+ throw new NullPointerException ("ReLinkerInstance may not be null" );
205+ }
206+ this .relinker = reLinkerInstance ;
207+ return this ;
208+ }
209+
198210 static File getAndroidDbDir (Object context , @ Nullable String dbName ) {
199211 File baseDir = getAndroidBaseDir (context );
200212 return new File (baseDir , dbName (dbName ));
Original file line number Diff line number Diff line change @@ -131,11 +131,16 @@ private static boolean loadLibraryAndroid(String libname) {
131131
132132 try {
133133 Class <?> context = Class .forName ("android.content.Context" );
134- Class <?> relinker = Class .forName ("com.getkeepsafe.relinker.ReLinker" );
135- // ReLinker.loadLibrary(Context context, String library)
136- Method loadLibrary = relinker .getMethod ("loadLibrary" , context , String .class );
137-
138- loadLibrary .invoke (null , BoxStore .context , libname );
134+ if (BoxStore .relinker == null ) {
135+ // use default ReLinker
136+ Class <?> relinker = Class .forName ("com.getkeepsafe.relinker.ReLinker" );
137+ Method loadLibrary = relinker .getMethod ("loadLibrary" , context , String .class );
138+ loadLibrary .invoke (null , BoxStore .context , libname );
139+ } else {
140+ // use custom ReLinkerInstance
141+ Method loadLibrary = BoxStore .relinker .getClass ().getMethod ("loadLibrary" , context , String .class );
142+ loadLibrary .invoke (BoxStore .relinker , BoxStore .context , libname );
143+ }
139144 } catch (ReflectiveOperationException e ) {
140145 // note: do not catch Exception as it will swallow ReLinker exceptions useful for debugging
141146 return false ;
You can’t perform that action at this time.
0 commit comments