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;
Related
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.
I'm developing an iOS framework that mixes Objective C and Swift code. Build fails at the #import "Example-Swift.h" line with 'Example-Swift.h' file not found.
The header file does get generated, I can find it at:
DerivedData/Example/Build/Products/Debug-iphonesimulator/Example.framework/Headers/Example-Swift.h
I tried all of the upvoted solutions on Stack Overflow, none worked. The only fix is manually adding the directory to User Header Search Paths in build settings.
I must be doing something wrong though if other people don't have to manually add the header path. Also, when users of this framework include it as a pod, they need to do update the build settings as well, which I really want to avoid.
So, is there a solution to this that's not an ugly hack? I'm using XCode 9.0.1. I wish Xcode / iOS had a normal build system... coming from Linux/Android, I like many things about the iOS ecosystem but the build system is just ridiculous.
I've seen this problem in a mixed Objective-C/Swift framework and my solution was to include the module name as the directory part of the include. In your case it would be
#import "Example/Example-Swift.h"
instead of
#import "Example-Swift.h"
This is actually documented in the Importing Swift into Objective-C subsection of Importing Code from Within the Same Framework Target at https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html
I have a project that is a couple years old, it uses Pods to utilize AFNetworking 1.3.3 (it was using RestKit, but I changed over to AFNetworking and still am having the same issues).
My import statements cause a compile failure
#import <AFNetworking/AFNetworking.h> // fail
#import <AFNetworking/AFHTTPClient.h> // fail
The error is simply:
Error:(23, 9) 'AFNetworking/AFNetworking.h' file not found
(or AFNetworking/AFHTTPClient.h if I try to import that one)
I can open the Pods folder in the project and clearly see the files there. I can even drill down into the classes, and my AppCode IDE auto-fills them in and/or auto imports them. But the project simply won't compile, as it does not recognize the imports above. See for reference, the files are there:
I've tried changing around versions of the framework with no luck. Any thoughts on something I may be overlooking? This project used to compile fine under older versions of Xcode, and nothing has changed with regards to the framework being used or the code using it.
Here is what my "Other C Flags" in build settings looks like with regards to what Pods setup:
Thank you in advance! Please let me know if there is more info I can provide.
It appears your IDE's list of include paths to search doesn't contain the directory of your AFNetworking headers.
Adding /Users/$USER/Desktop/blah/Pods to the list of "Other C Flags", much like in this answer for XCode, should solve your problem.
So I am trying to add a static library to my project in order to interface with a scanner. I have linked the binary in build phases to the libCaptuvoSDK.a, put the Captuvo.h header file in the project folder, and finally set the project to always search the user paths and added $(BUILT_PRODUCTS_DIR) recursive to the user header search paths. After doing all this I am trying to use #import "Captuvo.h" in my ViewController.swift file and getting the 2 errors Expected identifier in import declaration, and Expected expression. I have tried different combinations of importing and none of them seem to make a difference so I am led to believe the issue is with my process of adding the library.
I am new to Xcode and have never used a third party library in an application before so I feel I may be making a simple mistake or just misinterpreting things. Any help is appreciated!
Okay so I managed to fix my issue! I had imported the static library properly but the real issue was the header file. I fixed my issue by creating a new file in my projects folder named Quick-Scan-Bridging-Header.h. Inside that file is where the #import "Captuvo.h" line belonged. Once that was done I opened the Quick Scan apps build settings and under Objective-C Bridging Header I added the path Quick Scan/Quick-Scan-Bridging-Header. I also added the Header Search Path $(BUILT_PRODUCTS_DIR)
After I did all this I am able to use the Captuvo classes in my ViewController.swift file.
As a beginner in ObjectiveC I need some help.
I'm working on a phonegap plugin for IOS (so, written with objective C). I use some open source code but I got an error with an .h import.
My architecture look like:
myFmk.framework/
myFmk.framework/ABCDE/myFmk.h <== in a sub folder
myFmk.framework/myFmk <=== this is a file
myPlugin.h
myPlugin.m
In myPlugin.h I have #import and in "myFmk.framework/myFmk" file I have only one line "ABCDE/".
I thought that this file do a redirection of the absolute import (with brackets) but my complier told me that "myFmk/myFmk.h" is not found.
I tried to find some documentation about this feature but I wasn't able to find its name... do you have this documentation or the feature name?
Thks.
Is the framework added using a cocoapod? If not, did you follow the instructions properly for adding it to your project? It would probably help if you posted the framework you are experiencing problems with.
If this is a framework that is added to your project properly and you are unable to import there are a few things you should check. First, go to your project settings (click on the project at the very top of your file tree in the left column) and then look for "linked libraries". See if the library is listed there. If not click the + and try to add it.
If this framework was added via cocoapods another thing to check is search your file structure for libPods.a. If it is red, I find sometimes it is helpful to delete it, close the project and run pod install again.
Also if you installed the project via cocoapods remember to open the workspace and not the old xcode project file.
I have also experienced this problem when my header search paths and other linker flag paths were wrong. Linker Flags should be $inherited if this is a cocoapod. In my projects most Header search paths are $inherited too.
If none of this is helpful please provide more information such as how this framework was added to your project and what the framework is. Also let us know if you get any error messages.