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

Using Apple Pay Pod in a separate child target #1038

Closed nrajput05 closed 1 year ago

nrajput05 commented 1 year ago

Braintree SDK Version

5.21.0

Environment

Both

Xcode Version

14.2

OS Version & Device

All

Integration type

CocoaPods

Development Processor

Apple Silicon (M-series chips)

Describe the bug

I have a project where there could be two targets. One target supports ApplePay and one does not. Since apple refuses to accepts builds which have the Apple Pay Code in them but they do not use it I can not keep these 2 pods in one target and just get an appstore submission by explaining to the review team that this client of mine does not use Apple Pay and I have hidden it for this app.

In order to achieve this I tried sharing the common pods among two targets and one of them has an additional entry for Apple Pay pod. Here is how the podfile looks like:


platform :ios, '13.0'

use_frameworks!

def common_pods
  pod 'Flurry-iOS-SDK/FlurrySDK'
  pod 'Braintree'
  pod 'Braintree/Venmo'
  pod 'JTAppleCalendar'
  pod 'MaterialComponents/TextControls+FilledTextFields'
end

target 'testWithAP' do
  common_pods
  pod 'Braintree/ApplePay'
end

target 'testNonAP' do
  common_pods
end

post_install do |installer|
      installer.pods_project.build_configurations.each do |config|
        config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
      end
end

While the testNonAP target builds and runs successfully, the testWithAP gives this error:

Multiple commands produce '/Users/xxxx/Library/Developer/Xcode/DerivedData/testWithAP-dswkraujlkgxwmdvcldydpsuplzu/Build/Products/Debug-iphonesimulator/XCFrameworkIntermediates/Braintree/PayPalDataCollector/PPRiskMagnes.framework' note: That command depends on command in Target 'Braintree.common' (project 'Pods'): script phase “[CP] Copy XCFrameworks” note: That command depends on command in Target 'Braintree.common-ApplePay' (project 'Pods'): script phase “[CP] Copy XCFrameworks”

To reproduce

Just use the above pod file and try in a sample project where you would have two targets.

Expected behavior

Both targets should compile successfully.

Screenshots

No response

scannillo commented 1 year ago

👋 Hi @nrajput05 - thank you for raising this issue to us! It helps us a ton.

I am able to replicate using the Podfile structure you provided.

Can you tell me which of the payment methods from Braintree you are using in your app? Let me know if this is accurate:

nrajput05 commented 1 year ago

Yes, Apple Pay is the optional one.

scannillo commented 1 year ago

Thanks for confirming!

So if you structure your project like this (avoiding duplication of all Braintree pods b/w both target and just having an ApplePay-only target) things work with CocoaPods.

def common_pods
  pod 'Braintree'
  pod 'Braintree/Venmo'
end

target 'testWithAP' do
  pod 'Braintree/ApplePay'
end

target 'testNonAP' do
  common_pods
end

I also tested this out with other binaries (beyond just PPRiskMagnes that you see in the error console), and the same issue result. This looks like a limitation of CocoaPods to me.


To confirm this is a CocoaPods specific issue, I tried the setup that you desire, but via Swift Package Manager.

I have 1 target (TestAP) with all Braintree pods that you need + BraintreeApplePay: Screenshot 2023-05-12 at 12 35 43 PM

I have another target (TestBT_NonAP) with all the Braintree pods that you need excluding BraintreeApplePay: Screenshot 2023-05-12 at 12 35 49 PM

I am able to build everything just fine (the host app & each individual targets).

I provided that sample Swift Package Manager app here --> DupMagnesSPM.zip for you to reference.

I saw that you opened a CocoaPods issue here. Their response is odd to me, especially since the PPRiskMagnes framework is dynamic, not static.

scannillo commented 1 year ago

Side note in case it wasn't obvious, pod Braintree is an alias for Braintree/Core, Braintree/Card and Braintree/PayPal (see our Podspec). That alias isn't possible in SPM, which is why my example includes each individual framework you need.

nrajput05 commented 1 year ago

hmm switching to SPM isn't an option for me right now. I see the CocoaPod issues is reopened. I guess need to wait for them to come back.