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

Archive failure No such module 'PPRiskMagnes' #679

Closed ejensen closed 3 years ago

ejensen commented 3 years ago

Integration Details (please complete the following information):

Describe the bug Archiving fails when importing a subset of libraries within the Braintree Swift Package. The PayPalDataCollector library fails to compile: No such module 'PPRiskMagnes' This was not an issue in Braintree 5.3.0 and earlier.

To Reproduce Steps to reproduce the behavior (video attached below):

  1. Open the SPMTest app project
  2. Remove a reference of the optional Braintree libraries (ex. Union Pay, Venmo, etc)
  3. Set the archive build configuration to "Debug"
  4. Perform a clean archive

Expected behavior The archive completes successfully

Screenshots

Screen Shot 2021-05-18 at 9 06 04 AM Screen Shot 2021-05-18 at 9 52 33 AM

https://user-images.githubusercontent.com/915431/118695280-de3c5880-b7c1-11eb-89cc-67dae7d06862.mp4

JonathanDowning commented 3 years ago

Seconded, I'm unable to update our project to 5.3.1 due to No such module 'PPRiskMagnes', it's not immediately obvious from this diff why this is now the case.

scannillo commented 3 years ago

πŸ‘‹ Hello. Thank you for reporting this issue. I will be taking a look at this today.

scannillo commented 3 years ago

With a fresh clone of the repo & Xcode 12.5 (Swift 5.4), I am not immediately able to replicate this issue. However, after doing a clean, I can replicate.

Listed in the Swift 5.4 release notes are some package caching updates. Here are some suggestions to get you up and running which worked for me:

Let me know if those work!

mccarron commented 3 years ago

I'm also having the same exact problem with Xcode 12.5, can't do Archive builds at all. Tried the above steps and even rebooted a few times for good measure.

Builds are fine, but Archives fail. Very strange really.

scannillo commented 3 years ago

Hi @mccarron - thank you for sharing. Would you mind giving some more info:

With a fresh clone of the braintree_ios repo using the SPMTest app, I am able to successfully archive the demo app after completing @ejensen's replication steps (removing BraintreeUnionPay) using both archive via Xcode (Product > Archive) and via command line (via xcodebuild archive).

mccarron commented 3 years ago

Hi @mccarron - thank you for sharing. Would you mind giving some more info:

  • Can you post the error logs you are seeing (to help us confirm what is going on)?

I can post this but I can't share full debug logs here.

Screen Shot 2021-05-24 at 10 38 20 AM
  • Is this only a problem for you on Xcode 12.5 and Braintree iOS 5.3.1?

Correct this is Xcode 12.5 and Braintree iOS 5.3.1. It seems to archive just fine with Braintree iOS 5.3.0 on Xcode 12.5.

I don't have Xcode 12.4 installed right now so I can't easily test if it's an Xcode issue as well as we're doing this SPM migration due to Xcode 12.5 fixing SPM issues. I may on another machine so I can report back later today.

  • Can you share the command you are using to archive?

Product > Archive as you said and we also use fastlane to Archive also fails on our CI environment. It generates a long command that is not relevant here and can't share all of our debug logs as I said above.

  • Any other steps to replicate!

I'll try to reproduce on a clean project, it seems fairly reliable to do here with little work needed to reproduce for us.

We also use Braintree Drop In so think it may be related to the combo use maybe?

For now we'll stay on 5.3.0 since that seems to work just fine.

mccarron commented 3 years ago

Quick update it does in fact fail only on Xcode 12.5 but works fine on Xcode 12.4, both with Braintree iOS 5.3.1.

Switched between them in the same project state and triggered the failure only on Xcode 12.5.

CompileSwift normal arm64 /Users/mccarron/Library/Developer/Xcode/DerivedData/client-gzkndxhzcubkocfsukhbcquncyig/SourcePackages/checkouts/braintree_ios/Sources/PayPalDataCollector/Public/PayPalDataCollector/PPDataCollector.swift (in target 'PayPalDataCollector' from project 'Braintree') cd /Users/mccarron/Library/Developer/Xcode/DerivedData/client-gzkndxhzcubkocfsukhbcquncyig/SourcePackages/checkouts/braintree_ios /Applications/Xcode\ 12.5.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -emit-bc /Users/mccarron/Library/Developer/Xcode/DerivedData/client-gzkndxhzcubkocfsukhbcquncyig/SourcePackages/checkouts/braintree_ios/Sources/PayPalDataCollector/Public/PayPalDataCollector/PPDataCollector.swift -emit-module-path /Users/mccarron/Library/Developer/Xcode/DerivedData/client-gzkndxhzcubkocfsukhbcquncyig/Build/Intermediates.noindex/ArchiveIntermediates/clientLocal/IntermediateBuildFilesPath/Braintree.build/Local-iphoneos/PayPalDataCollector.build/Objects-normal/arm64/PayPalDataCollector.swiftmodule -emit-module-doc-path /Users/mccarron/Library/Developer/Xcode/DerivedData/client-gzkndxhzcubkocfsukhbcquncyig/Build/Intermediates.noindex/ArchiveIntermediates/clientLocal/IntermediateBuildFilesPath/Braintree.build/Local-iphoneos/PayPalDataCollector.build/Objects-normal/arm64/PayPalDataCollector.swiftdoc -emit-module-source-info-path /Users/mccarron/Library/Developer/Xcode/DerivedData/client-gzkndxhzcubkocfsukhbcquncyig/Build/Intermediates.noindex/ArchiveIntermediates/clientLocal/IntermediateBuildFilesPath/Braintree.build/Local-iphoneos/PayPalDataCollector.build/Objects-normal/arm64/PayPalDataCollector.swiftsourceinfo -serialize-diagnostics-path /Users/mccarron/Library/Developer/Xcode/DerivedData/client-gzkndxhzcubkocfsukhbcquncyig/Build/Intermediates.noindex/ArchiveIntermediates/clientLocal/IntermediateBuildFilesPath/Braintree.build/Local-iphoneos/PayPalDataCollector.build/Objects-normal/arm64/PayPalDataCollector-master.dia -emit-objc-header-path /Users/mccarron/Library/Developer/Xcode/DerivedData/client-gzkndxhzcubkocfsukhbcquncyig/Build/Intermediates.noindex/ArchiveIntermediates/clientLocal/IntermediateBuildFilesPath/Braintree.build/Local-iphoneos/PayPalDataCollector.build/Objects-normal/arm64/PayPalDataCollector-Swift.h -emit-dependencies-path /Users/mccarron/Library/Developer/Xcode/DerivedData/client-gzkndxhzcubkocfsukhbcquncyig/Build/Intermediates.noindex/ArchiveIntermediates/clientLocal/IntermediateBuildFilesPath/Braintree.build/Local-iphoneos/PayPalDataCollector.build/Objects-normal/arm64/PayPalDataCollector-master.d -target arm64-apple-ios12.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode\ 12.5.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.5.sdk -I /Users/mccarron/Library/Developer/Xcode/DerivedData/client-gzkndxhzcubkocfsukhbcquncyig/Build/Intermediates.noindex/ArchiveIntermediates/clientLocal/BuildProductsPath/Local-iphoneos -I /Applications/Xcode\ 12.5.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/lib -F /Users/mccarron/Library/Developer/Xcode/DerivedData/client-gzkndxhzcubkocfsukhbcquncyig/Build/Intermediates.noindex/ArchiveIntermediates/clientLocal/BuildProductsPath/Local-iphoneos -F /Users/mccarron/Library/Developer/Xcode/DerivedData/client-gzkndxhzcubkocfsukhbcquncyig/Build/Intermediates.noindex/ArchiveIntermediates/clientLocal/BuildProductsPath/Local-iphoneos/PackageFrameworks -F /Applications/Xcode\ 12.5.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Frameworks -F /Applications/Xcode\ 12.5.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.5.sdk/Developer/Library/Frameworks -g -module-cache-path /Users/mccarron/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity\=checked -O -D SWIFT_PACKAGE -D Xcode -serialize-debugging-options -Xcc -working-directory -Xcc /Users/mccarron/Library/Developer/Xcode/DerivedData/client-gzkndxhzcubkocfsukhbcquncyig/SourcePackages/checkouts/braintree_ios -Xcc -I/Users/mccarron/Library/Developer/Xcode/DerivedData/client-gzkndxhzcubkocfsukhbcquncyig/Build/Intermediates.noindex/ArchiveIntermediates/clientLocal/IntermediateBuildFilesPath/Braintree.build/Local-iphoneos/PayPalDataCollector.build/swift-overrides.hmap -Xcc -I/Users/mccarron/Library/Developer/Xcode/DerivedData/client-gzkndxhzcubkocfsukhbcquncyig/Build/Intermediates.noindex/ArchiveIntermediates/clientLocal/BuildProductsPath/Local-iphoneos/include -Xcc -I/Users/mccarron/Library/Developer/Xcode/DerivedData/client-gzkndxhzcubkocfsukhbcquncyig/Build/Intermediates.noindex/ArchiveIntermediates/clientLocal/IntermediateBuildFilesPath/Braintree.build/Local-iphoneos/PayPalDataCollector.build/DerivedSources-normal/arm64 -Xcc -I/Users/mccarron/Library/Developer/Xcode/DerivedData/client-gzkndxhzcubkocfsukhbcquncyig/Build/Intermediates.noindex/ArchiveIntermediates/clientLocal/IntermediateBuildFilesPath/Braintree.build/Local-iphoneos/PayPalDataCollector.build/DerivedSources/arm64 -Xcc -I/Users/mccarron/Library/Developer/Xcode/DerivedData/client-gzkndxhzcubkocfsukhbcquncyig/Build/Intermediates.noindex/ArchiveIntermediates/clientLocal/IntermediateBuildFilesPath/Braintree.build/Local-iphoneos/PayPalDataCollector.build/DerivedSources -Xcc -DSWIFT_PACKAGE -target-sdk-version 14.5 -parse-as-library -module-name PayPalDataCollector -num-threads 8 -o /Users/mccarron/Library/Developer/Xcode/DerivedData/client-gzkndxhzcubkocfsukhbcquncyig/Build/Intermediates.noindex/ArchiveIntermediates/clientLocal/IntermediateBuildFilesPath/Braintree.build/Local-iphoneos/PayPalDataCollector.build/Objects-normal/arm64/PPDataCollector.bc

/Users/mccarron/Library/Developer/Xcode/DerivedData/client-gzkndxhzcubkocfsukhbcquncyig/SourcePackages/checkouts/braintree_ios/Sources/PayPalDataCollector/Public/PayPalDataCollector/PPDataCollector.swift:1:8: error: no such module 'PPRiskMagnes' import PPRiskMagnes

scannillo commented 3 years ago

Thank you very much for providing that detail!

I created a new sample app via a blank Xcode project, included Braintree Drop In v9.0.1 (with Braintree 5.3.1) via SPM. I was able to replicate your archive issue via the XCode UI "Product > Archive".

However, I then ran xcodebuild -project 'TestApp.xcodeproj' -scheme 'TestApp' clean archive CODE_SIGNING_ALLOWED=NO and was able to successfully archive on the command line. Then, running archive in the Xcode UI also succeeded. Definitely weird, and we're still trying to figure out more details / what is going on. But wanted to update you! Feel free to give it a try.

rursache commented 3 years ago

i'm having the same issue on xcode 11.5 - No such module 'PPRiskMagnes' - even on running the app.

i only need the braintree + paypal integration and it seems that PPRiskMagnes lib is still creating issues (last time i tried this integration was in february).

sometimes after multiple builds the app runs but i get a runtime crash:

dyld: Library not loaded: @rpath/PPRiskMagnes.framework/PPRiskMagnes
  Referenced from: /private/var/containers/Bundle/Application/0C2D8DA4-D8DB-4086-8E32-65B42C27799B/<APPNAME>.app/<APPNAME>
  Reason: image not found
dyld: launch, loading dependent libraries
DYLD_LIBRARY_PATH=/usr/lib/system/introspection
DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib

what i tried:

ARCHIVE FAILED


Braintree is the only dependency that still keeps me from fully migrating from cocoapods to SPM. This is really annoying because all the other "big guys" already got SPM figured out (Stripe, Firebase, etc).
JetForMe commented 3 years ago

@sestevens mentioned in #576 that "cleaning and re-building" solves the issue. The thing is, at least for me, I never have an issue with Build, but only with Archive. AFAICT, Archive is always a clean-slate build.

simonpierreroy commented 3 years ago

This seems to be a bug in the Xcode build system for swiftPM integration! Try this https://github.com/simonpierreroy/xcframework-issue and always clean in between it should fail! It does the same with my own local package that has an XCframework! Here is my feedback FB9125479. I used this repo for my feedback to apple, since I was having the same issues with a close source package I can not share.

Screen Shot 2021-06-02 at 12 18 26 PM
JackoPlane commented 3 years ago

While we wait for an update to SPM, Is there an older version of the Braintree SDK that can be used with SPM that doesn't rely on PPRiskMagnes ?

scannillo commented 3 years ago

Hi everyone. We think this is likely an Xcode bug, but are still doing some testing internally. Like I said in my previous posts, we were only able to trigger the archive issues sometimes. Building & running the application, re-installing the package via SPM, and archiving on the command line all got things working for us.

@JackoPlane - people in this thread are saying that they don't see archive issues on 5.3.0, however @sestevens and I were seeing some similar issues in our CI near that version release. We can't say for sure that the issue is not present on 5.3.0, but you can give it a shot for now.

mccarron commented 3 years ago

@JackoPlane - people in this thread are saying that they don't see archive issues on 5.3.0, however @sestevens and I were seeing some similar issues in our CI near that version release. We can't say for sure that the issue is not present on 5.3.0, but you can give it a shot for now.

Agree with ^ I experienced it once with 5.3.0 locally but went away with a clean, but no issues on CI at all so far. knocks on wood

JetForMe commented 3 years ago

I do believe it's an Xcode bug, and only once did I succeed in archiving. Dozens of attempts later with all manner of cleaning, resetting, re-downloading, removing and re-adding, I haven't been able to Archive. I submitted our project to Apple, and it looks like another Apple engineer has taken on the Swift bug for it. I added @simonpierreroy's info to that.

We’re using 5.3.0.

JetForMe commented 3 years ago

One possibility might be if Braintree packaged up the entire suite as a single binary framework (since I presume there are parts of your code you don't want to share). We might be able to link against that. I think it's the transitive dependency that fails.

RamblinWreck77 commented 3 years ago

Just chiming to confirm I am seeing this same error in:

Apple Silicon Xcode 12.5 Braintree_ios 5.4.0

In debug OR release mode: -Clean -Build/Run attempt (always fails) -Build/Run attempt (sometimes fails) -Build/Run attempt (always works)

I was able to work around this issue/upload to the store by:

Set Release mode/any iOS device 1: clean 2: Build (always fails) 3: Build (might work, if it works go to 5) 4: Build again (should always work) 5: Archive (should spit out a binary now)

RamblinWreck77 commented 3 years ago

Also, this same problem totally breaks SwiftUI previews for the entire project which is super frustrating. Unfortunately I have not been able to find a workaround/retry pattern that gets SwiftUI previews to work.

Back to the dark ages of code -> compile -> test on device -> tweak code again πŸ˜‚

eseay commented 3 years ago

I ran into this issue with BT 5.3.0 and 5.4.0, but I have downgraded to 5.2.0, and that seems to be working for me.

JetForMe commented 3 years ago

Also, this same problem totally breaks SwiftUI previews for the entire project which is super frustrating. Unfortunately I have not been able to find a workaround/retry pattern that gets SwiftUI previews to work.

Back to the dark ages of code -> compile -> test on device -> tweak code again πŸ˜‚

Unrelated to braintree, almost certainly, but I've run into SwiftUI preview problems that say things like ".swift is not a member of any target." I found removing and re-adding that file to the project resets Xcode's notions.

scannillo commented 3 years ago

πŸ‘‹ Hello everyone. We pushed a potential "fix" to a branch called xcode-archive-test. With this change, we're no longer experiencing any archive issues with PPRiskMagnes via SPM. Feel free to give this branch a try and let us know if it resolves your issue.

rursache commented 3 years ago

πŸ‘‹ Hello everyone. We pushed a potential "fix" to a branch called xcode-archive-test. With this change, we're no longer experiencing any archive issues with PPRiskMagnes via SPM. Feel free to give this branch a try and let us know if it resolves your issue.

i'm still getting No such module 'PPRiskMagnes'. am i missing something? thanks!

scannillo commented 3 years ago

Hi @rursache - remove the dependency, clean, re-build etc?

rursache commented 3 years ago

Hi @rursache - remove the dependency, clean, re-build etc?

exactly in that order ☹️ builds fine but does not archive

EDIT: got it working by removing derived data folder (sudo rm -rf ~/Library/Developer/Xcode/DerivedData)

πŸŽ‰

JetForMe commented 3 years ago

I spent time in an Xcode lab during WWDC. They fully acknowledged the bug and will be working on it, although there's no indication as to when it will be fixed (hopefully they'll do an Xcode 12.5.1!).

In the meantime, they offered this workaround, which I have not had a chance to try yet. The failure is caused by a clean build failing to properly process XCFrameworks. This processing step involves copying them to the correct location in the built products directory. The proposed workaround is to manually copy the binary XCFrameworks to the appropriate location in the build products directory. This might work as a Run Script build phase in the main target, or you might need to create a separate Aggregate target and make that a dependency of the target you're trying to build.

The correct location can be found by doing one of the target builds that works and looking for where it copies PPRiskMagnes. Unfortunately I can't take the time right now to figure that out.

simonpierreroy commented 3 years ago

Same here :) my Feedback was acknowledge and I was told during a WWDC lab they are working on it. No timeline. (I hope a beta of Xcode 13). They confirm my hypothesis for the cause described here (at least told me it was a build system issue) https://github.com/braintree/braintree_ios/issues/679#issuecomment-853166124.

scannillo commented 3 years ago

Thank you @JetForMe & @simonpierreroy for communicating this issue to Apple dev's at WWDC πŸ‘ .

Is anyone hard blocked by this issue? If so, please let us know.

On our end - we are always able to circumvent this bug by cleaning, then re-building/ running the actual application, and then archiving succeeds. _Also, with the branch we posted above, we haven't yet been able to replicate the issue._

JetForMe commented 3 years ago

We're not blocked only because we're still using CocoaPods to integrate it, and we have a crucial deadline that's taking priority over the goal of getting rid of CocoaPods. In six weeks, we'll see.

mthole commented 3 years ago

I am regularly able to reproduce this issue on our CI machines, even with the xcode-archive-test branch. Note that I'm not even trying to archive, just do a normal Debug build, e.g.:

xcodebuild -workspace MyApp.xcworkspace -scheme MyApp -configuration Debug CODE_SIGNING_ALLOWED=NO COMPILER_INDEX_STORE_ENABLE=NO build | xcbeautify

It might be worth noting that my terrible workaround is simply to try this ^ xcodebuild build command twice on CI, in the event the first one fails. That consistently works around this issue, but isn't really viable long term.


Silly question: Should the Package.swift simply specify that the PayPalDataCollector target depends on PPRiskMagnes? That doesn't seem to be the case today.

scannillo commented 3 years ago

Silly question: Should the Package.swift simply specify that the PayPalDataCollector target depends on PPRiskMagnes? That doesn't seem to be the case today.

Great question! That is how it should be, but due to an Xcode/SPM bug when a library depends on a binary target, we had to expose PPRiskMagnes as its own library as a workaround. You can see that discussion here. The need for this workaround is apparently solved in Xcode 12.5, and we are currently working on / testing that update now.

I'm glad you have a workaround for CI. Today we will release a version of the SDK with a workaround that has calmed our CI from seeing this bug so frequently as well. Will keep you posted!

scannillo commented 3 years ago

πŸ‘‹ Hi everyone. We released Braintree v5.4.1 with a workaround that has consistently removed this issue from both our local testing and CI builds. We understand this issue is some combination of an Xcode bug with our SDK - but wanted to release this fix to help resolve this issue for you, if possible.

Thank you all for thorough feedback and help! Feel free to keep us posted by commenting, or opening a new issue if problems arise.

mccarron commented 3 years ago

An FYI we were still seeing this with 5.4.1 and 5.4.2 so we're rolling back to 5.3.0 which didn't have this issue for us.

Not sure if happening for others as well?

mthole commented 3 years ago

I am still hitting this issue after upgrading to 5.4.2 and removing the explicit dependencies on PPRiskMagnes, etc.

image

cc: @scannillo @mccarron FYI

rursache commented 3 years ago

@mthole: I am still hitting this issue after upgrading to 5.4.2 and removing the explicit dependencies on PPRiskMagnes, etc.

you need PPRiskMagnes tho

mthole commented 3 years ago

@mthole: I am still hitting this issue after upgrading to 5.4.2 and removing the explicit dependencies on PPRiskMagnes, etc.

you need PPRiskMagnes tho

The release notes say:

You can remove the KountDataCollector, PPRiskMagnes, and CardinalMobile explicit dependencies.

I read that to mean I should remove the explicit deps I have on PPRiskMagnes, and that SPM now transitively links them now as needed? For context, I am adding BraintreePayPal as the dependency to my project.

rursache commented 3 years ago

the installation guide is very clear around what you need to include when targeting parts of the sdk. your issue is not related to this thread / #679.

mthole commented 3 years ago

@rursache Doesn't look like that installation guide has been updated for 5.4.2, which contains the changes I'm referencing.

mthole commented 3 years ago

Got my set up working! For anyone else: After updating to 5.4.2, I removed my PPRiskMagnes direct dependency (correctly), but I also removed the PayPalDataCollector dependency, which is still needed.

scannillo commented 3 years ago

@rursache is correct - for v5.4.2+, you no longer need to explicitly include PPRiskMagnes, KountDataCollector, or CardinalMobile. As of now, you do still need to include PayPalDataCollector for PayPal, 3DS, and Local Payments/

JetForMe commented 3 years ago

We're able to build with Card, Core, ApplePay, and PayPal, and haven't needed PayPalDataCollector in order to build and archive. But we are seeing very bizarre behavior with the iOS drop-in UI not displaying the vault (stored methods), except for one build we did earlier today, and we can't figure out why.

simonpierreroy commented 3 years ago

@scannillo could you explain the change you did in the framework and your finding to make it work (why Xcode 12.5 for example) :) it would be useful for one of my project. Thank you so much.

scannillo commented 3 years ago

Hi @simonpierreroy - sure, happy to share. Check out this PR, in which the description outlines the situation and solution more thoroughly.