react-native-skia icon indicating copy to clipboard operation
react-native-skia copied to clipboard

SkData.h not found when using use_frameworks!

Open dpyeates opened this issue 3 years ago • 26 comments

Adding use_frameworks! :linkage => :static to my podlike (required for RN Firebase) and I get a failed build on skia due to missing headers?

.../node_modules/@shopify/react-native-skia/cpp/skia/include/core/SkStream.h:11:10: 'include/core/SkData.h' file not found

dpyeates avatar Jun 30 '22 14:06 dpyeates

Hi, @dpyeates! I'm not able to find any mention of use_frameworks! :linkage => :static in the Firebase installation examples - I'm seeing that they require enabling frameworks, but the only requirement for this should be use_frameworks!? Setting linkage to static globally like you suggest looks a bit suspect as there might be other libs not working with this switch.

chrfalch avatar Jul 01 '22 06:07 chrfalch

@chrfalch agreed, I was using it temporarily as a work around waiting for a package update.

However, even just having use_frameworks! I still get the same error?

@shopify/react-native-skia/cpp/skia/include/core/SkStream.h:11:10: 'include/core/SkData.h' file not found

dpyeates avatar Jul 11 '22 16:07 dpyeates

Has anyone been able to get RN Skia working in conjunction with Firebase and use_frameworks? Would you be able to share your podfile config? I've been at this a while now and have tried seemingly every option without any success.

Here is my current pod file:

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '12.4'
install! 'cocoapods', :deterministic_uuids => false

target 'RNApp' do
  config = use_native_modules!
  config = use_frameworks!
  $FirebaseSDKVersion = '9.3.0'
  $RNFirebaseAsStaticFramework = true
  $RNGoogleMobileAdsAsStaticFramework = true

  use_react_native!(
    :path => config[:reactNativePath],
    :hermes_enabled => true,
    :fabric_enabled => false,
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  pod 'rnmapbox-maps', :path => '../node_modules/@rnmapbox/maps', :inhibit_warnings => false

  pre_install do |installer|
    $RNMapboxMaps.pre_install(installer)
  end

  # Enables Flipper.
  #
  # Note that if you have use_frameworks! enabled, Flipper will not work and
  # you should disable the next line.
  # use_flipper!()

  post_install do |installer|
    react_native_post_install(installer)
    __apply_Xcode_12_5_M1_post_install_workaround(installer) if defined?(__apply_Xcode_12_5_M1_post_install_workaround)
    $RNMapboxMaps.post_install(installer)
  end
end

dpyeates avatar Jul 16 '22 11:07 dpyeates

@chrfalch could you try building using use_frameworks! and see if you get the same error please?

dpyeates avatar Jul 18 '22 12:07 dpyeates

Well, I got it to work with the workaround below since we also use React Native Firebase and just got started with React Native Skia:


Found this ruby package called cocoapods-user-defined-build-types that "allows to specify how each pods are built" - as the package says.

So, in our case, we have:

Note: I've included my M1 specific workarounds but if you're on an intel, I'm assuming you won't need that.

plugin 'cocoapods-user-defined-build-types'

enable_user_defined_build_types!

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '11'
install! 'cocoapods', :deterministic_uuids => false

# Replace RNAppName with your app name
target 'RNAppName' do

  config = use_native_modules!

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

  # Here's the specific fix for React Native Firebase
  pod "FirebaseCoreInternal", :build_type => :dynamic_framework
  pod "FirebaseCore", :build_type => :dynamic_framework
  
  use_native_modules!

  use_react_native!(
    :path => config[:reactNativePath],
    # to enable hermes on iOS, change `false` to `true` and then install pods
    :hermes_enabled => flags[:hermes_enabled],
    :fabric_enabled => flags[:fabric_enabled],
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  ## All this is M1 mac specific
  post_install do |installer|
    installer.pods_project.targets.each do |target|
      case target.name
      when 'RCT-Folly'
        target.build_configurations.each do |config|
          config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '9.0'
        end
      else
        target.build_configurations.each do |config|
          config.build_settings['IPHONEOS_DEPLOYMENT_TARGET']= '12.0'
        end
      end
    end
    react_native_post_install(installer)
      installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
          config.build_settings["ONLY_ACTIVE_ARCH"] = "NO"
        end
    end
    installer.aggregate_targets.first.user_project.native_targets.each do |target|
      target.build_configurations.each do |config|
        config.build_settings['LIBRARY_SEARCH_PATHS'] = ['$(inherited)', '$(SDKROOT)/usr/lib/swift']
      end
    end
    __apply_Xcode_12_5_M1_post_install_workaround(installer)
  end
end

laudebugs avatar Jul 19 '22 02:07 laudebugs

@laudebugs Thanks for the suggestion! @dpyeates Could you test out if this works for you?

chrfalch avatar Jul 19 '22 07:07 chrfalch

I'm trying :-) Having a few problems getting that gem to work. @laudebugs which version of CocoaPods are you using? I'm using 1.11.3 on an M1 Mac and I'm getting

[!] Your Podfile requires that the plugin cocoapods-user-defined-build-types be installed. Please install it and try installation again.

The gem installs OK after adding it to my Gemfile and doing a bundle install, but the pod install doesn't seem to be finding it. Still investigating - will update ASAP.

dpyeates avatar Jul 19 '22 15:07 dpyeates

try running gem install cocoapods-user-defined-build-types in your ios folder?

I'm trying :-) Having a few problems getting that gem to work. @laudebugs which version of CocoaPods are you using? I'm using 1.11.3 on an M1 Mac and I'm getting

[!] Your Podfile requires that the plugin cocoapods-user-defined-build-types be installed. Please install it and try installation again.

The gem installs OK after adding it to my Gemfile and doing a bundle install, but the pod install doesn't seem to be finding it. Still investigating - will update ASAP.

laudebugs avatar Jul 19 '22 15:07 laudebugs

Hmmm, no idea why that made a difference but it did. gem seems to work OK now. I had to add additional Firebase pod as I am using other Firebase libraries:

pod "FirebaseCoreInternal", :build_type => :dynamic_framework
pod "FirebaseCore", :build_type => :dynamic_framework
pod "FirebaseStorageInternal", :build_type => :dynamic_framework
pod "FirebaseAppCheckInterop", :build_type => :dynamic_framework
pod "FirebaseAuthInterop", :build_type => :dynamic_framework
pod "FirebaseCoreExtension", :build_type => :dynamic_framework
pod "FirebaseCrashlytics", :build_type => :dynamic_framework

However, I don't get to tell if Skia builds as Firebase modules fail to build before hand.

Screenshot 2022-07-19 at 18 06 38

dpyeates avatar Jul 19 '22 17:07 dpyeates

Hmmm, no idea why that made a difference but it did. gem seems to work OK now. I had to add additional Firebase pod as I am using other Firebase libraries:

pod "FirebaseCoreInternal", :build_type => :dynamic_framework
pod "FirebaseCore", :build_type => :dynamic_framework
pod "FirebaseStorageInternal", :build_type => :dynamic_framework
pod "FirebaseAppCheckInterop", :build_type => :dynamic_framework
pod "FirebaseAuthInterop", :build_type => :dynamic_framework
pod "FirebaseCoreExtension", :build_type => :dynamic_framework
pod "FirebaseCrashlytics", :build_type => :dynamic_framework

However, I don't get to tell if Skia builds as Firebase modules fail to build before hand.

Screenshot 2022-07-19 at 18 06 38

This happens even after cleaning your ios build folder and reinstalling pods?

laudebugs avatar Jul 19 '22 19:07 laudebugs

Yes. It seems there is an issue with @react-native-firebase/storage which means this isn't working quite right. If I remove @react-native-firebase/storage from my build I got one other Skia related error related to react-native bridging paths which I resolved with another workaround in the post_install before I got a successful build.

Worth noting that I also got it working without using the cocoapods-user-defined-build-types gem, by setting RNFirebaseAsStaticFramework to true and setting modular_headers => true on each Firebase library that I required.

$RNFirebaseAsStaticFramework = true
pod "[FB pod name here]", :modular_headers => true

To summarise: RNSkia doesn't build with use_frameworks! at the moment. So any dependent library you use that does require frameworks (such as Firebase) you will need to at to your pod file and set modular_headers => true.

Here is my pod file - I have FirebaseStorage excluded until I get a fix here

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '12.4'
install! 'cocoapods', :deterministic_uuids => false

target 'fdeck' do
  config = use_native_modules!

  $FirebaseSDKVersion = '9.3.0'
  $RNFirebaseAsStaticFramework = true
  pod "FirebaseCore", :modular_headers => true
  pod "FirebaseCoreInternal", :modular_headers => true
  pod "FirebaseCoreExtension", :modular_headers => true
  #pod 'FirebaseStorage', :modular_headers => true
  #pod "FirebaseStorageInternal", :modular_headers => true
  pod "FirebaseAppCheckInterop", :modular_headers => true
  pod "FirebaseAuthInterop", :modular_headers => true
  pod "FirebaseCrashlytics", :modular_headers => true
  pod "GoogleUtilities", :modular_headers => true

  use_react_native!(
    :path => config[:reactNativePath],
    :hermes_enabled => true,
    :fabric_enabled => false,
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  pod 'rnmapbox-maps', :path => '../node_modules/@rnmapbox/maps', :inhibit_warnings => false

  pre_install do |installer|
    $RNMapboxMaps.pre_install(installer)
  end

  # Enables Flipper.
  #
  # Note that if you have use_frameworks! enabled, Flipper will not work and
  # you should disable these next few lines.
  use_flipper!()

  post_install do |installer|

  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
         config.build_settings['HEADER_SEARCH_PATHS'] ||= '$(inherited) '
         config.build_settings['HEADER_SEARCH_PATHS'] << '"$(PODS_ROOT)/Headers/Private/React-bridging/react/bridging" '
         config.build_settings['HEADER_SEARCH_PATHS'] << '"$(PODS_CONFIGURATION_BUILD_DIR)/React-bridging/react_bridging.framework/Headers" '
       end
     end

    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        # This makes the iOS build much quieter.
        # In particular libevent dependency, pulled in by react core / flipper items is ridiculously noisy
        config.build_settings["GCC_WARN_INHIBIT_ALL_WARNINGS"] = "YES"
        # Another workaround needed for static framework build
        # Bitcode will not work with it, but that's okay, bitcode is deprecated
        # https://github.com/facebook/react-native/pull/34030#issuecomment-1171197734
        config.build_settings["ENABLE_BITCODE"] = "NO"
        # Required for Apple Silicon Macs
        config.build_settings["ONLY_ACTIVE_ARCH"] = "NO"
        # Required to allow react-native-skia to build (hopefully can come out with next RN patch release)
        config.build_settings['HEADER_SEARCH_PATHS'] ||= '$(inherited) '
        config.build_settings['HEADER_SEARCH_PATHS'] << '"$(PODS_ROOT)/Headers/Private/React-bridging/react/bridging" '
        config.build_settings['HEADER_SEARCH_PATHS'] << '"$(PODS_CONFIGURATION_BUILD_DIR)/React-bridging/react_bridging.framework/Headers" '
      end
    end
    # Apple Silicon builds require a library path tweak for Swift discovery or we get "symbol not found"
    installer.aggregate_targets.first.user_project.native_targets.each do |target|
      target.build_configurations.each do |config|
        config.build_settings['LIBRARY_SEARCH_PATHS'] = ['$(inherited)', '$(SDKROOT)/usr/lib/swift']
      end
    end
    __apply_Xcode_12_5_M1_post_install_workaround(installer)
    $RNMapboxMaps.post_install(installer)
  end
end

dpyeates avatar Jul 20 '22 11:07 dpyeates

Unfortunately, these workarounds do not work for us because we need to use use_frameworks! :linkage => :static (https://github.com/idnow/de.idnow.ios/issues/119). @chrfalch Are there any plans to make react-native-skia compatible with this build type? This is currently holding us back from integrating this library.

reichhartd avatar Jul 27 '22 12:07 reichhartd

Hi @reichhartd - could you look into how this can be done and what we'd need to support? A PR would be very welcome.

chrfalch avatar Jul 27 '22 12:07 chrfalch

Unfortunately, I have only rudimentary knowledge of cocoapods myself. I am currently reading up on the exact difference: Cocoa Touch Static Library vs. Cocoa Touch Framework

When I look at a similar issue with sentry-react-native (https://github.com/getsentry/sentry-react-native/pull/2369), the problem seems to be a reference to a private cocoa SDK class.

I also have a lot to do at the moment, so I can't promise to take over the issue.

Edit: This article explain the difference better: Basic overview of static and dynamic frameworks on iOS

reichhartd avatar Jul 27 '22 13:07 reichhartd

It works in combination with use_frameworks! linkage: :static if you remove the folder prefix from the header imports of the Skia lib. I don't know how reasonable these contribution and a pull request would be though. Since you would have to change a large part of the lib, I would say that is rather unrealistically.

image

reichhartd avatar Aug 08 '22 20:08 reichhartd

I'm seeing the same as @dpyeates and @reichhartd

imsherrill avatar Aug 11 '22 12:08 imsherrill

I'm also seeing this. Forced to run with use_frameworks! because of react-native-firebase (https://github.com/invertase/react-native-firebase/issues/6322).

trymbill avatar Aug 24 '22 20:08 trymbill

How can we move this forward? What changes need to be made to support use_frameworks? react-native-firebase is perhaps one of the most popular libraries and it has a hard requirement on use_frameworks going forward due to the underlying upstream iOS firebase libraries. It would be a shame if nobody using firebase could use skia!

evelant avatar Aug 29 '22 17:08 evelant

As a very temporary workaround you can roll back to react-native-firebase version 14.11.1 and remove use_frameworks, that's the last version of rnfirebase that can build without use_frameworks.

evelant avatar Aug 29 '22 17:08 evelant

Would it be possible to create a small repo showing this issue (preferably as a Github repo) so that we can investigate?

chrfalch avatar Aug 29 '22 18:08 chrfalch

The easiest way is to add the line use_frameworks! linkage: :static to the Podfile in the example project of this repository, and disable Flipper.

Otherwise, I created a repository here, for which I added the React Native TypeScript template. Only react-native-skia was installed, and just the line use_frameworks! linkage: :static was added to the Podfile.

The error appears when you try to launch the iOS app.

reichhartd avatar Aug 30 '22 13:08 reichhartd

Same here!

guhcostan-tw avatar Sep 14 '22 14:09 guhcostan-tw

Any updates on this issue?

enchorb avatar Sep 17 '22 14:09 enchorb

I tried adding use_frameworks! linkage: :static to a new RN 0.70.0 project and ended up with an error about Flipper not being found - so it doesn't even work with Flipper?

I found some information about Firebase now supporting static frameworks here: https://firebase.google.com/docs/ios/link-firebase-static-dynamic

chrfalch avatar Sep 19 '22 10:09 chrfalch

Flipper does not work with use_frameworks! as described in my comment above, and also in the Podfile of the template. https://github.com/facebook/react-native/blob/0.70-stable/template/ios/Podfile#L20-L23

reichhartd avatar Sep 19 '22 10:09 reichhartd

Correct - and I think the problem lies with Firebase, could you all try to follow the link and see if there are other options linking Firebase in later versions that doesn't affect linking of all other libraries in the App?

chrfalch avatar Sep 19 '22 10:09 chrfalch

any update on this issue?

Sundarcj avatar Sep 22 '22 13:09 Sundarcj

This won't work for us, as we also have react-native-idnow-videoident as a hard-dependency, which also requires use_frameworks!. I created an issue in their repository a couple months ago, if it is possible to set the link type freely. Unfortunately there is no answer yet.

I don't have a strong opinion which one I prefer, I think it should be up to the user which link type to use, because otherwise there will always be conflicting libraries.

reichhartd avatar Sep 22 '22 16:09 reichhartd

The issue is still happening any fix?

ckOfor avatar Oct 05 '22 08:10 ckOfor

Ahh! this dependency loop is quite frustrating. I removed Firebase entirely from my project (not only due to the above) and have been enjoying Skia since, however, I just integrated Appodeal, which requires use_frameworks and again this issue has resurfaced. It is not a Firebase issue. It is that Skia has missing headers if you define use_frameworks, or use_frameworks! :linkage => :static

dpyeates avatar Oct 07 '22 15:10 dpyeates