braintree / braintree_ios

Braintree SDK for iOS
https://developer.paypal.com/braintree/docs/start/hello-client/ios/v5
MIT License
560 stars 294 forks source link

'Braintree/Braintree-Swift.h' file not found in React Native project using CocoaPods #671

Closed jbatra-umeey closed 3 years ago

jbatra-umeey commented 3 years ago

Integration Details

Describe the bug

When updating to 5.3.0 we get an error during the compilation of the header file 'Braintree/Braintree-Swift.h' . The current version we are using is 4.37.1 In continuation to issue https://github.com/braintree/braintree_ios/issues/651

Podfile :

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.0'
use_frameworks!
inhibit_all_warnings!
target 'demoReactNativeApp' do
  config = use_native_modules!

pod 'Braintree'
pod 'Braintree/Venmo'

  use_react_native!(
    :path => config[:reactNativePath],
    # to enable hermes on iOS, change `false` to `true` and then install pods
    :hermes_enabled => false
  )

  # 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)
  end

end

To Reproduce There are no explicit steps to reproduce, other than try to update the version

Expected behavior Success build with the latest version

Screenshots

Screenshot 2021-05-05 at 1 34 46 PM

In the project directory, I can see this file present. Any changes needed in the main project's build settings?

Screenshot 2021-05-05 at 4 05 34 PM

As a workaround can we skip PayPalDataCollector from cocoa pods?

sestevens commented 3 years ago

As a workaround can we skip PayPalDataCollector from cocoa pods?

This depends on which payment methods you're using. If you're using PayPal, which is included by default with pod 'Braintree', then PayPalDataCollector is required. You can take a look at all of the dependencies in Braintree.podspec.

As mentioned in #651, we don't officially support React Native. However, if you have any suggestions or ideas about how to fix this issue, we're more than happy to review a PR.

jbatra-umeey commented 3 years ago

@sestevens Thanks for the prompt revert. Any tips to debug it?

Few workarounds I tried :

I suppose we should also have a look at Braintree.modulemap

module Braintree {
 umbrella header "Braintree-umbrella.h"

  export *
  module * { export * }
}
sestevens commented 3 years ago

I found a similar issue on CocoaPods, but it looks like the solution there was to use angle brackets < > on the import instead of quotes, which we're already doing.

I also see a similar issue here, and the solution was to use @import instead of #import. That might be worth a try, as long as it doesn't break anything for integrations that aren't using React Native.

jbatra-umeey commented 3 years ago

Ok, I managed to fix the umbrella header issue in BTPayPalDriver.m by replacing #import <Braintree/Braintree-Swift.h> with #import "Braintree-Swift.h"

I was getting the below issue on Xcode 12.4 :

Undefined symbols for architecture arm64:
  "__swift_FORCE_LOAD_$_swiftWebKit", referenced from:
      __swift_FORCE_LOAD_$_swiftWebKit_$_Braintree in libBraintree.a(PPDataCollector.o)
     (maybe you meant: __swift_FORCE_LOAD_$_swiftWebKit_$_Braintree)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Fixed it by adding libSwiftWebKit.TBD. Reference: https://developer.apple.com/forums/thread/655438

Screenshot 2021-05-06 at 12 01 32 PM

@sestevens should I raise a PR for the React-native sample?. Also, could you please review the fix for Braintree-Swift.h and include it your release?

sestevens commented 3 years ago

@jbatra-umeey Could you post a link to the React Native sample app you're using?

jbatra-umeey commented 3 years ago

@sestevens I kept https://github.com/wgltony/react-native-braintree-dropin-ui as the base and customized based on my requirements. For now, maybe we could use this one for testing

Disclaimer: This project needs some migration-related changes. Might need to fix them but it should be good to start with.

Updated podspec : https://github.com/wgltony/react-native-braintree-dropin-ui/blob/master/ios/RNBraintreeDropIn.podspec

Pod::Spec.new do |s|
  s.name         = "RNBraintreeDropIn"
  s.version      = "1.0.0"
  s.summary      = "RNBraintreeDropIn"
  s.description  = <<-DESC
                  RNBraintreeDropIn
                   DESC
  s.homepage     = "https://github.com/bamlab/react-native-braintree-payments-drop-in"
  s.license      = "MIT"
  # s.license      = { :type => "MIT", :file => "../LICENSE" }
  s.author             = { "author" => "lagrange.louis@gmail.com" }
  s.platform     = :ios, "12.0"
  s.source       = { :git => "https://github.com/BradyShober/react-native-braintree-dropin-ui.git", :tag => "master" }
  s.source_files  = "*.{h,m}"
  s.requires_arc = true
  s.dependency    'React'
  s.dependency    'Braintree'
  s.dependency    'BraintreeDropIn'
  s.dependency    'Braintree/DataCollector'
  s.dependency    'Braintree/Apple-Pay'
  s.dependency    'Braintree/Venmo'
end

Example App : Braintree.zip

jbatra-umeey commented 3 years ago

@sestevens could you please share an update on the suggested changes?. Also, please let me know if you need any help in compiling the react native sample

sestevens commented 3 years ago

Hi @jbatra-umeey, we haven't had a chance to reproduce this yet, but we're planning to take a look at the sample app you linked to. I want to be careful about using #import "Braintree-Swift.h" because we've had issues with "-style imports before. But we'll try it out when we get a chance!

We don't have an exact timeline for when we'll have a chance to tackle this, but I'll keep you posted on any progress.

jbatra-umeey commented 3 years ago

@sestevens is there any sample to compile the code using source files?

sestevens commented 3 years ago

@jbatra-umeey Here's a demo app that's included in this repo. Also, we tried changing the import to #import "Braintree-Swift.h", but it's causing pod lib lint to fail with an error about not being able to find that file. We'll keep investigating and let you know if we come up with a solution.

jbatra-umeey commented 3 years ago

@sestevens would you recommend building the pod from the local file path of SPM? Or any tips on importing headers from SPM in the cocoa pods project?

For example, in my case, the dependency of my development pod is on :

s.dependency    'BraintreeDropIn'
  s.dependency    'Braintree/DataCollector'
  s.dependency    'Braintree/Apple-Pay'
  s.dependency    'Braintree/Venmo'

FYI, As of now, I am using the source files to generate the pods

My profile: pod 'Braintree', :path => '/Users/xxx/sources/braintree_ios-master'

scannillo commented 3 years ago

👋 Hello @jbatra-umeey - I am able to get #import "Braintree-Swift.h" working for a React-Native app. After that, I am also able to replicate the swiftWebKit type issues you were seeing.

Question - is the native iOS portion of your React-Native app written in pure Objective-C?

If so, I was able to resolve the swiftWebKit type issue by adding an empty Swift file into my application, and letting XCode properly generate and link a bridging header. (SO post for reference). This removed the need to manually include libSwiftWebKit & other similar frameworks.

Please let me know if that gets things working for you. You can test using our branch react-native (link).

jbatra-umeey commented 3 years ago

@scannillo thanks for the quick update. I will try it out react-native branch on my end and share the update Yes, the code is written in Objective-C I believe the changes you pointed out w.r.t swiftWebKitshould work as per SO post

scannillo commented 3 years ago

👋 Hello. We have released a fix for this in Braintree iOS v5.3.2.