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 59
59
@ ThreadSafe
60
60
public class BoxStore implements Closeable {
61
61
62
- /** Android Context used for native library loading. */
62
+ /** On Android used for native library loading. */
63
63
@ Nullable public static Object context ;
64
+ @ Nullable public static Object relinker ;
64
65
65
66
private static final String VERSION = "2.4.0-2019-01-08" ;
66
67
private static BoxStore defaultStore ;
@@ -190,6 +191,7 @@ public static boolean isObjectBrowserAvailable() {
190
191
191
192
BoxStore (BoxStoreBuilder builder ) {
192
193
context = builder .context ;
194
+ relinker = builder .relinker ;
193
195
NativeLibraryLoader .ensureLoaded ();
194
196
195
197
directory = builder .directory ;
Original file line number Diff line number Diff line change @@ -66,9 +66,9 @@ public class BoxStoreBuilder {
66
66
/** BoxStore uses this */
67
67
File directory ;
68
68
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 ;
72
72
73
73
/** Ignored by BoxStore */
74
74
private File baseDirectory ;
@@ -195,6 +195,18 @@ public BoxStoreBuilder androidContext(Object context) {
195
195
return this ;
196
196
}
197
197
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
+
198
210
static File getAndroidDbDir (Object context , @ Nullable String dbName ) {
199
211
File baseDir = getAndroidBaseDir (context );
200
212
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) {
131
131
132
132
try {
133
133
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
+ }
139
144
} catch (ReflectiveOperationException e ) {
140
145
// note: do not catch Exception as it will swallow ReLinker exceptions useful for debugging
141
146
return false ;
You can’t perform that action at this time.
0 commit comments