Reputation: 1400
I have react native project and it works fine on both simulator and device.
But I notice that when I try to run my project(on device) while my computer is turned off, I can't run the project.
I works fine when my computer is powered on.
Any idea why this is happening and how to fix it?
Upvotes: 1
Views: 416
Reputation: 2638
Your application is not working because of bundle is not working in an offline state (node server is closed).
Android Build(apk)
Now Create offline js bundle with this following command.
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/
Now run this command to create offline resource files and others
cd android && ./gradlew assembleRelease
Open ~/android folder using Android Studio and you have your stand alone android application.
IOS Build(IPA)
Before creating bundle please check AppDelegate.m file For IPA building we need to static bundle which worked on offline mode
#if DEBUG
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
Creating an Offline Bundle
react-native bundle --dev false --entry-file index.ios.js --bundle-output ios/main.jsbundle --platform ios
Now we open Xcode and perform the following actions
1 Product -> Clean
2 Product -> Archive
Then you have to go for Product -> Archive in Xcode and follow the steps based on your desired release
Upvotes: 1