Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native xcode project "Header Search Path"

Following the steps from React Native official tutorial, the xcode project created by "react-native init MyFirstRNProject" won't compile. It complains "React/xxxxx.h" can't be found.

After further investigation of this xcode project, I figured the "React" target contains a build phase "Copy Headers" which copies all exposed headers into a weird location: "MyFirstRNProject/node_modules/react-native/React/build/Debug-iphonesimulator/include/React"

OK, cool, at least we got the header location. We can change the copied location to somewhere else that better than this. So whichever the project that do "#import < React/xxxxx.h >" should have above path in "Header Search Path" in build settings. Unfortunately, all projects have "Header Search Path" empty. And that's why I'm getting tons of header not found error.

OK, let's add it. Now it finds headers, but compilation still failed, see reference below: https://github.com/facebook/react-native/issues/21482

The discussion above saying that removing the "Header Search Path" of the projects will solve the problem. But we know that without header search path, it again can't find React headers.

Just curious now, I don't think my setup is wrong, does anyone has the same issue?

like image 665
Kai Avatar asked Jan 18 '19 21:01

Kai


1 Answers

I had the same problem on fresh install of Xcode 10.1 There are few steps to follow to compile the new project after react-native init appName

  1. In Xcode, Select File -> Project/Workspace Settings. You will see a Build System option to select the Legacy Build System as shown below

Set Legacy Build System

  1. Change Advanced settings, and set Build Location to Custom and change paths to Relative to Workspace and Build/ to build/Build/ as showed.

Build Path set up 3. User Debug for command-line builds(for react-native run-ios to work properly)

Command-line builds mode

  1. Clear your project

After this manipulations(don't need set header search paths) you'll be able to build and run empty project via Xcode or CLI

like image 110
natchkebiailia Avatar answered Oct 23 '22 04:10

natchkebiailia