prscX / react-native-selection-menu

React Native: Native Selection Menu
Apache License 2.0
110 stars 8 forks source link

Unable to use on RN 0.62.2 #16

Closed Doko-Demo-Doa closed 4 years ago

Doko-Demo-Doa commented 4 years ago

This is part of my Podfile:

  use_native_modules!
  pod 'RNSelectionMenu', :path => '../node_modules/react-native-selection-menu/ios'

  use_frameworks!
  pod 'BRYXBanner', :git => 'https://github.com/prscX/BRYXBanner.git', :branch => 'master'
  pod 'RSSelectionMenu', :git => 'https://github.com/prscX/RSSelectionMenu.git', :branch => 'objc-bridge'

  # Enables Flipper.
  #
  # Note that if you have use_frameworks! enabled, Flipper will not work and
  # you should disable these next few lines.
  add_flipper_pods!
  post_install do |installer|
    flipper_post_install(installer)

    installer.pods_project.targets.each do |target|
      if target.name.include?('BRYXBanner')
        target.build_configurations.each do |config|
          config.build_settings['SWIFT_VERSION'] = '4.2'
        end
      end

      if target.name.include?('RSSelectionMenu')
        target.build_configurations.each do |config|
          config.build_settings['SWIFT_VERSION'] = '4.1'
        end
      end
    end
  end

I use two libraries of yours: notification banner and selection menu. And the issue is:

image

What could be wrong?

Doko-Demo-Doa commented 4 years ago

Found the solution: Add following code to the Podfile:

  dynamic_frameworks = ['BRYXBanner', 'RSSelectionMenu']
  # Make all the other frameworks into static frameworks by overriding the static_framework? function to return true
  pre_install do |installer|
    installer.pod_targets.each do |pod|
      if !dynamic_frameworks.include?(pod.name)
        def pod.static_framework?;
          true
        end
        def pod.build_type;
          Pod::BuildType.static_library
        end
      end
    end
  end

It should look like this as a whole:

  add_flipper_pods!
  post_install do |installer|
    flipper_post_install(installer)

    installer.pods_project.targets.each do |target|
      if target.name.include?('BRYXBanner')
        target.build_configurations.each do |config|
          config.build_settings['SWIFT_VERSION'] = '4.2'
        end
      end

      if target.name.include?('RSSelectionMenu')
        target.build_configurations.each do |config|
          config.build_settings['SWIFT_VERSION'] = '4.2'
        end
      end
    end
  end

  dynamic_frameworks = ['BRYXBanner', 'RSSelectionMenu']
  # Make all the other frameworks into static frameworks by overriding the static_framework? function to return true
  pre_install do |installer|
    installer.pod_targets.each do |pod|
      if !dynamic_frameworks.include?(pod.name)
        def pod.static_framework?;
          true
        end
        def pod.build_type;
          Pod::BuildType.static_library
        end
      end
    end
  end
prscX commented 4 years ago

Many Thanks @Doko-Demo-Doa for sharing the fix. You have saved my day 😄, I was actually planning to look into this issue.

I have updated README with the installation steps and will update the same at other libraries as well.

Thanks </ Pranav >

Doko-Demo-Doa commented 4 years ago

@prscX I think you should add a more detailed description for this kind of issue. For example, two libraries I use are react-native-notification-banner and react-native-selection-menu. To use them at once, first we need to config the Swift version for each:

  post_install do |installer|
    flipper_post_install(installer)

    # This one is for react-native-notification-banner
    installer.pods_project.targets.each do |target|
      if target.name.include?('BRYXBanner')
        target.build_configurations.each do |config|
          config.build_settings['SWIFT_VERSION'] = '4.2'
        end
      end

      # This one is for react-native-selection-menu
      if target.name.include?('RSSelectionMenu')
        target.build_configurations.each do |config|
          config.build_settings['SWIFT_VERSION'] = '4.1'
        end
      end
    end
  end

At the last block, we have to make other frameworks into static framework, excluding above libs, so dynamic_frameworks will be declared as array:

  dynamic_frameworks = ['BRYXBanner', 'RSSelectionMenu'] # << Here, add the lib name.
  # Make all the other frameworks into static frameworks by overriding the static_framework? function to return true
  pre_install do |installer|
    installer.pod_targets.each do |pod|
      if !dynamic_frameworks.include?(pod.name)
        def pod.static_framework?;
          true
        end
        def pod.build_type;
          Pod::BuildType.static_library
        end
      end
    end
  end

It will be easier to understand.