Expo Branch crash on Android

In my managed app, Android production builds crash on launch. It seems to have something to do with expo-branch, but I’m not sure how. This was built with EAS. Any help appreciated!

FATAL EXCEPTION: create_react_context
 Process: io.melange.melange, PID: 24480
 java.lang.IllegalStateException: Native module RNBranch tried to override RNBranchModule. Check the getPackages() method in MainApplication.java, it might be that module is being created twice. If this was your intention, set canOverrideExistingModule=true. This error may also be present if the package is present only once in getPackages() but is also automatically added later during build time by autolinking. Try removing the existing entry and rebuild.
 	at com.facebook.react.NativeModuleRegistryBuilder.processPackage(NativeModuleRegistryBuilder.java:55)
 	at com.facebook.react.ReactInstanceManager.processPackage(ReactInstanceManager.java:1347)
 	at com.facebook.react.ReactInstanceManager.processPackages(ReactInstanceManager.java:1318)
 	at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1225)
 	at com.facebook.react.ReactInstanceManager.access$1100(ReactInstanceManager.java:131)
 	at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:1016)
 	at java.lang.Thread.run(Thread.java:919)

Relevant package.json dependencies:

    "expo-branch": "~4.1.0",
    "expo": "^41.0.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-41.0.0.tar.gz",

App.tsx:

// imports...
const Branch = require("./src/constants/branchConfig");
//imports ....

// config...

// LINKING AND BRANCH SETUP
const prefix = Linking.createURL("/");

const linking: LinkingOptions = {
	prefixes: [prefix], 
	config: config,
	subscribe(listener) {
		const onReceiveURL = (obj: { url: string }) => {
			let parsedURL = obj.url;
			
			if (typeof obj.url === "string" && parsedURL.startsWith("melange://")) {
				parsedURL = parsedURL.replace("melange://", "");
				parsedURL = parsedURL.replace(/\?.*/, "");
			}

			if (typeof obj.url === "string" && parsedURL.startsWith("https:")) {
				WebBrowser.openBrowserAsync(parsedURL);
			} else {
				listener(`${prefix}${parsedURL.toString()}`);
			}
		};


		Linking.addEventListener("url", onReceiveURL);

		// Listen to expo push notifications
		const subscription = Notifications.addNotificationResponseReceivedListener((response) => {
			const url = response.notification.request.content.data.url;
			// Let React Navigation handle the URL
			listener(`${prefix}${url}`);
		});


		if (Constants.appOwnership === "standalone" || !Constants.appOwnership) {
			Branch.subscribe(({ error, params, uri }) => {
				if (error) {
					console.error("Error from Branch: " + error);
					Alert.alert(`error: ${error}`);

					return;
				}

				if (params["+non_branch_link"]) {
					const nonBranchUrl = params["+non_branch_link"];
					return;
				}

				// A Branch link was opened
				const canonurl = params.$canonical_url;
				const url = params.$url;

				if (url || canonurl) {
					listener(`${prefix}${url}`);
				}

			});
		}

		return () => {
			Linking.removeEventListener("url", onReceiveURL);
			subscription.remove();
			if (
				(Constants.appOwnership === "standalone" || !Constants.appOwnership) &&
				Branch?.unsubscribe
			) {
				Branch.unsubscribe();
			}
		};
	},
};

export default function App() {
    return (
				<NavigationContainer
					theme={{ colors: { background: siteColor } }}
					ref={navigationRef}
					onReady={handleReady}
					onStateChange={handleStateChange}
					linking={linking}
					fallback={<Loading />}
				>
                                <Tabs /> 
				</NavigationContainer>
		);
}

branchConfig.ts:


import Constants from "expo-constants";

if (Constants.appOwnership && Constants.appOwnership !== "standalone") {
	module.exports = {
		BranchEvent: function (eventName, buo) {
			this.logEvent = function () {
				console.log(eventName); 
			};
		},
	};
} else {
	const Branch = require("expo-branch")
	module.exports = Branch.default;
}

I’ve tried running npm install && expo update, which does not fix the issue.

We are probably having the same issue.

I’m getting false in Constants.appOwnership === "standalone", for standalone apps with eas.

Were you able to fix it?

I had that issue separately. Is appOwnership null? I changed my environment check to

if (Constants.appOwnership === "standalone" || !Constants.appOwnership) ...

which solved that problem. Shout if that works for you!