iOS Mobile App Build Fix Procedure
This document outlines the definitive, repeatable procedure for fixing build issues in the React Native / Expo mobile apps within this monorepo. This “wipe and rebuild” strategy should be followed for any app that fails to build or run, especially after initial setup or significant changes.
This procedure is based on the “known-good” configuration of the altFinder_app-mobile and bonjour_it_com-mobile applications. By following these steps, we are standardizing all other mobile apps to match the setup of the ones that are confirmed to build and run successfully.
The core issues this procedure resolves are:
- Incorrect CocoaPods autolinking commands in the
Podfile. - Build failures related to
AppDelegate.swiftand the React Native New Architecture. - Network errors during the
expo prebuildstep that prevent clean rebuilds.
The Fix Procedure
Section titled “The Fix Procedure”Follow these steps exactly for each mobile app that needs to be fixed.
1. Clean and Rebuild the ios Directory
Section titled “1. Clean and Rebuild the ios Directory”This step wipes the existing native iOS project and regenerates it from scratch. We must force the command to use yarn to bypass a known npm network error.
Replace <app-name> with the name of the app you are fixing (e.g., bonjour_locker-mobile).
NPM_CONFIG_USER_AGENT="yarn" yarn nx run <app-name>:prebuild --clean2. Replace the AppDelegate
Section titled “2. Replace the AppDelegate”The default AppDelegate.swift generated by Expo is incompatible with our setup. It must be replaced with the standard Objective-C++ version.
-
Delete the Swift file:
Terminal window rm apps/<path-to-app>/mobile/ios/<project-name>/AppDelegate.swift(Example:
rm apps/bonjour_services/bonjour_locker/mobile/ios/bonjourlockermobile/AppDelegate.swift) -
Create
AppDelegate.h: Create a new file namedAppDelegate.hin the same directory with the following content:#import <Expo/Expo.h>#import <React/RCTBridgeDelegate.h>#import <UIKit/UIKit.h>@interface AppDelegate : EXAppDelegate <RCTBridgeDelegate>@end -
Create
AppDelegate.mm: Create a new file namedAppDelegate.mmin the same directory with the following content:#import "AppDelegate.h"#import <React/RCTBundleURLProvider.h>@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{self.moduleName = @"main";// You can add your custom initial props in the dictionary below.// They will be passed down to the ViewController used by React Native.self.initialProps = @{};return [super application:application didFinishLaunchingWithOptions:launchOptions];}- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge{#if DEBUGreturn [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.js"];#elsereturn [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];#endif}@end
3. Correct the Podfile
Section titled “3. Correct the Podfile”The prebuild command may still generate a Podfile with an incorrect autolinking command. We need to ensure it uses the correct Node.js evaluation script.
-
Open the
Podfile: Located atapps/<path-to-app>/mobile/ios/Podfile. -
Find and Replace the
config_command: Locate the line that starts withconfig_command =. It will look something like this:config_command = ['npx', 'expo-modules-autolinking', 'ios', '--platform', 'ios', '--json', '--search-paths', pod_search_paths.join(',')]Replace it with this exact line:
config_command = ['node', '--eval', "require('expo/scripts/autolinking').createConfigAsync({ platform: 'ios' }).then(c => console.log(JSON.stringify(c)))", '--', '--search-paths', pod_search_paths.join(',')]
4. Install Pods
Section titled “4. Install Pods”Finally, navigate to the ios directory and run pod install.
cd apps/<path-to-app>/mobile/ios/pod installAfter these steps are complete, the app should build and run successfully.