React Native running app on device without server - ios

Its unbelievable how bad the documentation is for React Native, they just put as little as possible for everything. I've already managed to run my app using option 1 but option 2 is even more unclear: https://facebook.github.io/react-native/docs/running-on-device-ios.html
I don't know there's no example of the terminal command react-native bundle in full so I know what is actually required there. For example --entry-file <path> what path? The whole path from my hard drive root to this folder, or just the file itself? --bundle-output....? What the hell do I need to put for that? I don't know why they need to make it so damn unclear.
I'm surprised there's no other resources online that give the instructions more clearly. I guess that's why there aren't so many React Native apps on the app store.

I hope you also find that this is a much easier approach. In the example below, my app was named BleMobileApp. Feel free to change it to your app's name.
RUN APP ON DEVICE WITHOUT DEBUG SERVER
Duplicate the main deployment target and name it BleMobileApp-Deploy.
Make sure to REMOVE the DEBUG=1 flag in BleMobileApp-Deply's Build settings (Do not touch the original target BleMobileApp!)
Add a New Run Script Phase to BleMobileApp-Deploy's Build phases and paste following command:
yes | cp -rf ${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app/main.jsbundle $SRCROOT/main.jsbundle
That's it!
(OPTIONAL) In case you would like to MINIFY the JS Bundle!
Edit file ./node_modules/react-native/scripts/react-native-xcode.sh like below (Line 43~47)
2. Change the default run script like below (For BleMobileApp-Deploy target):
export NODE_BINARY=node
FORCE_MINIFYING=true ../node_modules/react-native/scripts/react-native-xcode.sh
This should do the trick for you.
Happy coding!

From React Native Docs:
Configure release scheme Building an app for distribution in the App Store requires using the Release scheme in Xcode. Apps built for Release will automatically disable the in-app Developer menu, which will prevent your users from inadvertently accessing the menu in production. It will also bundle the JavaScript locally, so you can put the app on a device and test whilst not connected to the computer.
To configure your app to be built using the Release scheme, go to Product → Scheme → Edit Scheme. Select the Run tab in the sidebar, then set the Build Configuration dropdown to Release.

This can be done from the terminal:
react-native run-ios --device "My iPhone" --configuration Release

the best way i could find,
just follow the step bellow
Product → Scheme → Edit Scheme
Select the Run tab in the sidebar
Build Configuration dropdown to Release
sometimes metro bundle starts, may be its bug in IOS but you can close it
Please see the attached screenshot

Related

Could not get GOOGLE_APP_ID in Google Services file from build environment

For setting up firebase i am using two config 1.GoogleService-Info-test.plist, 2.GoogleService-Info-prdn.plist for UAT and Production. For installing crashlytics using firebase i have followed firebase documentation https://firebase.google.com/docs/crashlytics/get-started?authuser=1#ios. But when i try to run, it throws error in build phase while running script.
I tried without changing config file name and it worked.
Error msg at build phase while running fabric run script "Could not get GOOGLE_APP_ID in Google Services file from build environment".
Can anyone suggest better solution to achieve my requirement.
This is one way you can do it, by having your projects environments separated by targets, by doing so you can then add your different plist files and just check the target that they belong to, that way when you compile the target it will take it's corresponding plist file
Another way to do it, or to look up how to do it, it's called multiple environments with firebase, here are some helpful links
Use different GoogleService-Info.plist for different build schemes
https://medium.com/rocket-fuel/using-multiple-firebase-environments-in-ios-12b204cfa6c0
This worked for me:
When install Crashlytic with Firebase, for multiple scheme, you can have error Could not get GOOGLE_APP_ID in Google Services file from build environment. You can fix it by:
In Build Settings, add a user define for file name in User Defined:
In Build Phases, tap plus button, New Run Script Phase above your Crashlytic build phase, and type this code to the text field. Remember to rename %YOUR_CUSTOM_PATH_TO_FOLDER% to your path to Plist files:
GOOGLE_SERVICE_INFO_PLIST_FROM="${PROJECT_DIR}/%YOUR_CUSTOM_PATH_TO_FOLDER%/${FIREBASE_CONFIG_FILE}.plist"
BUILD_APP_DIR="${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}"
GOOGLE_SERVICE_INFO_PLIST_TO="${BUILD_APP_DIR}/GoogleService-Info.plist"
cp "${GOOGLE_SERVICE_INFO_PLIST_FROM}" "${GOOGLE_SERVICE_INFO_PLIST_TO}"
This worked for me:
Make sure you add the Xcode Crashlytics build phase after Copy Bundle Resources.
I had this in my "Build Phases" and it's works
"${PODS_ROOT}/FirebaseCrashlytics/run"
"${PODS_ROOT}/FirebaseCrashlytics/upload-symbols" -gsp "${PROJECT_DIR}/MyApp/GoogleService-Info.plist" -p ios "${DWARF_DSYM_FOLDER_PATH}/${DWARF_DSYM_FILE_NAME}"
Our project only one target, but we need to use two Firebase config files GoogleService-Info-Prod.plist and GoogleService-Info-Dev.plist.
I had this in my "Build Phases" and it works.
if [ "${CONFIGURATION}" = "Release" ]; then
${PODS_ROOT}/FirebaseCrashlytics/run -gsp ${PROJECT_DIR}/RushCard/FirebaseConfig/GoogleService-Info-Prod.plist
else
${PODS_ROOT}/FirebaseCrashlytics/run -gsp ${PROJECT_DIR}/RushCard/FirebaseConfig/GoogleService-Info-Dev.plist
fi
In my case I created New Run Script Phrase above Compile Sources, that's why I always see
Could not get GOOGLE_APP_ID in Google Services file from build environment
When I moved Crashlytic's run script at the end of list bug was disappear. Please look the following screen shot:
And article about it is here
I use multiple configurations for several white-labelled apps. I added a User-Defined variable FIREBASE_SUFFIX and changed my script to the following:
${PODS_ROOT}/FirebaseCrashlytics/run -gsp ${PROJECT_DIR}/Firebase/GoogleService-Info-${FIREBASE_SUFFIX}.plist
NOTE: I use Carthage for firebase here: https://github.com/firebase/firebase-ios-sdk/blob/master/Carthage.md. If you're this same setup, you should use something like this instead (replace the path to where you put your script files):
${PROJECT_DIR}/scripts/run -gsp ${PROJECT_DIR}/Firebase/GoogleService-Info-${FIREBASE_SUFFIX}.plist
Another way is to make sure one plist keeps the original name GoogleService-Info.plist
Different targets meant more work to update CI for me.
This is valid for Xcode 11 at least, not tested on any other versions
I was using new Firebase/Crashlytics which beta and getting error "No Google App ID or Google Services file provided" when I try to upload manually dSYMS
Here is command:
/path/to/pods/directory/FirebaseCrashlytics/upload-symbols
-gsp/path/to/GoogleService-Info.plist -p ios /path/to/dSYMs
Then I reliaze there should be space between "-gsp" and path to Google.plist after that It worked.
The solution for me was removing the call to upload-symbols script.
One of the Crashlytics guides mentions you should add this:
${PODS_ROOT}/FirebaseCrashlytics/run
/path/to/pods/directory/FirebaseCrashlytics/upload-symbols <- Not needed
I misinterpreted this... the run script already calls upload-symbols so there's no need to add a second call.
Make sure in Xcode file explorer (i.e on the left side) "GoogleService-Info.plist" is showing. If not you have to drag and drop "GoogleService-Info.plist" in the Xcode panel.
In my case problem is I copy-pasted the file in the project location, due to this file reference is missing in the Project info.
Well all above answers purpose a possible solution for this issue, in my case GoogleService.plist file was missing from 'Copy Bundle Resources' by adding into it worked in my case..
To check the file goto
Project Directory >> Build Phases >> Copy Bundle Resources
add it add here if you find missing.
If these solutions provided above do not work, I solved mine by going to Build phases as shown on this image. Click on plus and add Google plist
I was able to fix this by locate where is my GoogleService-Info.plist, copy it to ios folder in Flutter and run with this script
"$PODS_ROOT/FirebaseCrashlytics/upload-symbols" --flutter-project "$PROJECT_DIR/firebase_app_id_file.json" -gsp "$PROJECT_DIR/GoogleService-Info.plist" -p ios "$DWARF_DSYM_FOLDER_PATH/$DWARF_DSYM_FILE_NAME"
Update:
I found a better solution:
Just upgrade all firebase package to lastest version
Remove Crashlytics build script
Run flutter clean, flutter pub get
pod install (in ios folder)
I had this issue because I didn't download GoogleService-Info.plist file from Firebase console.
If you have your project on Firebase but missing this file in Xcode, don't worry, you don't need to do the setup again from the beginning. Just go to:
Project Settings > General > Scroll down and in the "Your Apps" panel you will see the file and you can download it and import it in the Xcode project.
I had the same error, also due to the fact that I have multiple bundle identifier and therefore I have a build phase script called Firebase Script (that pinpoints to the correct GoogleService-Info.plist ) that was running after the Crashlytics script.
The solution is to run Firebase Script before the Crashlytics script.
In my case I had a different name in my file, his name was GoogleService-Enterprise-Info.plis when I change it to the normal name GoogleService-Info.plist, IT WORK FINE !!
I faced the same issue for #react-native-firebase/crashlytics
In case you are facing this issue, you probably have missed the 'ios setup' instruction mentioned in below link. Please follow the instruction to fix the issue.
https://rnfirebase.io/#generating-ios-credentials
Just download from Settings of your projects and place for your correct target which you are running.
This error would be shown if there is a space in your project name or in the path of your project.
Read more in this GitHub Issue
Additionally to other answers..
I faced that problem with exact same error message and in my case everything was ok with file GoogleService-Info.plist except that it was genereated with wrong Bundle ID for application (it was changed in XCode much later than initial Firebase setup happened), so I had to create new app in Firebase Console with correct Bundle ID (it's not able to edit) and download new GoogleService-Info.plist
If you are using one of the popular build scripts going around for handling multiple different environments, it is probably useful to know that you should use a different GoogleService-Info.plist destination based on the target platform:
// iOS
PLIST_DESTINATION=${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app
// watchOS
PLIST_DESTINATION=${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.appex
// macOS
PLIST_DESTINATION=${BUILT_PRODUCTS_DIR}/${CONTENTS_FOLDER_PATH}/Resources
Ultimate guide:
Assure that in Runner folder you have file GoogleService-Info.plist and it is attached in your project
If you don't have this file go to Firebase Console, add you IOS app and download the GoogleService-Info.plist file, then add it to you project's Runner folder by XCode.
If there is no such file in XCode but it exists physically in the folder then right click on Runner folder (in Runner project) -> Add files to Runner -> Select that file
If you want to use multiple flavors add ENV_SUFFIX in Runner (target) -> Build Settings -> User-Defined (on the bottom)
Still in the target's Runner change tab to Build Phases -> Press Plus button -> New Run Script Phase -> Name it as Copy GoogleService-Info.plist and add this line
cp Runner/GoogleService-Info_${ENV_SUFFIX}.plist Runner/GoogleService-Info.plist
IMPORTANT! This script has to be before Initialize Crashlytics step or any other Firebase related script (you can drag it to the top)
Add other GoogleService-Info.plist files with suffix for the env. In my case those would be the _dev _prod and _tst files from the first screen shot
Enjoy multiflavor app
Try downgrading, it worked for me!
I used:
'Fabric', '1.9.0'
'Crashlytics', '3.12.0'

Add value to Info.plist array after building (but before installing)

I have an Xcode project that builds into a few different apps (whitelabels) using different configurations.
For a new payment method I need each app to have a unique CFBundleURLScheme.
I wrote the following "Run Script" that is before Compile Sources in "Build Phases".
INFO_PLIST="${PROJECT_DIR}/${INFOPLIST_FILE}"
plutil -insert CFBundleURLTypes.0.CFBundleURLSchemes.0 -string "swish${PRODUCT_BUNDLE_IDENTIFIER//.}" $INFO_PLIST
This adds the value swishourbundleidentifier. (So, swish + our.bundle.identifier, but without the dots)
This currently changes the actual Info.plist. What I want is that it changes the Info.plist that's in the folder where the app is built to, so that it is overridden each time (so there are no double values) and that the added value doesn't show up in git.
How would I go about that? I guess it's simply changing "${PROJECT_DIR}/${INFOPLIST_FILE}", but to what?
If any more information is needed, please let me know.
EDIT: Actually, if it is possible, a better solution would be to add something like swish${PRODUCT_BUNDLE_IDENTIFIER//.} in the Info.plist's URL Schemes. So that it's compiled to that on build time, but no double values. I tried this but it doesn't seem to work like that unfortunately.
You could access to build directory with
$CONFIGURATION_BUILD_DIR/$CONTENTS_FOLDER_PATH
Reference: https://help.apple.com/xcode/mac/10.2/#/itcaec37c2a6
(Xcode 11.2)
It is possible to do what you're asking:
You can get the path of the app bundle's Info.plist at ${TARGET_BUILD_DIR}/${INFOPLIST_PATH}.
BUT: In the New Build System, any custom build steps will run before the New Build System's Process .../Info.plist step, so you cannot edit the app bundle's plist via a Run Script step to Build Phases, because your changes will just be overwritten:
To run a shell script after Xcode finishes building, you can add it to your scheme(s) as a build post-action:
Product > Scheme > Edit Scheme... > Build > Post-actions
If you're going to reference any build system environment variables (e.g. BUILT_PRODUCTS_DIR or INFOPLIST_PATH), make sure you select your app target in Provide build settings from.
Add your shell script, but remember that if you edit any file in the app bundle (i.e. Info.plist), you'll need to re-sign the app. Add this to your script:
export CODESIGN_ALLOCATE=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate
/usr/bin/codesign --force --sign - --entitlements "${TARGET_TEMP_DIR}/${FULL_PRODUCT_NAME}.xcent" --timestamp=none "${CODESIGNING_FOLDER_PATH}"
App bundle is read-only. Info.plist is in app bundle

React Native - launchPackager.command cant be opened

I am having trouble building react native ios project.
Error message:
"launchPackage command" can't be opened because it is from an unidentified developer.
Any idea how to fix this?
Although this answer will most likely work, you would also allow all future apps from unidentified developers to be installed without being prompted.
To allow executing only the command in question (launchPackager.command), go to your react-native installation folder (most likely node_modules/react-native/scripts) in Finder and right-click launchPackager.command, choose Open and confirm by clicking Open again.
You will not be prompted again for this command as you have allowed execution specifically.
Another simple way is to delete node_modules folder from project directory and do npm install.
This happened because project was copied from old mac which had node_modules folder created by that old mac user, hence some problem occurs for project transferred to new mac.
Had the same problem on macOS Mojave.
This helped:
chmod 777 node_modules/react-native/scripts/launchPackager.command
on MacOS Catalina and above
Go to
System Preferences
Security & Privacy
Choose tab "Privacy"
Select "Developer Tools" on left pane
Check "Terminal" to allow terminal to run software locally which does not meet system's security policy . (please be aware of potential implications of this action and make sure that you know what you are doing )
Go to
System Preferences
Security & Privacy
Choose tab General
Choose Allow apps downloaded from anywhere or Allow apps downloaded from App Store and identified developers
I had the same error with you and this method worked for me.
chmod 777 node_modules/react-native/scripts/launchPackager.command
open terminal and Run the above command
after that Run the react-native run-android
Works for Me, It will Run :)
The reason is because you downloaded source code using virtual machine.
Solution:
Please download source code at your real machine.
And then copy it at VM, and build this project.

Where is the Run Script and Build Phase in Xcode?

To get Carthage set up, the documentation says that you need to add a Run Script.
On your application targets’ “Build Phases” settings tab, click the
“+” icon and choose “New Run Script Phase”. Create a Run Script in
which you specify your shell (ex: bin/sh), add the following contents
to the script area below the shell:
/usr/local/bin/carthage copy-frameworks
and add the paths to the frameworks you want to use under “Input
Files”, e.g.:
$(SRCROOT)/Carthage/Build/iOS/Box.framework
$(SRCROOT)/Carthage/Build/iOS/Result.framework
$(SRCROOT)/Carthage/Build/iOS/ReactiveCocoa.framework
This script works around an App Store submission bug triggered by
universal binaries and ensures that necessary bitcode-related files
and dSYMs are copied when archiving.
However, I can't find the Build Phases tab anymore or Run Script in the Build Settings search. The Xcode 8 Release Notes mention
Xcode 8 provides completely rewritten AppleScript support. A new
scripting dictionary provides the ability to automate Xcode workflows.
Does that mean there is no more Run Script? I looked at AppleScript but honestly it looks overwhelmingly complex. Do I need to learn AppleScript just to add the simple one liner that I used to do in Xcode?
/usr/local/bin/carthage copy-frameworks
It is still there. Make sure you click everywhere indicated in red in the image below.
Carthage maintainers updated README, it is necessary to add output paths too to prevent useful copying of frameworks. I have released simple script named Carting to automate these steps.

Crashlytics in iOS won't proceed past "Build Your Project" in Fabric app

I'm installing Crashlytics for my iOS app. I downloaded it via their site link, and went through all the steps for integrating the frameworks, adding the run script, etc.
I was experiencing an issue, so I removed the frameworks and decided to start over and try a fresh install. But the Fabric app updated to a newer version, and now when I try to reinstall Crashlytics into my app, it doesn't give me the option to reinstall the frameworks. It goes straight from clicking "install" to the "Build your project" screen, which I cannot pass.
To help configure your project, please build it now by pressing ⌘B
I press ⌘B, it builds and nothing happens. I think the issue is because I removed the Crashlytics and Fabric frameworks from my project, but I can't see a way to add them back again. The Fabric app doesn't give me that option.
Go into Build settings of the your target.
Find "Debug Information Format".
Set this from "DWARF" in both debug and release to "DWARF with dSYM File"
Moving from Comment to Answer.
Mike from Fabric here. If you back up through the Mac app, then click on the arrow in the top-left, click on "+ New App", that will walk you through re-adding everything.
If you check the resource navigator you may see the following message:
"DEBUG_INFORMATION_FORMAT should be set to dwarf-with-dsym for all configurations. This could also be a timing issue, make sure the Fabric run script build phase is the last build phase and no other scripts have moved the dSYM from the location Xcode generated it. Unable to process eCreditWebWrapper.app.dSYM at path"
Go to Build Settings and search for "Debug Information Format". Ensure "Debug" is set to "DWARF with dSYM File".
Without the dSYM file Fabric won't work.
As for Xcode 10.2.1, the automated installation via Fabric Mac app won't work anymore. New apps cannot be added via the New App Step-by-step guide.
You have to follow the manual installation instructions. Download and add the 2 frameworks into your Xcode workspace, then add the Run Build Script phase (and related Fabric codes), then build the App. Last (very important), run the app in an actual device.
Once the App is successfully launched, the new App information will be available in the Fabric dashboard as well as the Fabric Mac App (needs to relaunch the App to see the new app).
Here are the steps:
Download the 2 frameworks
Drag to your project where your App Delegate is (make sure ticked "Copy items if needed")
Compile the project / workspace in Xcode
Add the "Run Script Phase" as instructed here; note that Xcode 10+ requires an extra configuration at Input Files
Add the required import and initialization codes in App Delegate
Add the Fabric API keys in Info.plist
Compile again
Run the App in a real device. You will see the line Crashlytics in the Xcode log. If no log appears, checks if your active scheme contains OS_ACTIVITY_MODE settings. Set it to default if the current setting is disabled.
If the Crashlytics line appears, that means the manual installation is working; you will see your App appearing at Fabric online dashboard.
I have solved this issue by the following way. Following the advise from above, I began adding a new app to crashlytics. When I reached to adding new "Run script" build phase, I just copied that text and pasted it over the previous one(created with Crashlytics).
I have also unchecked "Run script only when installing".
After this, I canceleed adding a new app and procedeed back to the UPGRADE. At this moment, building the app, can pass you to the next step and you don't get stuck on that screen anymore.
I was stucked on Build phases too.
I have also unchecked "Run script only when installing" and press again command+B and then I passed to the next step.
If the script is not running, you may have checked the "run script only when installing" in the run script section.
I hope it helps
TL;DR
Tap your scheme -> edit scheme -> set build configuration to "Release"
Explanation:
The most voted answer sounds about right, but there are situations where you just don't need crashlytics in debug builds (who wants crashes sent when you just develop and experiment with your code?). In this case you should disable crashlytics by checking debug compilation flags (out of scope of this answer) and for the first time during installation build app for release to let crashlytics know that you built app.
I had the same issue today. The problem was that i didn't have the run-script :
./Fabric.framework/run <api key>
in my project. Once i put this back in then it all worked perfectly. I also cleaned my project and deleted derived data just to be sure.
you must check that your deployment target version because of "Fabric's minimum iOS version is 6.0"
I was only able to get the Fabric app to continue the installation process after setting my build target to 'Generic iOS Device' and creating an archive from the Product > Archive menu.
Simply building the app or running it on an emulator doesn't seem to trigger the Fabric App to proceed.
If you use Xcode 10.
Project Navigator -> your project -> Targets -> Build Phases -> your Run Script for Fabric -> Input Files -> "+" (add input file) -> clear field and past this line:
$(BUILT_PRODUCTS_DIR)/$(INFOPLIST_PATH)
Be sure to remove this: $(SRCROOT)/
In the Run Script build phase there is a call:
./Crashlytics.framework/run <your_api_key_here>
Maybe you added some conditions to trigger it only on certain builds like:
releaseConfig="Release"
if [ "$releaseConfig" = "${CONFIGURATION}" ]; then
echo "Running Crashlytics"
./Crashlytics.framework/run <your_api_key_here>
fi
so that it will not just trigger on ⌘B
See https://dev.twitter.com/crashlytics/ios/advanced-setup
In my situation I was following all the steps correctly but got stuck on 'add build phase' step.
Then I just restarted fabric and all works just fine
Also there are some other possible actions:
1) Just restart Fabric, Xcode and your Mac.
2) Also if you use Cocoapods change build phase line from
./Crashlytics.framework/run [yourAPIKey]
to
"${PODS_ROOT}/Fabric/run" [yourAPIKey]
3) After building project if Fabric will stop responding just wait a while. It took about minute on my Mac.
Thanks, I solved the problem by removing folders:
~ / Library / Caches / com.crashlytics.data
~ / Library / Caches / com.crashlytics.mac
Kindly cross verify that run script you adding is to your actual target if u will add to tests target it will not proceed until you add it to actual target
None of the solutions here worked for me. The scenario for me was someone else added the Fabric framework to our project and committed it to the repo. The run script on their computer launched/triggered the Fabric Plugin, but would not launch/trigger on mine, although it did not report errors.
The solution was to create a separate project, using Cocoapods download the same version of Fabric, replace the run script in our project/repo (and the one referenced in the target's run script) with the downloaded version from Cocoapods. Rebuild and then the plugin would respond.
Comparing the two run script files, they are drastically different, but the run script from Cocoapods was not a flat text file and it was unreadable. So I'm not sure what was different between the scripts, but we somehow got different versions of the script while using the same version of Fabric.
What I did wrong was adding the script to the pods project build phase instead of the main project build phase, adding it to the main projects build phase solved the problem.
If you are duplicating the target, remove the run script from build phase and add it again to solve the issue.
If you have multiple TARGETS,
check your Schema selection is correct before you build project.
For Xcode 10. Add your app's built Info.plist location to the Build Phase's Input Files field:
$(BUILT_PRODUCTS_DIR)/$(INFOPLIST_PATH)
This solved my issue i hope this can solve others issue.
It turned out I had not enough permissions to create new project in Fabric.
Upgrading from Member to Admin resolved the issue.
In my case, removing an app from helped.
1) Remove the app from Fabric.
2) Follow all the steps again to add the app and install Crashlytics.
Nothing helped me. Now Fabric catches my archive creation. But I create the archives via fastlane's build_app.
Open Project in higher version of Xcode. This resolved my issue after waste many hours.
My Project build on Xcode 10.2 and I was running on Xcode 10.1 but when I run the same project on Xocode 11. The build was succeeded.
Try to wrap your run script variable with double quotes ""
"${PODS_ROOT}/Fabric/run"
Go to folder /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/<CURRENT_IOS_SDK>/usr/lib/ and delete all .dylib files.
It worked for me.

Resources