Thanh TO HIEU
Thanh TO HIEU

Reputation: 13

Build fail when using use_frameworks! react-native

I'm developing an app using React-native 0.59.1. But I've got an issue that I can not link a static library. In Podfile I am installing both frameworks and library using Cocapods. Xcode will throw an error the library is not linked yet when Podfile contains the keyword use_framework!, but is successful if I remove this keyword. Can you help me to fix it?

platform :ios, '10.0'

target 'Test_RN_0_59_1' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  rn_path = '../node_modules/react-native'

  pod 'yoga', path: "#{rn_path}/ReactCommon/yoga/yoga.podspec"
  pod 'DoubleConversion', :podspec => "#{rn_path}/third-party-podspecs/DoubleConversion.podspec"
  pod 'Folly', :podspec => "#{rn_path}/third-party-podspecs/Folly.podspec"
  pod 'glog', :podspec => "#{rn_path}/third-party-podspecs/GLog.podspec"
  pod 'React', path: rn_path, subspecs: [
    'Core',
    'CxxBridge',
    'RCTAnimation',
    'RCTActionSheet',
    'RCTImage',
    'RCTLinkingIOS',
    'RCTNetwork',
    'RCTSettings',
    'RCTText',
    'RCTVibration',
    'RCTWebSocket',
    'RCTPushNotification',
    'RCTCameraRoll',
    'RCTSettings',
    'RCTBlob',
    'RCTGeolocation',
    'DevSupport'
  ]
  
  pod 'rn-juicy-score', :path => '../node_modules/rn-juicy-score'

Capture

Upvotes: 1

Views: 5755

Answers (2)

Jagjot
Jagjot

Reputation: 6136

If you want to use static library with use_framework! in React Native, you can use the following solution:

...
pod 'rn-juicy-score', :path => '../node_modules/rn-juicy-score'

pre_install do |installer|
  installer.pod_targets.each do |pod|
    if pod.name.eql?('rn-juicy-score')
      def pod.build_type
        Pod::BuildType.static_library
      end
    end
  end
end

Adding a condition in pre_install block would make sure your specified pod is built using static library and the rest are built using dynamic framework. This will allow you to use both build systems and configure according to requirement.

Upvotes: 4

Leandro Ariel
Leandro Ariel

Reputation: 1421

If you are using react native > 0.68.x, you need use use_frameworks!, you must to add in your Podfile this code:

  $static_framework = ['Flipper-Boost-iOSX', 'Flipper-RSocket', 'glog', 'Yoga', 'YogaKit', 'React-logger', 'Flipper-Fmt', 'RCT-Folly', 'Flipper-Folly', 'React-jsi', 'FlipperKit', 'Flipper', 'Flipper-Glog', 'Flipper-PeerTalk', 'React-cxxreact', 'React-jsiexecutor', 'React-Core', 'React-RCTText', 'RCTTypeSafety', 'ReactCommon', 'React-Codegen', 'React-RCTVibration', 'React-RCTSettings', 'React-RCTNetwork', 'React-RCTLinking', 'React-RCTAnimation', 'React-RCTBlob', 'React-RCTImage', 'React-CoreModules']

  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

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

After that run pod install to update the changes. I tested this in Intel & M1 mac's.

Upvotes: 3

Related Questions