diff --git a/native/android/app/src/main/java/app/comm/android/CommCoreJSIModulePackage.java b/native/android/app/src/main/java/app/comm/android/CommCoreJSIModulePackage.java --- a/native/android/app/src/main/java/app/comm/android/CommCoreJSIModulePackage.java +++ b/native/android/app/src/main/java/app/comm/android/CommCoreJSIModulePackage.java @@ -13,6 +13,7 @@ import java.lang.reflect.Field; import java.util.Collections; import java.util.List; +import java.util.function.Supplier; public class CommCoreJSIModulePackage extends ReanimatedJSIModulePackage { @@ -20,25 +21,9 @@ public List getJSIModules( ReactApplicationContext reactApplicationContext, JavaScriptContextHolder jsContext) { - ModuleRegistry moduleRegistry; - try { - Field moduleRegistryField = - NativeModulesProxy.class.getDeclaredField("mModuleRegistry"); - moduleRegistryField.setAccessible(true); - NativeModulesProxy proxy = - (NativeModulesProxy)reactApplicationContext.getCatalystInstance() - .getNativeModule("NativeUnimoduleProxy"); - moduleRegistry = (ModuleRegistry)moduleRegistryField.get(proxy); - } catch (Exception e) { - throw new RuntimeException( - "Accessing expo modules registry resulted in an error: " + - Log.getStackTraceString(e) + - "This might be due to changes in expo's internal implementation."); - } - SecureStoreModule secureStoreModule = - (SecureStoreModule)moduleRegistry.getExportedModuleOfClass( - SecureStoreModule.class); - CommSecureStore.getInstance().initialize(secureStoreModule); + Supplier secureStoreModuleSupplier = + () -> new SecureStoreModule(reactApplicationContext); + CommSecureStore.getInstance().initialize(secureStoreModuleSupplier); CommHybrid.initHybrid(reactApplicationContext); super.getJSIModules(reactApplicationContext, jsContext); return Collections.emptyList(); diff --git a/native/android/app/src/main/java/app/comm/android/fbjni/CommSecureStore.java b/native/android/app/src/main/java/app/comm/android/fbjni/CommSecureStore.java --- a/native/android/app/src/main/java/app/comm/android/fbjni/CommSecureStore.java +++ b/native/android/app/src/main/java/app/comm/android/fbjni/CommSecureStore.java @@ -4,6 +4,7 @@ import expo.modules.core.arguments.MapArguments; import expo.modules.core.arguments.ReadableArguments; import expo.modules.securestore.SecureStoreModule; +import java.util.function.Supplier; public class CommSecureStore { @@ -19,8 +20,15 @@ return CommSecureStore.instance; } - public void initialize(SecureStoreModule secureStoreModule) { - this.secureStoreModule = secureStoreModule; + public void + initialize(Supplier secureStoreModuleSupplier) { + if (this.secureStoreModule == null) { + synchronized (this) { + if (this.secureStoreModule == null) { + this.secureStoreModule = secureStoreModuleSupplier.get(); + } + } + } } private void checkModule() {