diff --git a/ReactAndroid/src/main/java/com/facebook/react/CoreModulesPackage.java b/ReactAndroid/src/main/java/com/facebook/react/CoreModulesPackage.java index df524cf91..f696bfdd1 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/CoreModulesPackage.java +++ b/ReactAndroid/src/main/java/com/facebook/react/CoreModulesPackage.java @@ -60,7 +60,7 @@ import com.facebook.react.uimanager.events.RCTEventEmitter; new ExceptionsManagerModule(mReactInstanceManager.getDevSupportManager()), new Timing(catalystApplicationContext), new SourceCodeModule( - mReactInstanceManager.getDevSupportManager().getSourceUrl(), + mReactInstanceManager.getSourceUrl(), mReactInstanceManager.getDevSupportManager().getSourceMapUrl()), new UIManagerModule( catalystApplicationContext, diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java index 4d091a109..37822b8d6 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java @@ -86,6 +86,7 @@ public class ReactInstanceManager { private @Nullable volatile ReactContext mCurrentReactContext; private final Context mApplicationContext; private @Nullable DefaultHardwareBackBtnHandler mDefaultBackButtonImpl; + private String mSourceUrl; private final ReactInstanceDevCommandsHandler mDevInterface = new ReactInstanceDevCommandsHandler() { @@ -340,6 +341,13 @@ public class ReactInstanceManager { mDevSupportManager.showDevOptionsDialog(); } + /** + * Get the URL where the last bundle was loaded from. + */ + public String getSourceUrl() { + return Assertions.assertNotNull(mSourceUrl); + } + /** * Attach given {@param rootView} to a catalyst instance manager and start JS application using * JS module provided by {@link ReactRootView#getJSModuleName}. If the react context is currently @@ -493,6 +501,7 @@ public class ReactInstanceManager { JavaScriptExecutor jsExecutor, JSBundleLoader jsBundleLoader) { FLog.i(ReactConstants.TAG, "Creating react context."); + mSourceUrl = jsBundleLoader.getSourceUrl(); NativeModuleRegistry.Builder nativeRegistryBuilder = new NativeModuleRegistry.Builder(); JavaScriptModulesConfig.Builder jsModulesBuilder = new JavaScriptModulesConfig.Builder(); diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/JSBundleLoader.java b/ReactAndroid/src/main/java/com/facebook/react/bridge/JSBundleLoader.java index ee42c5153..d703bbc4f 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/bridge/JSBundleLoader.java +++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/JSBundleLoader.java @@ -30,6 +30,11 @@ public abstract class JSBundleLoader { public void loadScript(ReactBridge bridge) { bridge.loadScriptFromAssets(assetManager, assetFileName); } + + @Override + public String getSourceUrl() { + return "file:///android_asset/" + assetFileName; + } }; } @@ -48,6 +53,11 @@ public abstract class JSBundleLoader { public void loadScript(ReactBridge bridge) { bridge.loadScriptFromNetworkCached(sourceURL, cachedFileLocation); } + + @Override + public String getSourceUrl() { + return sourceURL; + } }; } @@ -62,8 +72,14 @@ public abstract class JSBundleLoader { public void loadScript(ReactBridge bridge) { bridge.loadScriptFromNetworkCached(sourceURL, null); } + + @Override + public String getSourceUrl() { + return sourceURL; + } }; } public abstract void loadScript(ReactBridge bridge); + public abstract String getSourceUrl(); }