Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot create offline bundle for react native (iOS)

Hi I was trying to create a offline bundle for react native iOS for testing using the following code

react-native bundle --entry-file index.js --platform ios --dev false --bundle-output ios/main.jsbundle --assets-dest ios

After doing this I tried to run the app using the command react-native run-ios --configuration=release once it is done the app opens and crashes instantly. So I used react-native run-ios this time the app opens with the local development server, if I terminate the development server then I will be getting Unhandled JS Exception error. For Android I tried the following steps to make it work.

  1. mkdir android/app/src/main/assets
  2. react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
  3. react-native run-android

Even if I terminate the local development server the app will work in Android. Any help for building offline bundle for iOS is appreciated.

Edit 1:

After bundling for iOS using the command

react-native bundle --entry-file index.js --platform ios --dev false --bundle-output ios/main.jsbundle --assets-dest ios

I'm able to generate main.jsbundle inside iOS directory and then followed the following steps.

  1. Removed all the App Transport Security Settings and added Allow Arbitrary Loads(true) inside Info.plist file.

  2. Edited the Run Edit Scheme to Release

  3. Changed the jsCodeLocation from

    jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];

to

jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
  1. Product -> Build

After following the above steps I'm getting the following error

File /Users/jeffreyrajan/Library/Developer/Xcode/DerivedData/app_prod-fnewtufemaynsoedmhggmfjynoti/Build/Products/Release-iphonesimulator/app_prod.app/main.jsbundle does not exist. This must be a bug with
+ echo 'React Native

Here is the screenshot of the whole error enter image description here

Here is the project structure

enter image description here

Current Version:

  • React : 16.0.0
  • React Native : 0.51.0
  • Xcode:9.2
like image 586
Jeffrey Rajan Avatar asked Jan 11 '18 14:01

Jeffrey Rajan


1 Answers

It appears that the build script that runs the bundler command does not handle whitespace characters in file paths correctly. I can see from the screenshot you posted that the path to your project contains a space character in the React-Native Projects directory.

If you rename the directory to e.g. React-Native-Projects, the Archive build will work correctly.

In general, it's a good developer practice to limit directory and file names to alphanumeric characters, because many Unix tools require escaping other character types.

like image 199
jevakallio Avatar answered Sep 19 '22 22:09

jevakallio