Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a offline build for Testing: React Native

I have developed an app using React Native. But I want to give for testing to end user. So how can we create a build that loads all assets and JS files without localhost?

I searched on Google to find solutions. I got an answer that below command will help me.

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

But it won't help me anymore. Can anyone help to create a local build in iOS?

like image 839
Nirmalsinh Rathod Avatar asked Sep 18 '17 06:09

Nirmalsinh Rathod


1 Answers

I found my answer after doing research for last 2-3 days. Hope it will help for all React-Native developer.

Here is the answer:

--> Start your npm server to your local system using below command:

sudo npm run start

--> Above command will start your development server. Now we have to create js bundle using the following command to connect our application to js build directly:

For iOS:

$curl http://localhost:8081/index.ios.bundle -o main.jsbundle

For Android:

$curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"

Above two steps will create js bundle for iOS and Android in main folder. Now follow the below step to generate an IPA and APK file.

For iOS:

--> Open your xcodeproj from your ios folder. Add drag main.jsbundle to your xcode project.

--> Open AppDelegate.m file and you can bundle is loaded using one for below line of code.

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

or

jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle"];

Just comment above line which is there in your code and put below line of code:

jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];

Now, you are good to go with iOS……

For Android:

Open a terminal and go to your project repo path. Compile your project using below command:

./gradlew assembleRelease

To install APK into your device:

adb install {PATH_TO_APK}

Now you are ready to go with Android too..

Hope this is will to all my kind of person….

like image 120
Nirmalsinh Rathod Avatar answered Sep 26 '22 07:09

Nirmalsinh Rathod