react-native-branch-deep-linking-attribution icon indicating copy to clipboard operation
react-native-branch-deep-linking-attribution copied to clipboard

'RCTLog.h' file not found & Use of undeclared identifier 'RNBRANCH_VERSION' within `react-native-branch` npm package

Open farhankassam2 opened this issue 4 years ago • 4 comments

https://github.com/BranchMetrics/react-native-branch-deep-linking-attribution/blob/3b3b3df9b72bc832d1c525627253ec9ac7955c1d/ios/RNBranchConfig.m#L9

https://github.com/BranchMetrics/react-native-branch-deep-linking-attribution/blob/3b3b3df9b72bc832d1c525627253ec9ac7955c1d/ios/RNBranchConfig.m#L23

Dear Branch support team,

I sent an email highlighting the following major issue via email to [email protected] with the case number: 00108294 last week but got no reply. So I decided to raise an issue on your Github publicly instead. Do get back to me at your earliest convenience.

I also want to state that I have already followed the steps in this Prepare for app distribution page to prepare our app for distribution and all the requirements have been met to create an archive for our app. I have also looked around the Developer Documentation and "Apple Developer Forums" for a solution to this and tried precisely twelve different solutions to fix this depending on posts from other users of the forum as well as from Github issues and Stackoverflow links, but none seemed to resolve this.

Here is the issue: I have been struggling with this issue for one whole week. It seems to be appearing in the RNBranchConfig.m file within the react-native branch package for iOS specifically in the lines noted above: line 9 and line 23.

A screenshot of the error message is provided below: Screen Shot 2020-10-14 at 2 18 48 PM

To reproduce the issue, do the following:

  1. Open .xcodeproj in Xcode and add the RNBranch.xcodeproj manually into the Library directory as follows: Screen Shot 2020-10-14 at 3 30 05 PM

I did the above to remove the -lBranch not found error I was experiencing in Xcode before as below: Screen Shot 2020-10-11 at 2 34 52 PM copy 2) Go to Product > Clean Build Folder to start the build process afresh.

  1. Make sure that the device to run the target app on is Generic iOS Device in the top-left corner next to the Run symbol as shown below: Screen Shot 2020-10-14 at 3 15 32 PM

  2. Click on Product > Archive to start the archiving process of generating the .ipa file which compresses the app into a file that can be distributed to other software (I am using this so that I can distribute the app to BETA testers). This is shown below: Screen Shot 2020-10-14 at 3 17 13 PM

  3. For me, during the archiving process, it pops up a terminal window showing that dependency graphs have been loaded, as it should as follows: Screen Shot 2020-10-14 at 3 18 59 PM

After a minute or so, it shows that there are two compile-time errors, both in the same aforementioned file. I will show the full image here after the failed archiving process showing all the details: Screen Shot 2020-10-14 at 3 22 39 PM

These are the solutions I have tried so far:

  1. Adding React target dependency to to my project's target as below: Screen Shot 2020-10-14 at 2 21 52 PM

  2. Adding React as a target itself to the project schemes and unchecking parallelize build as below: Screen Shot 2020-10-14 at 2 36 40 PM

  3. Manually adding the React.xcodeproj as a Library to use in the project under <project>/Library and then adding libReact.a into the following: a) Build Phases > Link Binary with Libraries as below: Screen Shot 2020-10-14 at 2 40 14 PM b) General > Frameworks, Libraries and Embedded Content as below: Screen Shot 2020-10-14 at 2 41 57 PM

The React.xcodeproj was added in the following Library directory manually: Screen Shot 2020-10-14 at 2 43 32 PM

  1. Commenting out line 9 and line 23 in the first image to see if those two are even needed. It turns out that even after this, the archiving fails with the other remaining warnings.

  2. Trying to use the following react-native package versions: 0.60.0, 0.61.2, 0.62.1 and 0.63.3 with react peer dependency versions: 16.13.1 and 16.90 and in different combinations with each other to see if perhaps the file can be found in different versions of React. In some Github posts I read that the issue occurs only with RN versions lower than 0.61, which is why I chose to also downgrade the version. Initially, I had been using 0.62.1 and after that I was playing around with the various versions aforementioned.

  3. Making sure that pod React is correctly added in my Podfile to link with the correct podspec as below is a line in my Podfile: Screen Shot 2020-10-14 at 2 50 20 PM

  4. Adding subspecs for the various other React dependencies to my podfile and then running pod install within ios directory to ensure that the subspecs are also included as below: Screen Shot 2020-10-14 at 2 53 20 PM

When I tried the above, it threw me an error after doing pod install that some of the podspec files like the ones corresponding to RCTLinkingIOS and DevSupport cannot be found and therefore, pod install would fail:

  1. I ensured I have $(inherited) in the header search paths and I also added ${SRCROOT}/../../../ios/Pods/Headers to the header search paths so that the project can detect the React dependency and associated files. I tried both of these with recursive and non-recursive strategies just for the sake of it. This is show below: Screen Shot 2020-10-14 at 3 01 22 PM

  2. I have also ensured that I have $(inherited) as non-recursive in the Library search paths for both debug and release as shown below: Screen Shot 2020-10-14 at 3 05 44 PM

10)I have tried setting the Always Search User Paths (Deprecated) to both Yes and No. I tried Yes because according to Xcode help it states that enabling it may allow Xcode to search for libraries in the format <React/RCTLog.h> as well as in the format "RCTLog.h" as stated in the Xcode help window below (I am attaching it here for reference): Screen Shot 2020-10-14 at 3 09 28 PM

The setting is located under Build Settings > Search Paths as show below: Screen Shot 2020-10-14 at 3 07 30 PM

  1. Next, I downloaded the RCTLog.h file provided by React in this LINK and manually added it into the RNBranch.xcodeproj directory too as show below: Screen Shot 2020-10-14 at 4 12 04 PM

I then changed the import to: #import "RCTLog.h" in line 9 and line 23 to: NSString * const RNBNC_PLUGIN_VERSION = @"5.0.0"; of RNBranchConfig.m to let the file know that the RCTLog.h is located within its own Xcode project and that the current react native branch version is 5.0.0 (hardcoded) as show below: Screen Shot 2020-10-14 at 4 14 30 PM

After I try to archive the app; it fails again.

  1. The last solution I tried was following the steps outlined on this Github issue post, but instead of linking react-native-branch, I tried linking and then doing pod install for both [email protected] and [email protected], hoping that when I run react-native link react-native and react-native link react, the machine will think that cocoapods is not installed, which apparently according to the link, is able to correctly link the React dependencies into the Xcode project and detected by packages using React.xcodeproj. For further details on the solution I tried, visit this issue comment: LINK. I followed the same steps even when linking the react-native-branch package, as that is the package causing this issue. But after much trial and error, the same error pops when I go to archive.

Now that I have described the twelve possible solutions I have tried, you can see that I have tried so many different things to get RNBranchConfig.m to detect RCTLog.h in the React dependency, but NONE worked! I am currently out of options and that is why I ask for some help. We need to get our app release for BETA testing within two weeks now so I also have a time constraint, which, as a developer, is quite pressurizing I hope you can understand. I hope the issues in this react-native-branch can be resolved sooner than later to make it a reliable long-term package to use for deep linking in iOS.

Below, find details about the version of the various tools, software, packages and libraries I am using while I encounter this error so that you may assist me faster:

  • react-native: ^0.60.0, ^0.61.2, ^0.62.1 and ^0.63.3
  • react: ^16.13.1,^16.90 and ^16.14.0
  • react-native-branch: ^5.0.0
  • cocoapods: cocoapods-1.8.4
  • node: v12.14.1
  • npm: 6.13.4
  • Xcode: 11.4
  • macOS: Catalina 10.15.5
  • ruby: ruby-2.6.3
  • react-native-cli: 2.0.1

Any help is greatly appreciated.

farhankassam2 avatar Oct 14 '20 22:10 farhankassam2

Please find attached the archive log exported after trying to archive via Product > Archive: Archive PhoneMe_2020-10-14T23-10-15.txt

Please find a build log exported from the IDE when trying to build the React Native iOS app from the IDE, here: build_log.pdf

farhankassam2 avatar Oct 15 '20 08:10 farhankassam2

The error can be reproduced by cloning the following repo and running the app on Xcode: https://github.com/farhankassam2/PNM_179_Test_Project/.

In the repo, react-native-branch has already been successfully linked and installed.

Thanks.

farhankassam2 avatar Oct 21 '20 09:10 farhankassam2

I managed to find a solution that successfully builds the app with RNBranch package, and this solution is so trivial it blew my mind I am not even sure why it works but here it is:

I uninstalled react-native-branch version 5.0.0 and removed it from the yarn list of packages too by doing yarn remove react-native-branch. It seems as though I had two package managers, npm and yarn, that was configuring the package, which could be one cause of the problem. I decided to stick to using only npm for managing the package. After uninstalling, I followed the following steps precisely (similar to what is mentioned here but using npm as my package manager instead: https://github.com/BranchMetrics/react-native-branch-deep-linking-attribution/issues/361#issuecomment-415149270):

yarn remove react-native-branch
npm uninstall --save react-native-branch
react-native unlink react-native-branch
pod deintegrate ## removes the previously installed pods in the Pods directory
rm Podfile
npm install --save [email protected]
react-native link react-native-branch
git checkout -- Podfile ## puts the Podfile back
pod update Branch
pod install

My Podfile contained the following two necessary Pods before I ran any command starting with pod above:

  pod 'react-native-branch', path: '../node_modules/react-native-branch'
  pod 'Branch'

You may have noticed that I specified the installation of version 5.0.0-rc.1 as that is the one that removes this error. Perhaps the package mantainers need to look into why the newer version 5.0.0 fails to build the app.

After doing all the above, I simply went into the iOS directory and opened the project workspace. This allows me move to explaining my next mistake: I was mainly trying to build the app from the .xcodeproj but what worked for me was building the app from .xcworkspace. I opened the Xcode workspace of the app from within iOS directory and first, did Product > Clean Build Folder and after, Product > Build or Archive and tadaaaa!!! The app built successfully and now allows me to archive the app.

Since I have been stuck on this issue for some time, I had experimented a lot of different solutions as you can see from the issue description, but some experimentation still remains (I did not exhaust all possible solutions fully to give you an idea of precisely where the problem lies).

Certainly, the problem was not react-native related but that the package providers were not importing React dependencies into their package correctly. Therefore, some manual linking was required even despite my react-native version being >0.60 (for which we don't usually manually link by running react-native link). I did not try experimenting more after this simply because I wanted to avoid getting stuck again, but what I got from this is that the problem lies in either the following:

  1. react-native-branch package has misconfigured something in their latest release of 5.0.0 and so the previous 5.0.0-rc.1 release resolves this build time error OR,
  2. Linking a package via two package managers like yarn and npm is likely to cause some misconfiguration of the package as it is installed and configured twice by two different package managers. Therefore, it is recommended to only install and link a package via one package manager!!! OR,
  3. Building and archiving of the app with this specific package only works in the Xcode workspace and not the Xcode project for some reason.

The former two are more likely the cause of the problem because I did experiment building and archiving with version 5.0.0 in the Xcode workspace but the had also failed for me.

I hope this fix helps those who are struggling with the same issue 👍

farhankassam2 avatar Oct 30 '20 09:10 farhankassam2

I see the same error message using react-native-branch v5.0.0

With the IDFA deprecation, we're all forced to use v5.0.0 if we want to target iOS and bugs like this should have been caught.

Anyone else experience this issue?

jason-ce avatar Nov 13 '20 22:11 jason-ce