Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EAS build fails - 'FBDefines/FBDefines.h' file not found #26

Closed
nkalinov opened this issue Sep 26, 2022 · 19 comments
Closed

EAS build fails - 'FBDefines/FBDefines.h' file not found #26

nkalinov opened this issue Sep 26, 2022 · 19 comments
Labels
bug Something isn't working SDK 46 Affects plugin in Expo SDK 46 upstream flipper Upstream issue with fbflipper (check linked issues)

Comments

@nkalinov
Copy link

Hi,

I am trying to setup Flipper for first time in my Expo app but something fails and I have no idea how to fix.
I followed this blog post - https://blog.expo.dev/developing-react-native-with-expo-and-flipper-8c426bdf995a
Maybe a relevant issue - facebook/flipper#478 ?

Dependencies:

"expo": "^46.0.0",
"react-native-flipper": "^0.164.0",
"expo-community-flipper": "^46.0.1",

Error log:

....
› Copying   react-native ios/build/Build/Products/Debug-iphonesimulator/FlipperKit/FlipperKit.framework/Headers/FBDefines.h ➜ ../../../Users/expo/workingdir/build/mobile/ios/Pods/FlipperKit/iOS/FBDefines/FBDefines.h
› Compiling react-native Pods/FlipperKit » UIView+SKInvalidation.mm

❌  (/Users/expo/workingdir/build/mobile/ios/build/Build/Products/Debug-iphonesimulator/FlipperKit/FlipperKit.framework/Headers/SKMacros.h:11:9)

   9 | #define SKMACROS_H
  10 | 
> 11 | #import <FBDefines/FBDefines.h>
     |         ^ 'FBDefines/FBDefines.h' file not found
  12 | 
  13 | #ifdef __cplusplus
  14 | #define SK_EXTERN_C_BEGIN extern "C" {
› Compiling react-native Pods/FlipperKit » UIColor+SKSonarValueCoder.mm
› Compiling react-native Pods/FlipperKit » UICollectionView+SKInvalidation.mm

❌  (/Users/expo/workingdir/build/mobile/ios/build/Build/Products/Debug-iphonesimulator/FlipperKit/FlipperKit.framework/Headers/SKMacros.h:11:9)

   9 | #define SKMACROS_H
  10 | 
> 11 | #import <FBDefines/FBDefines.h>
     |         ^ 'FBDefines/FBDefines.h' file not found
  12 | 
  13 | #ifdef __cplusplus
....
@jakobo
Copy link
Owner

jakobo commented Sep 26, 2022

Start by removing "react-native-flipper": "^0.164.0" from your package.json. I know this means some plugins that depend on the RCT Bridge won't work but we can rule out the plugin this way.

Let's definitely keep an eye on that linked Flipper issue, as it seems to be very related.

@jakobo jakobo added investigating Ongoing conversation about the issue upstream flipper Upstream issue with fbflipper (check linked issues) SDK 46 Affects plugin in Expo SDK 46 labels Sep 26, 2022
@nkalinov
Copy link
Author

Thanks for looking at this @jakobo !
I removed react-native-flipper from my dependencies and now I get:

❌  (node_modules/react-native/React/AppSetup/RCTAppSetupUtils.mm:27:9)

  25 | 
  26 | #ifdef FB_SONARKIT_ENABLED
> 27 | #import <FlipperKit/FlipperClient.h>
     |         ^ 'FlipperKit/FlipperClient.h' file not found
  28 | #import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
  29 | #import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
  30 | #import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>

Found another relevant issue.

@jakobo
Copy link
Owner

jakobo commented Sep 27, 2022

Thanks. Do you mind sharing your podfile in case there's something conflicting with the Flipper code? You can run expo prebuild locally, which will generate the ./ios/Podfile for the build. Usually flipper issues can be traced back to

  1. Wrong deps in package.json
  2. Residual flipper module in node_modules getting autolinked
  3. An error in the Podfile caused by another build plugin

@nkalinov
Copy link
Author

Here's the Podfile after expo prebuild:

require File.join(File.dirname(`node --print "require.resolve('expo/package.json')"`), "scripts/autolinking")
require File.join(File.dirname(`node --print "require.resolve('react-native/package.json')"`), "scripts/react_native_pods")
require File.join(File.dirname(`node --print "require.resolve('@react-native-community/cli-platform-ios/package.json')"`), "native_modules")

require 'json'
podfile_properties = JSON.parse(File.read(File.join(__dir__, 'Podfile.properties.json'))) rescue {}

platform :ios, podfile_properties['ios.deploymentTarget'] || '12.4'
install! 'cocoapods',
  :deterministic_uuids => false

target 'MySupermarket' do
  use_expo_modules!
  config = use_native_modules!

  use_frameworks! :linkage => podfile_properties['ios.useFrameworks'].to_sym if podfile_properties['ios.useFrameworks']

  # Flags change depending on the env values.
  flags = get_default_flags()

  use_react_native!(
    :path => config[:reactNativePath],
# @generated begin expo-community-flipper-isprod - expo prebuild (DO NOT MODIFY) sync-e002ec08de24fbbe5b9a843ae9231b9627b8b9c4

            # https://www.npmjs.com/package/expo-community-flipper
            :production => ENV["PRODUCTION"] == "1" ? true : false,
# @generated end expo-community-flipper-isprod
    :hermes_enabled => flags[:hermes_enabled] || podfile_properties['expo.jsEngine'] == 'hermes',
    :fabric_enabled => flags[:fabric_enabled],
# @generated begin expo-community-flipper-urn - expo prebuild (DO NOT MODIFY) sync-59337f4ef2cee165bd93878dbfd00ddba4d65e67

            # https://www.npmjs.com/package/expo-community-flipper
            :flipper_configuration => ENV['FLIPPER_DISABLE'] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabled,
# @generated end expo-community-flipper-urn
    # An absolute path to your application root.
    :app_path => "#{Dir.pwd}/.."
  )

  # Uncomment to opt-in to using Flipper
  # Note that if you have use_frameworks! enabled, Flipper will not work
  #
  # if !ENV['CI']
  #   use_flipper!()
  # end

  post_install do |installer|
    react_native_post_install(installer)
    __apply_Xcode_12_5_M1_post_install_workaround(installer)

    # This is necessary for Xcode 14, because it signs resource bundles by default
    # when building for devices.
    installer.target_installation_results.pod_target_installation_results
      .each do |pod_name, target_installation_result|
      target_installation_result.resource_bundle_targets.each do |resource_bundle_target|
        resource_bundle_target.build_configurations.each do |config|
          config.build_settings['CODE_SIGNING_ALLOWED'] = 'NO'
        end
      end
    end
  end

  post_integrate do |installer|
    begin
      expo_patch_react_imports!(installer)
    rescue => e
      Pod::UI.warn e
    end
  end
end

One thing that I'm noticing is that I have use_frameworks! which was mandated by https://docs.expo.dev/versions/latest/sdk/firebase-analytics/#additional-configuration-for-ios

Looking at this Podfile comment it seems use_frameworks! is not compatible with flipper? Or maybe this plugin needs to add the instructions from the comment - $staticFrameworks etc. ?

@jakobo
Copy link
Owner

jakobo commented Oct 1, 2022

This is going to be a long writeup with no good answers, just some things to try.

It looks like the prebuild is now pulling the latest template which includes a 5mo old change for the build-properties config plugin. The change for expo/expo#17106 added the use_frameworks command. It's a problem because Flipper (specifically Folly if I'm remembering correctly) needs everything statically linked.

Best Chance: Use Expo's Plugins

According to the build properties config plugin, we can force static linkage by including the new-ish build properties plugin. That should be enough to make everything play nicely assuming the static linking directive does what it should.

npx expo install expo-build-properties

And updating our plugin list

{
  "expo": {
    "plugins": [
      [
        "expo-build-properties", { "ios": { "useFrameworks": "static" } }
      ]
    ]
  }
}

Second Best Chance: Upstream Change

I'm tagging @Kudo (original author of expo Podfile change) in case there's a way we can solve this on the expo side. Ideally, that entire use_frameworks line shouldn't be written unless the developer explicitly opted in to the useFrameworks prop. If we can get this change in the expo templates, then we just need to add a section to the REAMDE about compatibility with other expo plugins.

Third Best: Using this Plugin Nukes use_frameworks Calls

If static linking frameworks doesn't work and we can't get the change upstream in Expo, then we can destroy the line completely. There is no idempotent destroy lines operation in the config plugin utils.

Instead, after reading in the file here, we would regex for /[\s]*use_frameworks!.+?\n/ and replace the line with a commented version and a note that our plugin did the commenting-out.

This, like the upstream change, requires a note about incompatibility with plugins that enable use_frameworks. However, I'd really like to solve this the first or second way since that's more in line with how expo's trying to manage the config plugin ecosystem.


@jakobo jakobo added bug Something isn't working upstream expo Upstream issue with expo (check linked issues) and removed upstream flipper Upstream issue with fbflipper (check linked issues) labels Oct 1, 2022
@nkalinov
Copy link
Author

nkalinov commented Oct 1, 2022

I am actually already setting useFrameworks to static via the expo-build-properties plugin. This was a requirement of expo-firebase-analytics that I'm using as well. Here's the relevant instructions https://docs.expo.dev/versions/latest/sdk/firebase-analytics/#additional-configuration-for-ios

Here's my full set of plugins:

    "plugins": [
      [
        "expo-build-properties",
        {
          "ios": {
            "useFrameworks": "static"
          }
        }
      ],
      "expo-community-flipper",
      "sentry-expo",
      [
        "expo-tracking-transparency",
        {
          "userTrackingPermission": "We use Tracking to fix bugs and improve your experience."
        }
      ]
    ],

I can confirm the build succeeds when expo-firebase-analytics and ["expo-build-properties",{"ios": {"useFrameworks": "static"}}] are not present so it's definitely an incompatibility between this plugin and static useFrameworks.

Is that expected to work with static useFrameworks?
Maybe this plugin needs to check for useFrameworks and if present follow the additional instructions from this Podfile comment - https://fbflipper.com/docs/getting-started/ios-native/#cocoapods

  # If you use `use_frameworks!` in your Podfile,
  # uncomment the below $static_framework array and also
  # the pre_install section.  This will cause Flipper and
  # it's dependencies to be built as a static library and all other pods to
  # be dynamic.
  #
  # NOTE Doing this may lead to a broken build if any of these are also
  #      transitive dependencies of other dependencies and are expected
  #      to be built as frameworks.
  #
  # $static_framework = ['FlipperKit', 'Flipper', 'Flipper-Folly',
  #   'CocoaAsyncSocket', 'ComponentKit', 'Flipper-DoubleConversion',
  #   'Flipper-Glog', 'Flipper-PeerTalk', 'Flipper-RSocket', 'Yoga', 'YogaKit',
  #   'CocoaLibEvent', 'OpenSSL-Universal', 'boost-for-react-native', 'Flipper-Fmt']
  #
  # pre_install do |installer|
  #   Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
  #   installer.pod_targets.each do |pod|
  #       if $static_framework.include?(pod.name)
  #         def pod.build_type;
  #           Pod::BuildType.static_library
  #         end
  #       end
  #     end
  # end

@jakobo
Copy link
Owner

jakobo commented Oct 1, 2022

Yeah. I was hoping to avoid the static linking statements, specifically because of the transitive dependency problem they mention:

  # NOTE Doing this may lead to a broken build if any of these are also
  #      transitive dependencies of other dependencies and are expected
  #      to be built as frameworks.

There are a lot of pods that use OpenSSL-universal. Unfortunately, firebase absolutely needs the use _frameworks line as of v15+.

On the rn-firebase repo, they are trying the static link solution above without success. The flipper issue here makes it clear that there is no chance of use_frameworks and flipper working together. 😭

This might literally be a “these don’t work together” problem, and adding flipper will explicitly remove use_frameworks.

@jakobo jakobo added upstream flipper Upstream issue with fbflipper (check linked issues) and removed upstream expo Upstream issue with expo (check linked issues) labels Oct 1, 2022
@jakobo
Copy link
Owner

jakobo commented Oct 1, 2022

Note: it's pretty clear at this point it's a flipper + use_frameworks issue, and is highly likely that this needs to be fixed at the rn/flipper layer. Our best path forward seems to be pinning a library compatibility thread and making this plug-in strip the use_frameworks

@jakobo
Copy link
Owner

jakobo commented Oct 1, 2022

@all-contributors please add @nkalinov for bugs, this has been a huge help. The next revision to the plugin will make it possible to choose flipper or use_frameworks so at least you can get Flipper support on Android

@allcontributors
Copy link
Contributor

@jakobo

I've put up a pull request to add @nkalinov! 🎉

@jakobo
Copy link
Owner

jakobo commented Oct 1, 2022

Workaround available in v46.0.2 via a configuration option. You can explicitly disable flipper in iOS if you're using a plugin that requires use_frameworks to be enabled.

@jakobo jakobo removed the investigating Ongoing conversation about the issue label Oct 1, 2022
@nkalinov
Copy link
Author

nkalinov commented Oct 1, 2022

I'll try the new options, thank you so much! But first, I need to dig into another failure related to expo-firebase-analytics - the latest version won't build even without expo-community-flipper. It fails with 'react/bridging/CallbackWrapper.h' file not found.

@Kudo
Copy link
Contributor

Kudo commented Oct 2, 2022

hi there! this is Kudo from expo. for the flipper + use_frameworks issue, i think it's currently breaking as the issue states. hopefully there's something flipper team could pay more attention on it.

if there's any thing we could help from expo side, please let me know. thanks!

@jakobo
Copy link
Owner

jakobo commented Oct 2, 2022

Thanks Kudo (sorry about the tag, but I figured if anyone understood the config plugin changes on expo side it would be you or Evan).

I'm not sure there's anything we can do from the expo side unless you think we could change the expo-build-properties plugin to only add the use_frameworks! statement to the Podfile if ios.useFrameworks is set. At least then people would be matching the current react-native ecosystem where you can't use Flipper and use_frameworks at the same time.

For now, I've added the ability for this plugin to strip the use_frameworks lines via a ruby block-comment.

@Kudo
Copy link
Contributor

Kudo commented Oct 3, 2022

I'm not sure there's anything we can do from the expo side unless you think we could change the expo-build-properties plugin to only add the use_frameworks! statement to the Podfile if ios.useFrameworks is set.

actually we did. please see the tail of this line, it is:
use_frameworks! :linkage => podfile_properties['ios.useFrameworks'].to_sym if podfile_properties['ios.useFrameworks']

fwiw, for upcoming sdk 47, i also changed the Podfile a little bit. especially for the flipper settings here. hopefully that would not break the config-plugin from expo-community-flipper. please let me know how do you think for it. thanks!

@jakobo
Copy link
Owner

jakobo commented Oct 3, 2022

i also changed the Podfile a little bit

We anchor off of the fabric_enabled arg instead of the flipper enabled statement (as it'd be easier to catch if the fabric arg changed), so I think we'll be okay in SDK47.

Also, the tailed line helps a ton. I think that gives us "as good as it gets" parity with a regular react-native setup. Appreciate your support on all of this from the Expo side. @all-contributors, can you add @Kudo for docs and questions? ❤️

@jakobo
Copy link
Owner

jakobo commented Oct 3, 2022

@nkalinov I'm going to close this for now, as we will either need to pick firebase or flipper on iOS 😢 However, we'll keep tracking the flipper project to see if the use_frameworks ever does get resolved. Just let me know if we need to reopen down the road.

@jakobo jakobo closed this as completed Oct 3, 2022
@viljark
Copy link

viljark commented Oct 13, 2022

Just adding a comment if someone runs also into these exceptions when building for iOS with expo-build-properties with useFrameworks: 'static' + expo-community-flipper

❌ error: Multiple commands produce '/Users/expo/Library/Developer/Xcode/DerivedData/MyApp-bxmbpizqcfjivacfihxakrpkfskb/Build/Intermediates.noindex/ArchiveIntermediates/MyApp/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/fmt.framework'

❌ error: Multiple commands produce '/Users/expo/Library/Developer/Xcode/DerivedData/MyApp-bxmbpizqcfjivacfihxakrpkfskb/Build/Intermediates.noindex/ArchiveIntermediates/MyApp/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/folly.framework'

For now I fixed it by setting in eas.json

      "ios": {
        "env": {
          "FLIPPER_DISABLE": "1"
        },
      },

@zyc
Copy link

zyc commented Jan 29, 2023

Just adding a comment if someone runs also into these exceptions when building for iOS with expo-build-properties with useFrameworks: 'static' + expo-community-flipper

❌ error: Multiple commands produce '/Users/expo/Library/Developer/Xcode/DerivedData/MyApp-bxmbpizqcfjivacfihxakrpkfskb/Build/Intermediates.noindex/ArchiveIntermediates/MyApp/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/fmt.framework'

❌ error: Multiple commands produce '/Users/expo/Library/Developer/Xcode/DerivedData/MyApp-bxmbpizqcfjivacfihxakrpkfskb/Build/Intermediates.noindex/ArchiveIntermediates/MyApp/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/folly.framework'

For now I fixed it by setting in eas.json

      "ios": {
        "env": {
          "FLIPPER_DISABLE": "1"
        },
      },

Just to clarify, do you mean here? Or somewhere else?

{
  "build": {
    "DEVELOPMENT_PROFILE": {
      "ios": {
        "env": {
          "FLIPPER_DISABLE": "1"
        }
      }
    }
  }
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working SDK 46 Affects plugin in Expo SDK 46 upstream flipper Upstream issue with fbflipper (check linked issues)
Projects
None yet
Development

No branches or pull requests

5 participants