Skip to content

Use of iOS dynamic frameworks in a custom extension (use_frameworks! or use_modular_headers!) #73

@Souro7

Description

@Souro7

What we are trying to do

We are trying to use a dynamic framework (native iOS swift) for our extension. Specifically, use_frameworks! is being used.

What we have tried so far

For this, we have created a react-native bridge, which uses the same Framework.
This works perfectly in our react-native app when we add the following to our Podfile:

use_frameworks!
  pre_install do |installer|
     installer.pod_targets.each do |pod|
       if pod.name.eql?('RNPermissions') || pod.name.start_with?('Permission-')
         def pod.build_type;
           Pod::BuildType.static_library # I assume you use CocoaPods >= 1.9
         end
       end
     end
   end

We have published a version of our extension using the same, however the shoutem clone command fails at pod install with the following error when we clone this app from shoutem:

Screenshot 2020-10-08 at 6 19 54 PM

Again to fix this, we made the following changes to the Podfile:

pre_install do |installer|
    Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
    installer.pod_targets.each do |pod|
      if pod.name.eql?('RNPermissions') || pod.name.start_with?('Permission-')
                              def pod.build_type;
                                Pod::BuildType.static_library
                              end
                            end
        if $static_framework.include?(pod.name)
          def pod.build_type;
            Pod::BuildType.static_library
          end
        end
      end
  end

This resolves the pod install issue. However, this leads to Build fail with the following errors:

Screenshot 2020-10-08 at 6 34 01 PM

Another approach we have tried is use_modular_headers! instead of use_frameworks!. This eliminates the previous errors, however, the Build still fails with the following error:

Screenshot 2020-10-08 at 6 39 38 PM

Our entire Podfile is attached below:

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.0'

install! 'cocoapods', :deterministic_uuids => false

target 'NewTest' do
  config = use_native_modules!

  use_react_native!

  pod 'Shopify', :path => '../node_modules/shoutem.shopify/Shopify.podspec'
  
  # React Native FBSDK dependencies
  pod 'FBSDKCoreKit'
  pod 'FBSDKLoginKit'

  use_modular_headers!
  $static_framework = ['CocoaLibEvent', 'openssl-ios-bitcode', 'OpenSSL-Universal']

  pre_install do |installer|
    Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
    installer.pod_targets.each do |pod|
      if pod.name.eql?('RNPermissions') || pod.name.start_with?('Permission-')
                              def pod.build_type;
                                Pod::BuildType.static_library
                              end
                            end
        if $static_framework.include?(pod.name)
          def pod.build_type;
            Pod::BuildType.static_library
          end
        end
      end
  end
             pod 'RNNearBee', :path => '../node_modules/react-native-nearbee'
             pod 'ReactNativePermissions', :path => '../node_modules/react-native-permissions-ble-fix'
             pod 'Permission-BluetoothPeripheral', :path => "../node_modules/react-native-permissions/ios/BluetoothPeripheral.podspec"
             pod 'Permission-LocationAlways', :path => "../node_modules/react-native-permissions/ios/LocationAlways.podspec"
             pod 'Permission-LocationWhenInUse', :path => "../node_modules/react-native-permissions/ios/LocationWhenInUse.podspec"
             pod 'Permission-Notifications', :path => "../node_modules/react-native-permissions/ios/Notifications.podspec"

end

## <Additional target>

use_flipper!
post_install do |installer|
  flipper_post_install(installer)
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['EXPANDED_CODE_SIGN_IDENTITY'] = ""
      config.build_settings['CODE_SIGNING_REQUIRED'] = "NO"
      config.build_settings['CODE_SIGNING_ALLOWED'] = "NO"
    end

    ## <Extension postinstall targets>
    
                if target.name == 'Starscream'
                    target.build_configurations.each do |config|
                        config.build_settings['SWIFT_VERSION'] = '4.2'
                    end
                end
            
  end
end

Question

We can see that it is mentioned in your documentation that we are supposed to

Uncomment this line if you're using Swift or would like to use dynamic frameworks: https://shoutem.github.io/docs/extensions/tutorials/using-native-api#referencing-a-3rd-party-sdk

Is there a way to use iOS dynamic frameworks in our extension?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions