fix: react native expo failing builds #281
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
💡 Motivation and Context
Fix for build issues reported here:
https://posthog.com/questions/pods-suddenly-not-able-to-be-installed
https://posthog.com/questions/react-renderer-animations-primitives-h-file-not-found
Trying to understand what happened
Our latest iOS SDK version 3.19.0 has unfortunately borken builds for RN Expo users.
After investigating the issue, and trying to replicate it, I found that the issue was that RN Expo tools like to link the PostHog SDK statically.
My basic understanding of the underlying issue:
Because we were using
#import "utils.h"
, the compiler searches for the file in the current directory first. If it is not found there, the compiler then searches all other include directories. This worked okay when PostHog was shipped as a framework/module since the search was limited within the module itself. However, when PostHog was shipped as a static library, the compiler would search and find matching header files in the whole project from other dependencies or RN expo libs.primitives.h file not found
error, the compiler was linking toreact/rendered/animations/utils.h
src/dsp/dsp.h file not found
error, the compiler was linking to anotherlibwebp
header file if that dependency was present in the project. (This becomes apparent when we look at the screenshot example of the error, we never#include "src/dsp/dsp.h"
in our files).Remedying the issue
To remedy this, I flattened the whole file structure of
/vendor/libwebp
(both to simplify things and to handle how pods in general try to change the project structure) and used#import "./utils.h"
instead. My understanding is that the./
explicitly tells the compiler to look for the file in the current directory and not extend the search to other include directories.Reproducing the issue and the fix
I've attached a sample project that reproduces the issue and the fix with the following steps:
SamplePostHog.zip
Initial Setup
Install dependencies:
Attempt initial iOS build:
This will fail with a
'primitives.h' file not found
error - this is the first error we expect.Add 'libwebp` dependency
Edit
ios/Podfile
:Install CocoaPods dependencies:
Try building again:
This will fail with
'src/dsp/dsp.h' file not found
error - this is the second error we expect.Add local 'PostHog` dependency with the fix
Update
ios/Podfile
again:Reinstall CocoaPods dependencies:
Build one final time:
The build should now complete successfully.
Notes
Additional Steps
libwebp
tophlibwebp
to avoid conflicts in caselibwebp
is already present in the project. I haven't noticed any errors, but just playing it safe here.📝 Checklist
@marandaneto unfortunately I couldn't verify this for Flutter, still need to fix my local env for that. I'll try and do it while you review this, but if it's easy for you to check it would be really helpful.