diff --git a/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactTestHelper.java b/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactTestHelper.java index 8a65a51f6..5542d7a3a 100644 --- a/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactTestHelper.java +++ b/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactTestHelper.java @@ -80,7 +80,8 @@ public class ReactTestHelper { .setJSExecutor(executor) .setRegistry(new NativeModuleRegistry( mModuleSpecList, - Collections.emptyMap())) + Collections.emptyMap(), + false)) .setJSModuleRegistry(mJSModuleRegistryBuilder.build()) .setJSBundleLoader(JSBundleLoader.createAssetLoader( mContext, diff --git a/ReactAndroid/src/main/java/com/facebook/react/XReactInstanceManagerImpl.java b/ReactAndroid/src/main/java/com/facebook/react/XReactInstanceManagerImpl.java index a8956a2eb..d7c85c712 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/XReactInstanceManagerImpl.java +++ b/ReactAndroid/src/main/java/com/facebook/react/XReactInstanceManagerImpl.java @@ -892,7 +892,10 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE; Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "buildNativeModuleRegistry"); NativeModuleRegistry nativeModuleRegistry; try { - nativeModuleRegistry = new NativeModuleRegistry(moduleSpecs, reactModuleInfoMap); + nativeModuleRegistry = new NativeModuleRegistry( + moduleSpecs, + reactModuleInfoMap, + mLazyNativeModulesEnabled); } finally { Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE); ReactMarker.logMarker(BUILD_NATIVE_MODULE_REGISTRY_END); diff --git a/ReactAndroid/src/main/java/com/facebook/react/cxxbridge/NativeModuleRegistry.java b/ReactAndroid/src/main/java/com/facebook/react/cxxbridge/NativeModuleRegistry.java index 2c15fab2a..f80c61f00 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/cxxbridge/NativeModuleRegistry.java +++ b/ReactAndroid/src/main/java/com/facebook/react/cxxbridge/NativeModuleRegistry.java @@ -36,14 +36,19 @@ public class NativeModuleRegistry { public NativeModuleRegistry( List moduleSpecList, - Map reactModuleInfoMap) { + Map reactModuleInfoMap, + boolean isLazyNativeModulesEnabled) { Map, ModuleHolder>> namesToSpecs = new HashMap<>(); for (ModuleSpec module : moduleSpecList) { Class type = module.getType(); - ModuleHolder holder = new ModuleHolder( - type, - reactModuleInfoMap.get(type), - module.getProvider()); + ReactModuleInfo reactModuleInfo = reactModuleInfoMap.get(type); + if (isLazyNativeModulesEnabled && + reactModuleInfo == null && + BaseJavaModule.class.isAssignableFrom(type)) { + throw new IllegalStateException("Native Java module " + type.getSimpleName() + + " should be annotated with @ReactModule and added to a @ReactModuleList."); + } + ModuleHolder holder = new ModuleHolder(type, reactModuleInfo, module.getProvider()); String name = holder.getInfo().name(); Class existing = namesToSpecs.containsKey(name) ? namesToSpecs.get(name).first :