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

Swiftui previews not working with braintree pod in custom framework. #1020

Closed HimanDhawan closed 1 year ago

HimanDhawan commented 1 year ago

Braintree SDK Version

5.21.0

Environment

Sandbox

Xcode Version

Xcode 14.3

OS Version & Device

iPhone 14- iOS 16.2

Integration type

CocoaPods

Development Processor

Apple Silicon (M-series chips)

Describe the bug

I am using macOS venture 13.3.1 and xcode 14.3. I am unable to see previews of Swiftui Views in Custom framework.

Error : `== DATE:

Wednesday, 26 April 2023 at 1:30:15 PM India Standard Time

2023-04-26T08:00:15Z

== PREVIEW UPDATE ERROR:

PotentialCrashError: Update failed

XCPreviewAgent may have crashed. Check ~/Library/Logs/DiagnosticReports for any crash logs from your application.

==================================

|  RemoteHumanReadableError
|  
|  LoadingError: failed to load library at path "/Users/parasdhawan/Library/Developer/Xcode/DerivedData/MyFramework-emvrcwqtpwmcsnboottoocztjpxm/Build/Intermediates.noindex/Previews/MyFramework/Products/Debug-iphonesimulator/MyFramework.framework/MyFramework": Optional(dlopen(/Users/parasdhawan/Library/Developer/Xcode/DerivedData/MyFramework-emvrcwqtpwmcsnboottoocztjpxm/Build/Intermediates.noindex/Previews/MyFramework/Products/Debug-iphonesimulator/MyFramework.framework/MyFramework, 0x0000): Library not loaded: @rpath/Braintree.framework/Braintree
|    Referenced from: <1813D29C-ACDA-3C6A-A280-B5FD064D8DCA> /Users/parasdhawan/Library/Developer/Xcode/DerivedData/MyFramework-emvrcwqtpwmcsnboottoocztjpxm/Build/Intermediates.noindex/Previews/MyFramework/Products/Debug-iphonesimulator/MyFramework.framework/MyFramework
|    Reason: tried: '/Users/parasdhawan/Library/Developer/Xcode/DerivedData/MyFramework-emvrcwqtpwmcsnboottoocztjpxm/Build/Intermediates.noindex/Previews/MyFramework/Products/Debug-iphonesimulator/Braintree.framework/Braintree' (no such file), '/Users/parasdhawan/Library/Developer/Xcode/UserData/Previews/Simulator Devices/3072C050-AAFA-41DB-92DC-6ABD0A1DDE11/data/Containers/Bundle/Application/14329EF8-FAF5-43BF-84A6-FA03C3408C36/XCPreviewAgent.app/Frameworks/Braintree.framework/Braintree' (no such file), '/Users/parasdhawan/Library/Developer/Xcode/DerivedData/MyFramework-emvrcwqtpwmcsnboottoocztjpxm/Build/Intermediates.noindex/Previews/MyFramework/Products/Debug-iphonesimulator/MyFramework.framework/Frameworks/Braintree.framework/Braintree' (no such file), '/Users/parasdhawan/Library/Developer/Xcode/UserData/Previews/Simulator Devices/3072C050-AAFA-41DB-92DC-6ABD0A1DDE11/data/Containers/Bundle/Application/14329EF8-FAF5-43BF-84A6-FA03C3408C36/XCPreviewAgent.app/Frameworks/Braintree.framework/Braintree' (no such file), '/Users/parasdhawan/Library/Developer/Xcode/DerivedData/MyFramework-emvrcwqtpwmcsnboottoocztjpxm/Build/Intermediates.noindex/Previews/MyFramework/Products/Debug-iphonesimulator/MyFramework.framework/Frameworks/Braintree.framework/Braintree' (no such file), '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/swift/Braintree.framework/Braintree' (no such file), '/usr/lib/swift/Braintree.framework/Braintree' (no such file, not in dyld cache), '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/Braintree.framework/Braintree' (no such file))

== VERSION INFO:

Tools: 14E222b
OS:    22E261
PID:   3265
Model: MacBook Air
Arch:  arm64e

== ENVIRONMENT:

openFiles = [
    /Users/parasdhawan/Documents/Learning/MyFramework/MyFramework/MySwiftUIView.swift
]
wantsNewBuildSystem = true
newBuildSystemAvailable = true
activeScheme = MyFramework
activeRunDestination = iPhone 14 variant iphonesimulator arm64
workspaceArena = [x]
buildArena = [x]
buildableEntries = [
    MyFramework.framework
]

== SELECTED RUN DESTINATION:

name = iPhone 14
eligible = true
sdk = Optional(<DVTSDK:0x11e815e70:'iphonesimulator16.4':Simulator - iOS 16.4:<DVTFilePath:0x600000d76680:'/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator16.4.sdk'>>)
variant = Optional("iphonesimulator")
device = Optional(<DVTiPhoneSimulator: 0x12eb32b60> {
        SimDevice: iPhone 14 (B475510E-8A89-4FEC-A78A-DEC866E54754, iOS 16.4, Shutdown)
})

== SELECTED RUN DESTINATION:

Simulator - iOS 16.4 | iphonesimulator | arm64 | iPhone 14 | no proxy

Destination Preferences {
    platform: iphonesimulator
    platformSpecifier: iphonesimulator
    deviceName: iPhone 14
    deviceSpecifier: com.apple.CoreSimulator.SimDeviceType.iPhone-14
    deviceModel: iPhone 14
    deviceIdentifier: B475510E-8A89-4FEC-A78A-DEC866E54754
    deviceFamily: (Device Family: iPhone)
    sdkVariant: iphonesimulator
    architecture: arm64
    sdkSpecifier: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator16.4.sdk
    sdkVersion: 16.4
    runtimeVersion: 16.4
}

Proxy:
Destination Preferences {
}

== SESSION GROUP 3917:

workspace identifier: WorkspaceIdentifier(identifier: 6821A28B-5772-400B-9649-8A427055870F)
providers: [
    MySwiftUIView_Previews /Users/parasdhawan/Documents/Learning/MyFramework/MyFramework/MySwiftUIView.swift
]
translation units: [
    /Users/parasdhawan/Documents/Learning/MyFramework/MyFramework/MySwiftUIView.swift
]
attributes: EditorSettingsCollection(storage: [PreviewsPipeline.EditorIdentifier(id: 3892): PreviewsPipeline.EditorSettings(defaultPreviewSettings: PreviewsPipeline.PreviewSettings(storage: [ObjectIdentifier(0x00000002af872dd8): PreviewsPipeline.PreviewSettings.(unknown context at $2af82faf4).ValueBox(value: true, isEqual: (Function), isDefaultValue: false), ObjectIdentifier(0x00000002af872e08): PreviewsPipeline.PreviewSettings.(unknown context at $2af82faf4).ValueBox(value: false, isEqual: (Function), isDefaultValue: false)]), appPreviewDestinationRequirements: PreviewsPipeline.DestinationRequirements(rule: PreviewsPipeline.DestinationRequirements.(unknown context at $2af822a54).Rule.none), isAppPreviewEnabled: false, _isLightboxEnabled: PreviewsFoundation.UserDefault<Swift.Bool>(key: "UVCanvasEnablePreviewShowAll", cachedValue: false, encoder: Foundation.JSONEncoder), suppressAppPreviewWhenPreviewProvidersArePresent: false, storage: [:])])
session: 3918
request sessions: [
    My SwiftUI View | MySwiftUIView_Previews: not completed
]

== UPDATE SESSION 3918:

Start Date: Wednesday, 26 April 2023 at 1:23:18 PM India Standard Time
Preview Provider {
    Simulator {
        platform: iphonesimulator
        device: 3072C050-AAFA-41DB-92DC-6ABD0A1DDE11 iPhone 14
        buildNumber: 20E247
        runtimePath: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime
    }
    pid: 4193
    host bundle: 
    com.apple.dt.PreviewAgent.iOS {
        url: file:///Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Xcode/Agents/XCPreviewAgent.app
        version: 20.30.47
        attributes: [
            AppExtensionIdentifierPreviewAttributeKey: nil,
            LaunchConfigEnvironmentVariablesPreviewAttributesKey: ["DYLD_INSERT_LIBRARIES": "/System/Library/PrivateFrameworks/LiveExecutionResultsProbe.framework/LiveExecutionResultsProbe", "DYLD_FRAMEWORK_PATH": "/Users/parasdhawan/Library/Developer/Xcode/DerivedData/MyFramework-emvrcwqtpwmcsnboottoocztjpxm/Build/Intermediates.noindex/Previews/MyFramework/Products/Debug-iphonesimulator", "__XCODE_BUILT_PRODUCTS_DIR_PATHS": "/Users/parasdhawan/Library/Developer/Xcode/DerivedData/MyFramework-emvrcwqtpwmcsnboottoocztjpxm/Build/Intermediates.noindex/Previews/MyFramework/Products/Debug-iphonesimulator", "__XPC_DYLD_LIBRARY_PATH": "/Users/parasdhawan/Library/Developer/Xcode/DerivedData/MyFramework-emvrcwqtpwmcsnboottoocztjpxm/Build/Intermediates.noindex/Previews/MyFramework/Products/Debug-iphonesimulator", "DYLD_LIBRARY_PATH": "/Users/parasdhawan/Library/Developer/Xcode/DerivedData/MyFramework-emvrcwqtpwmcsnboottoocztjpxm/Build/Intermediates.noindex/Previews/MyFramework/Products/Debug-iphonesimulator", "PACKAGE_RESOURCE_BUNDLE_URL": "/Users/parasdhawan/Library/Developer/Xcode/DerivedData/MyFramework-emvrcwqtpwmcsnboottoocztjpxm/Build/Intermediates.noindex/Previews/MyFramework/Products/Debug-iphonesimulator", "OS_ACTIVITY_DT_MODE": "YES", "__XPC_DYLD_FRAMEWORK_PATH": "/Users/parasdhawan/Library/Developer/Xcode/DerivedData/MyFramework-emvrcwqtpwmcsnboottoocztjpxm/Build/Intermediates.noindex/Previews/MyFramework/Products/Debug-iphonesimulator", "SQLITE_ENABLE_THREAD_ASSERTIONS": "1"],
        ]
    }
}
Build Graph {
    target framework MyFramework.framework (#1)
       Preview Provider My SwiftUI View My SwiftUI View (#2)
       translationUnit MySwiftUIView.swift (#3)
}
Update Plan {
    iOS [arm64 iphonesimulator16.4 iphonesimulator] (iPhone 14, B475510E-8A89-4FEC-A78A-DEC866E54754-iphonesimulator16.4-arm64-iphonesimulator), [], thinning disabled) {
        Destination: iPhone 14 B475510E-8A89-4FEC-A78A-DEC866E54754 | default device for iphonesimulator [
            Framework Agent - Previews {
                execution points [
                    provider MyFramework.MySwiftUIView_Previews
                ]
                translation units [
                    MySwiftUIView.swift (in MyFramework.framework)
                ]
                loadable products [
                    Description(buildableName: "MyFramework.framework", moduleName: "MyFramework")
                ]
                modules [
                    MyFramework.framework
                ]
            }
        ]
    }
}

== POWER STATE LOGS:

26/4/2023, 1:23 PM Received power source state: Battery Powered (lowPowerMode: true, status: unplugged, level: 100%)
26/4/2023, 1:23 PM Broadcasting device power state: Low Power
26/4/2023, 1:23 PM No device power state user override user default value.Current power state: Low Power`

To reproduce

  1. Create fresh Xcode Framework.
  2. Pod init in xcode framework repository.
  3. Add these two pods : pod 'Braintree', pod 'Braintree/Venmo'
  4. Open workspace.
  5. Add swiftui view.
  6. Swiftui preview for that view gives error Screenshot 2023-04-26 at 1 28 07 PM

Expected behavior

Swiftui preview should work.

Screenshots

Screenshot 2023-04-26 at 1 30 03 PM
HimanDhawan commented 1 year ago

My pod file :

# Uncomment the next line to define a global platform for your project
 platform :ios, '15.0'

target 'MyFramework' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for MyFramework
pod 'Braintree'
pod 'Braintree/Venmo'
  target 'MyFrameworkTests' do
    # Pods for testing
  end

end
KunJeongPark commented 1 year ago

I was able to replicate this issue. I am investigating this. I've created a ticket for this issue. (ticket for internal tracking: DTBTSDK-2674) Thank you.

KunJeongPark commented 1 year ago

I think this might be a Cocoapods issue. I was able to run preview using Swift Package Manager. I am investigating possible workarounds. I am looking into this article. https://michaziobro-21492.medium.com/using-swiftui-previews-in-cocoapods-framework-libraries-374f702b784f

HimanDhawan commented 1 year ago

@KunJeongPark I was able to run previews using swift package manager too. We are using other pods that doesn't support swift package manager. Thus, we cannot move to swift package manager.

KunJeongPark commented 1 year ago

I am finding the same issue with other pods in general such as SwiftJSON. So I think this is a Cocoapods issue. I think you may be able to get a better answer from the Cocoapods folks. Here is their issues page in Github. https://github.com/CocoaPods/CocoaPods/issues