I was working on my first React Native NativeModule. A simple 'Hello, World!' Objective-C function just to get an idea of how it worked. Things were going relatively smoothly, however, it seems xcode lost reference to all React Native files. I thought this problem was probably project specific, so I started a new TestApp using react-native init TestApp, but when I open that .xcodeproj file I have the same issue.
The first error in this new TestApp is in the AppDelegate.m file: 'React/RCTBundleURLProvider.h' file not found but as you might expect it avalanches from there.
I spent the most of yesterday trying out all sorts of potential solutions to no avail.
This might be a false lead, but maybe not, however I noticed Header Search Paths is empty whenever I first open .xcodeproj on a newly initialized project. That being said, I have tried numerous search paths based on answers I have found here on StackOverflow, GitHub, etc, the latest being $(SRCROOT)/../node_modules/react-native/React
I know this problem might be a little vague, but any help would be greatly appreciated. As an iOS developer, I am trying my best to be open to React Native, but continually running into issues such as this is really putting a damper on that.
Thanks!
ps. At this point I wonder if reinstalling xcode, node, npm, and react native altogether would be the surest solution.
Edits for clarity
First I run react-native init TestApp and cd TestApp followed by npm install. I've tried running react-native link at this point as well.
I then open ios/TestApp.xcodeproj. After xcode does its usual indexing I will inevitably be greeted by a red 'React/RCTBundleURLProvider.h' file not found in AppDelegate. Sometimes 'React/RCTRootView.' file not found' happens too. Most of the time, even if this second warning doesn't happen, The RCTRootView * in didFinishLaunchingWithOptions is not colored.
If I try to create a native module like so:
#import <Foundation/Foundation.h>
#import "RCTBridgeModule.h"
#interface Test : NSObject <RCTBridgeModule>
#end
I get an immediate 'RCTBridgeModule.h' file not found.
In other words, Xcode is not finding anything RCT. Autocomplete doesn't suggest anything RCT.
Even with these warnings, I can run the app from Xcode or by running react-native run-ios.
This extra bit, may or may not be relevant:
If I have import { NativeModules } from 'react-native' in my App.js, NativeModules turns out to be undefined.
My current feeling is that there is a crucial step in set up that is not listed in the RN Docs, and for some reason other tutorials aren't touching either. I tried on another computer to the same result.
"Header search paths" being empty is perfectly normal. RN is exposing its headers from the React project. If you go to React.xcodeproj (under Libraries) you can see that the React target has a "Copy Headers" Build Phase, and these headers are being exposed when packaging the library as public headers.
To make sure that your app can use the headers, go to your app's scheme and into the Build section - the React target should be in the list and before your app's target. Also, the Parallelize Build checkbox needs to be OFF. It should be set-up like this out of the box in new RN projects, but maybe something was changed in your project so it's worth checking.
When the build is just starting, and especially on a freshly initialized project, you can expect to see some errors in the IDE during the build regarding public React headers, but they should be gone and resolved once all React third-party libraries finish building and React itself is packaged.
If everything is set-up correctly and it's still not working, delete the DerivedData folder and build again.
Finally linking native code with react-native!
So, I haven't really solved the precise issue, but I managed a workaround.
Previously I was trying to initialize a react-native project and then modifying the Xcode project that was built in the initialization.
I decided instead to approach the problem from the opposite angle of linking react-native to an existing xcode project by following this documentation: https://facebook.github.io/react-native/docs/integration-with-existing-apps.html
I've been able to repeatedly link native code (both swift and objc) to react-native after react-native init TestApp by erasing the contents of TestApp/ios and following the process in the link above.
Thanks #Artal for providing some valuable info on the way it is supposed to work.
Related
I'm a newcomer to Xcode and native iOS development, having had previous experience on Android native and React native. I inherited an Objective-C codebase for an iOS application, which has not been touched for about 2 years. I tried to build the project on an iOS simulator, but I encountered this error during the build.
I have seen quite a few posts on StackOverflow where "xxxx.h" file is not found, however, I was unable to find a definitive solution. As you can see in the screenshots below, the AFHTTPSessionManager.h file is indeed in the Pods folder, however, for some reason, the header file just cannot be found.
What I have tried is to add the full path of where the file is found into the Header Search in the build settings for both the project and the pods directory.
Some help is very much appreciated so I can start working on the project. Thank you!
When you're importing files inside your module/framework, you use #import "file.h"
But when you need to use an instance defined in an other framework, you can't do that. You need to import that framework header file, in this case #import <AFNetworking.h>, or #import AFNetworking;
I'm a beginner in iOS development. I cloned a repo containing working code. I opened up the project in xcode, but when I build the project I receive the error Module 'Subscriptions' not found.
In my build settings, the Subscriptions.framework framework is in Linked Frameworks and Libraries. From what I've researched about module not found errors in xcode, this should be the fix for my problem. However, this is not fixing my problem. This project should normally be able to be built and compiled. Is there something I'm missing here?
Update
Here is the xcode file tree view.
Main
|-Main
|-MainTests
|-Products
|-Frameworks
|-Subscriptions.xcodeproj
|-Subscriptions
|-Products
|-Subscriptions.framework
|-Frameworks
|-Pods
Pods
Ok. I finally figured out what was going on. I dove into the directory I thought that the Susbcriptions.framework was being installed in, and it wasn't there. The directory in the build products path was set to Products/Debug-iphoneos but the Subscriptions.framework was instead being installed into Products/Debug. This made me realize that somewhere in XCode I had the build setting set to build for MacOS instead of iOS. I found the setting and rebuilt my project for an iPhone XS simulator and the module was imported successfully.
During the iOS linking phase, I started seeing errors for my React Native project.
React Native version: 0.41.2, 0.40, 0.39
All worked fine, I edited the Android version, React Native code didn't change, when this kind of linking errors started showing up with headers on /node_modules/react-native/React/Base/{RCTHeaderName.h} path not being found:
In file included from /Users/user/ReactNativeProject/node_modules/react-native-vector-icons/RNVectorIconsManager/RNVectorIconsManager.h:9:
../react-native/React/Base/RCTBridgeModule.h:12:9: fatal error: 'React/RCTDefines.h' file not found
#import <React/RCTDefines.h>
^
In the Link Binary With Libraries I include the core React library
(libReact.a).
The location of the RCTLog.h is
PROJECTROOT/node_modules/react-native/React/Base/RCTLog.h, but the
import is #import <React/RCTLog.h>
Newly adding React.xcodeproj into Libraries doesn't help, Xcode's Product > Clean doesn't help, neither does restarting Xcode
react-native run-android works, react-native run-ios shows the error
File permissions set to the user executing react-native run-ios
Do you have Parallelize build option unchecked and React listed first in your build targets?
You can find this window in Xcode => Your project icon near the run button => Edit scheme => Build tab
Update:
solution on Facebook React-Native
https://github.com/facebook/react-native/issues/11813
============
This issue happened to me also.
It seems React.xcodeproj only recognise configuration Debug and Release. All of output of React.xcodeproj is written into Debug-iphonesimulator or Release-iphonesimulator.
That means if you have some configurations other than "Debug/Release", the output will still be written into Debug-iphonesimulator or Release-iphonesimulator, that is not what we want.
So the solution is to add a same configuration in React.xcodeproj to match the one of your own project.
For example, if you have "Debug/Release/Test/AppStore" 4 configurations in your own project, you have to make sure React.xcodeproj also has the same 4 configurations.
please click the "+" button of Configurations, then "Duplicate Release Configuration", and rename it according to you need.
It seems like there are a lot of reasons to be getting these 'missing headers' errors and I've tried a lot of things posted on Stack Overflow and nothing would work. Finally I stumbled upon the solution below that did work for me. Posting in case anyone else has the same issue ... its a bit obscure. For me it was caused by a build locations setting in Xcode that is apparently incompatible with vanilla React Native. The build locations setting that fixed this issue is shown here:
in XCode->Settings>Locations->Advanced... make sure your Build Location is not set to Legacy, it should be set to Unique
Note: the vanilla React Native application may have to be reinitialized from scratch with react-native init ... after changing this setting.
Add path/project folder/ios/Pods/Headers/Public in your Library's Build Settings -> Header Search Path. The issue will get resolved
I m using React-native v0.10.0 and getting this screen:
Ok, So I figure out I m doing something wrong.
So I downloaded the code from this official React-native website for integrating React-native into existing app using pod.
The downloaded code uses React-native v0.2.1 and everything looks good there.
So I copied the whole code and overrode mine, but the red screen still appears. It left me just with the changes of the React-nativeץ
Is there any chance that the current version of React-native v0.10.1 doesn't work at all? :/
Thanks in advance!
I've had success by adding pod 'React/RCTWebSocket' to the Podfile as well and running pod install again.
This issue is caused because RCTWebSocketManager is not defined in your bundled app. The connect method of an object cannot be called on an undefined or null object.
To resolve this problem in iOS open Build Phases for your app target and ensure libRCTWebSocket.a exists in the Link Binary with Libraries section. If the item is not listed and not available for addition then add RCTWebSocket.xcodeproj to your app's Libraries folder in Xcode and try linking again.
This may seem rather trivial, but check to make sure that you have deleted react-native from the node_modules directory within the directory of react-native-router in the app's node_modules directory. If react-native is listed again the app will throw an error.
I have experienced this issue on a couple of occasions and this has been the cause for the error.
My application has been running fine with the Cloud-iOS.a library for the past few days. However, today, when I used the “Product > Clear Build Folder” command and tried to run the app again, it would give me this error:
‘Cloud/CLAPIEngine.h’ file not found
The Cloud library builds successfully, but the main project gives me that error along with 4 others in both the main project and the XCTest files (that are linked with this one).
I’ve tried removing and re-inserting the file from Build Phases > Headers and Build Phases > Compile Sources and that didn’t do anything (I also have tried to remove the -fno-objc-arc flag from the file to see if it would recognize it, and sure enough, it gave me an ARC error). I’ve tried looking through other SO questions like these:
Restkit/Restkit.h file not found Xcode 6.1
Adding frameworks to project in Xcode 5 and having *relative* paths added
... and nothing worked. I even tried restarting the app itself and nothing happened. I made a test project and included the same library to see if it’s my project, but this project also says the same errors. Both projects also have the file in the "include/" directory. I don’t know why this is happening and I’m starting to get really tired with Xcode’s random problems.
I’ve included the test project in a Dropbox link for others to check out and see why it’s doing this.
https://www.dropbox.com/sh/lu8hntaaww8y6r4/AAA1KJ085YvKjwMR-AZff6Nga?dl=0
What can I do to get this to run again? Thanks in advance.
(After this, I’m not running the “Clear Build Folder" command again.)
Ok. Looks like someone over at Apple Developer Forums was able to give me an answer. I chose the last one that they gave me, which was to change the static library into a framework. Thank goodness Apple made this available on iOS, because (after a bit of tweaking), everything works!