Search code examples
react-nativecocoapods

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


Solution

  • 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.