React/RCTEventEmitter.h file not found - react-native

I am trying to implement PushNotificationIOS with a detached Expo app. I am running SDK 21.0.0 (React Native 0.48).
I am getting React/RCTEventEmitter file not found
I have completed the following steps:
Open my .xcworkspace project
Drag the RCTPushNotification.xcodeproj into my Libraries folder
Added libRCTPushNotification.a into App > Build Phases > Link Binary With Libraries
Added $(SRCROOT)/../node_modules/react-native/Libraries under Header Search Paths - I also tried without the /../. I have a bunch of Pods in the Header Search Paths list too.
I then added the following into AppDelegate.m but when I click through to the file (⌘ + click), I get a question mark.
#import <React/RCTPushNotificationManager.h>
If I change it to the below, it works, I can click through
#import "RCTPushNotificationManager.h"
However, this is my problem
When I clean and build my project, I get the below error in RCTPushNotificationManager.h to say:
'React/RCTEventEmitter.h' file not found

#Dan I have ran into this exact same issue, it also occurs for RCTLinking, and other libraries dependent on eventEmitter.h and a detached Expo project.
The issue turns out to be that RCTPushNotification doesn't have the reference to React from Cocoapods file React since Expo manages React in Cocoapods. So you should go into RCTPushNotification.xcodeproj then into Targets - RCTPushNotification Header Search Paths and add the link to "ios/Pods/Headers/Public/React" and set to recursive.
The easiest way to do the above is navigate to your iOS/Pods/Headers/Public/React and drag and drop the folder straight into build settings for header search paths like the below image.
Heads up finally after this you will have to reference ReactCommon/yoga most likely as well, ReactCommon/yoga however should be in your 'node_modules/react-native/ReactCommon/yoga'

This works for me on detached Expo project
"react": "16.6.3",
"react-native": "0.58.6",
Add 'RCTPushNotification' to your pod and run pod install
pod 'React', :path => '../node_modules/react-native', :subspecs => [
'RCTPushNotification',
]

Since nothing mentioned above worked for me, I started experimenting, and this is what solved it for me:
1. Link React-Core & Public
As mentioned by Escamilla, in xcode open the RCTPushNotification.xcodeproj and under Build Settings search for header search path and add there the 2 path:
"$(SRCROOT)/../../../../ios/Pods/Headers/Public"
"$(SRCROOT)/../../../../ios/Pods/Headers/Public/React-Core"
2. Copy RCTPushNotificationManager.h manually into React-Core
In the root folder of your project execute:
cp ./node_modules/react-native/Libraries/PushNotificationIOS/RCTPushNotificationManager.h ./ios/Pods/Headers/Public/React-Core/React
This will copy RCTPushNotificationManager.h wich is in node_modules/react-native/Libraries/PushNotificationIOS/ manually into the React folder which is in ios/Pods/Headers/Public/React-Core/React.
I have no idea if that is a good solution but it works. Maybe if someone could explain me why it was not in there in the first place? That would be golden.
I followed the setup instructions 1 by 1 very carefully doing everything right but nothing worked except the manual copy mentioned above…
Also, this is randomly resetted once in a while and has to be done again -.-'

Open up your project in XCode.
Open up the Libraries folder. You should see React.xcodeproj and several RCT*.xcodeproj.
Drag the React.xcodeproj into each of the other projects.
Click on each project and navigate to the Build Phases tab.
Click on Target Dependencies and add React as a target dependency

Just follow these steps:
create project react-native init project.
add this line to pod file in ios folder: pod 'React-RCTPushNotification', :path => '../node_modules/react-native/Libraries/PushNotificationIOS'
cd ios && pod install
cd .. && react-native run-ios
No need to do messy manual linking

Replace #import RCTEventEmitter.h or #import React/RCTEventEmitter.h with #import <React/RCTEventEmitter.h>
Its work for me

this worked for me!
add the missed lib manually
https://github.com/microsoft/react-native-code-push/issues/1565#issuecomment-489738672

USE those libraries:
https://github.com/zo0r/react-native-push-notification
https://github.com/react-native-community/react-native-push-notification-ios
follow step by step,
everything will work
no need anything else
not forget to
pod install

Related

React Native: Invariant Violation when using "React-Native-FS"

I have been trying to use "React-Native-FS" while developing a react native application. However, whenever I try to import "React-Native-FS" to my app I get the following message:
Invariant Violation: Native Module Cannot Be Null
Does anyone have any clue what could be causing this? I've searched around and can't find an answer. Any help would be greatly appreciated. Thanks!
try to do link your library with
react-native link react-native-fs
if its not linked try to do manually linking with below step
ANDROID
... 1. android/settings.gradle
include ':react-native-fs'
project(':react-native-fs').projectDir = new File(settingsDir,'../node_modules/react-native-fs/android')
2.android/app/build.gradle
dependencies {
implementation project(':react-native-fs')
}
ANd do build android project with android studio
IOS
Adding with CocoaPods
Add the RNFS pod to your list of application pods in your Podfile, using the path from the Podfile to the installed module:~~
pod 'RNFS', :path => '../node_modules/react-native-fs'
Install pods as usual:
pod install
Adding Manually in XCode
In XCode, in the project navigator, right click Libraries ➜ Add Files to [your project's name] Go to node_modules ➜ react-native-fs and add the .xcodeproj file
In XCode, in the project navigator, select your project. Add the lib*.a from the RNFS project to your project's Build Phases ➜ Link Binary With Libraries. Click the .xcodeproj file you added before in the project navigator and go the Build Settings tab. Make sure 'All' is toggled on (instead of 'Basic'). Look for Header Search Paths and make sure it contains both $(SRCROOT)/../react-native/React and $(SRCROOT)/../../React - mark both as recursive.
Run your project (Cmd+R)

How can I change the project and app name of ReactNative project with react-native 0.60

It's simple issue but I don't know how to do it. I'm looking for some references, but there are problems.
I'm using react-native : 0.60.5. Hence there is no eject method or command.
The project was not created with expo.
After I referenced How to Rename A React Native App and error Unrecognized command "eject", then I follow the process below.
change the app.json's name and diplayName field to name which I want to change
remove android/ and ios/ directory
use react-native upgrade --legacy true
But there is no change on the project name and app name.
Is there any way to change the project and app name? Thanks.
Please check the below steps :
if you want to change both the app name and the package name (i.e. rename the entire app), the following steps are necessary:
Make sure you don't have anything precious (non-generated, manually
copied resources) in the android/ and ios/ subfolders.
Delete both the android/ and ios/ folder.
Change the "name" entry in your package.json to the new name.
Change the app name in both your index.android.js and index.ios.js:
AppRegistry.registerComponent('NewAppName', () => App);
Run react-native upgrade to re-generate the platform subfolders.
If you have linked resources (like custom fonts etc.) run
react-native link.
If you have other generated resources (like app icons) run the
scripts to generate them (e.g. yo).
Finally, uninstall the old app on each device and run the new one.
Hope it helps. feel free for doubts
for android edit strings.xml file which located in res/values/
string name="app_name">APP_NAME</string
I had a very hard time with this and this is what I did - hopefully it helps someone. Literally took me 15 minutes
https://www.npmjs.com/package/react-native-rename install react-native-rename and rename your app to whatever you need using the instructions provided for the package
Important part would be to use this:
npx react-native-rename "YourProjectName" -b com.yourporjectnamehere - because this is needed for android to work correctly
find in your project every file and folder name that will contain your previous name - for me it was mostly in ios folder. I had to rename all the folders and some of the files inside. just replace the part with your previous name with your current name
find all occurrences of your previous name left inside the project with the whole project search in your editor and replace them with the new name.
To make it work for ios
Delete Pods inside the ios folder
Delete node_modules
go to ios folder with your terminal and do pod install
do npm install in your original directory again
make sure all the caches are deleted for your ios simulator with yarn start --reset-cache
To make it work for android
Make sure that under android/app/src/com/yourprojectnamehere/ the folder contains MainApplication.java and MainActivity.java files and that the project name inside are updated
./gradlew clean inside android folder in terminal
Delete node_modules
npm install
react-native run-android and everything should be working
I know its a lot of steps, but from what I have found renaming react native app is not actually as easy as you might have thought

React/RCTBridgeDelegate.h' file not found

I have created a new project called auth using react-native init auth at terminal.When i tried to run the project using react-native run-ios. The build failed and gave a error 'React/RCTBridgeDelegate.h' file not found.
Tried to update the react native version
react-native run-ios at terminal in mac
I expect the build to be successful and see the ios simulator
The actual result which i got is build failed and hence cant see the simulator
The issue is related to cocoapods dependency manager. Do the following to fix this:
Open the terminal and go to your project ios directory
Type in pod init (If it doesn't exist) and then pod install
Open the workspace project and delete the build from ios folder
Run react-native run-ios from terminal.
It should work now.
In my case the libPods-FOO.a library had somehow become unlinked when I did a pod update && pod install. To see if this applies to you:
In Xcode, check under Project Navigator:
[Your Project Name] --> Targets --> [Your target name] --> General
Scroll down to Frameworks, Libraries and Embedded Content
If you don't have a libPods-XXXX.a in there (where XXXX is your project name) then add it:
Click the '+' sign to add the libPods library
Search for libPods in the search box
Choose the libPods-XXXX.a and click Add.
Just a hint: for those of you using the M1 Macs, pod install won't work. You should use arch -x86_64 pod install as stated in this issue
The issue happened due to the missing of React schema in cocoapods dependency. to resolve follow these steps:
open project in XCode using ios/{project name}.xcworkspace file
From menu bar -> click Product-> Scheme -> Manage Scheme
It will open a modal -> click on the + button
List item
New modal -> In target DropDown select React and click okay
close the modal and rebuild project Project - Build
it will resolve the issue.
In case you have Mac with an Apple M1 chip, It can be resolve in two ways,
#SOLUTION 1
Open Application->Utilites->Terminal.app
Right-click, Terminal.app -> Get Info -> General-> Enable "Open using Rosetta"
Restart Terminal
#SOLUTION 2
From terminal execute
sudo arch -x86_64 gem install ffi
Go to iOS directory and execute
arch -x86_64 pod install
I did what #Vahid suggested, but I also had another issue. A set of instructions I was following told me to pull the related .xcodeproj file into my actual project and then manually link a few different files.
These steps were not necessary and were creating the issue for me.
I was following this:
https://github.com/frostney/react-native-ibeacon
But it's better to use this npm package and follow their instructions:
https://www.npmjs.com/package/react-native-ibeacons
It can happen if you are using mac on M1 chip and trying to run the app on a simulator. Try to install iterm2 from official site(https://iterm2.com/), and launch it with Rosetta(Applications -> Right click on 'Iterm2' app -> "Get info" -> Check "Open using Rosetta"). Then run:
sudo gem install cocoapods
rm -rf /Users/{USERNAME}/.cocoapods/repos/cocoapods
Go to your project folder and run cd ./ios && pod install
Run build with npx react-native run-ios
In this particular project, certain targets were not working. I noticed the broken targets with this error were missing libPods-myProjectName.a. Under Targets -> General tab, "Frameworks, Libraries and Embedded Content" I pressed the "+" icon and searched for "pods" and added "pods-myProjectName.a" and now it seems to work. This might not be applicable to you, but I am adding this as another possibility of what might be wrong.
The simple pod install command did not work for me. If you have M1 Mac then try using.
arch -x86_64 pod install
follow this steps :
Select your project on Xcode
Go to Build Settings
In Search path tab select Header Search Path and add this values for both debug and release
$(inherited)
${PODS_ROOT}
${SRCROOT}/../../../ios/Pods/Headers (Make sure to set it to recursive)
[Mac OSX]
I updated the cocoapods version
brew upgrade cocoapods
For me adding arm64 to Excluded Architectures section works.
In my Xcode project I had to have multiple targets.
I added the (dev) target for development purposes, but in order to add React Native to that target you have to add it to the Podfile.
target 'MyApp' do
config = use_native_modules!
...
target 'MyAppTests' do
inherit! :complete
# Pods for testing
end
# 👇 Add your target in the Podfile
target 'MyApp (dev)' do
inherit! :complete
end
...
Then run pod install inside your ios folder, and done!

How to make manual linking of PushNotificationIOS if there is no Libraries folder in Xcode project?

How to make manual linking of PushNotificationIOS if there is no Libraries folder in Xcode project? Where should I put in this case?
Here is the structure of my project, I don't have Libraries folder there.
I'm following this guide for manual linking.
That's expoKit project.
According to doc :
The most limiting thing about Expo is that you can't add in your own native modules without detaching and using ExpoKit. Continue reading the next question for a full explanation.
But expo project support push notification :
Push notifications work right out of the box across both iOS and Android, using a single, unified API. You don't have to set up APNS and GCM/FCM or configure ZeroPush or anything like that. We think we've made this as easy as it can be right now.
see more here
In my case this issue related to ExpoKit project, in expoKit project manual linking should be done differently than in pure react native project.
Here is example how to do it here is the first variant:
1.cd into your project and make sure you have a podfile (pod install)
2.You’re going to want to open up your finder then open up project-name/ios/Pods/Headers/Public
3.Your Xcode wants React/RCTPush… so drag and drop the React folder in 2. ^ into your header search path (since RCTPushNotificationManager.h is listed in here).
4. You can find your header search path by opening up Xcode and clicking on your project in the top left corner then opening up the Libraries folder and then opening up RCTPushNotification.xcodeproj.
5. Click Build Setting and type header search path in the search bar. Then open it up and drag and drop 3. ^ over.
Here is second variant:
in Podfile add the library which you need, in my case it was RCTPushNotification:
pod 'React',
:path => "../node_modules/react-native",
:inhibit_warnings => true,
:subspecs => [
"Core",
"ART",
"RCTPushNotification"]

Error: RNFirebase core module was not found natively on iOS

I created a new app and I am trying to use react-native-firebase. But I continually get this error:
RNFirebase core module was not found natively on iOS, ensure you have
correctly included the RNFirebase pod in your projects 'Podfile' and
have run 'pod install'.
See http://invertase.link/ios for the ios setup guide.
Steps that I have done:
yarn add react-native-firebase
react-native link react-native-firebase
Set up my .plist file from Google under .../myproject/ios/myproject
Ran pod updateafter ensuring I was using Ruby 2.5.0
Ran pod install
The pod file that I am currently using is:
# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'
target 'MyProject' do
# Uncomment the next line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!
pod 'Firebase/Core'
pod 'Firebase/Database'
pod 'Firebase/Messaging'
target 'MyProjectTests' do
inherit! :search_paths
# Pods for testing
end
end
These are the versions that I am using:
"react": "^16.3.0-alpha.1",
"react-native": "0.54.2",
"react-native-firebase": "^3.3.1",
If you don't want to manually link, you can try installing RNFirebase as a pod install directly:
pod 'RNFirebase', :path => 'path/to/node_modules/react-native-firebase/ios'
Changing or hardcoding HEADER_SEARCH_PATHS did not help me. When the error recurs, it's not necessary to rm -rf node_modules nor delete the pod file etc, I found it useful to clear the cache.
I always prefer not to use pods with react native, however, the react-native-firebase's instructions for the non-pop installation will not work.
The reason for this is the package's search paths which assumes either /pods or /firebase
Hence, to make it link properly follow these steps:
download firebase sdk
make a folder directly under ios and call it Firebase, copy the frameworks needed of the sdk in that folder WITHOUT keeping the sub-folders (note, you have not entered XCode yet)
If you haven't already npm install -s react-native-firebase
Open XCode and drag and drop the desired frameworks to the Frameworks-folder in XCode (Eg. in my example the contents of the Analytics, Messaging and DynamicLinks folder). Do not copy items when asked as you already have then in the Firebase subfolder of ios:
In XCode right-click Libraries and select "Add files to [project]". Find RNFirebase-project in node_modules and select the RNFirebase.xcodeproj, do not "copy items"
In Project/Target settings go to Linked Frameworks and Libraries. Find and add libRNFirebase.a
In AppDelegate.m make adjustments as per the instructions from react-native-firebase, eg: import <Firebase.h> and [FIRAPP configure]; in didFinishLaunchingWithOptions
In Header Search Paths AND Framework Search Paths, add $(PROJECT_DIR)/Firebase
Don't forget to add you GoogleServices-Info.plist to your project
I had the same problem, while trying to fix it was making my app to crash on start up.
I moved it through the terminal under the ios/AppFolder/ but the Xcode was never aware of this file.
What helped me was to open my project in Xcode. Then left-click on my AppFolder > Add Files and then add the GoogleService-Info.plist.
I manually linked these react-native-firebase/* packages with
react-native link #react-native-firebase/xxx
"#react-native-firebase/analytics","#react-native-firebase/app","#react-native-firebase/auth","#react-native-firebase/crashlytics","#react-native-firebase/messaging"
which generated pod spec in pod and it worked.