braze-inc / braze-swift-sdk

Braze SDK for the Apple ecosystem, including: iOS, macOS, iPadOS, visionOS, tvOS
https://www.braze.com
Other
52 stars 19 forks source link

[Bug]: Build fails with `duplicate symbols` warning when `use_frameworks!` is written in the Podfile #35

Closed dazy1030 closed 1 year ago

dazy1030 commented 1 year ago

Platform

iOS

Platform Version

iOS14 or higher

Braze SDK Version

5.8.1

Xcode Version

Xcode14.1

Computer Processor

Intel

Repro Rate

100%

Steps To Reproduce

  1. Create a plain iOS project. Name the application AppPlayground.
  2. Create a Notification Service Extension target named NotificationService.
  3. Rebuild it into a CocoaPods project with the pod init command.
  4. Describe the Podfile as follows and execute the pod install command.

    platform :ios, '14.0'
    
    use_frameworks!
    
    target 'AppPlayground' do
      pod 'BrazeKit'
    end
    
    target 'NotificationService' do
      pod 'BrazeNotificationService'
    end
  5. Build the AppPlayground target.

Expected Behavior

Build succeeds.

Actual Incorrect Behavior

"130 duplicate symbols for architecture arm64" warning and build fails.

Verbose Logs

Ld /Users/hoge/Library/Developer/Xcode/DerivedData/AppPlayground-avojqrsyaguretehxikmkuemuafx/Build/Products/Debug-iphonesimulator/AppPlayground.app/AppPlayground normal (in target 'AppPlayground' from project 'AppPlayground')
    cd /Users/hoge/repositories/AppPlayground
    /Applications/Xcode14_1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -target arm64-apple-ios15.5-simulator -isysroot /Applications/Xcode14_1.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator16.1.sdk -L/Users/hoge/Library/Developer/Xcode/DerivedData/AppPlayground-avojqrsyaguretehxikmkuemuafx/Build/Intermediates.noindex/EagerLinkingTBDs -L/Users/hoge/Library/Developer/Xcode/DerivedData/AppPlayground-avojqrsyaguretehxikmkuemuafx/Build/Products/Debug-iphonesimulator -L/Applications/Xcode14_1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator -L/Applications/Xcode14_1.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator16.1.sdk/usr/lib/swift -F/Users/hoge/Library/Developer/Xcode/DerivedData/AppPlayground-avojqrsyaguretehxikmkuemuafx/Build/Intermediates.noindex/EagerLinkingTBDs -F/Users/hoge/Library/Developer/Xcode/DerivedData/AppPlayground-avojqrsyaguretehxikmkuemuafx/Build/Products/Debug-iphonesimulator -F/Users/hoge/repositories/AppPlayground/Pods/BrazeKit -F/Users/hoge/repositories/AppPlayground/Pods/BrazeNotificationService -F/Users/hoge/Library/Developer/Xcode/DerivedData/AppPlayground-avojqrsyaguretehxikmkuemuafx/Build/Products/Debug-iphonesimulator/XCFrameworkIntermediates/BrazeKit -F/Users/hoge/Library/Developer/Xcode/DerivedData/AppPlayground-avojqrsyaguretehxikmkuemuafx/Build/Products/Debug-iphonesimulator/XCFrameworkIntermediates/BrazeNotificationService -filelist /Users/hoge/Library/Developer/Xcode/DerivedData/AppPlayground-avojqrsyaguretehxikmkuemuafx/Build/Intermediates.noindex/AppPlayground.build/Debug-iphonesimulator/AppPlayground.build/Objects-normal/arm64/AppPlayground.LinkFileList -Xlinker -rpath -Xlinker /usr/lib/swift -Xlinker -rpath -Xlinker @executable_path/Frameworks -Xlinker -rpath -Xlinker @loader_path/Frameworks -Xlinker -rpath -Xlinker @executable_path/Frameworks -dead_strip -Xlinker -object_path_lto -Xlinker /Users/hoge/Library/Developer/Xcode/DerivedData/AppPlayground-avojqrsyaguretehxikmkuemuafx/Build/Intermediates.noindex/AppPlayground.build/Debug-iphonesimulator/AppPlayground.build/Objects-normal/arm64/AppPlayground_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -Xlinker -objc_abi_version -Xlinker 2 -fobjc-link-runtime -L/Applications/Xcode14_1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator -L/usr/lib/swift -Xlinker -add_ast_path -Xlinker /Users/hoge/Library/Developer/Xcode/DerivedData/AppPlayground-avojqrsyaguretehxikmkuemuafx/Build/Intermediates.noindex/AppPlayground.build/Debug-iphonesimulator/AppPlayground.build/Objects-normal/arm64/AppPlayground.swiftmodule -ObjC -framework BrazeKit -framework BrazeNotificationService -Xlinker -sectcreate -Xlinker __TEXT -Xlinker __entitlements -Xlinker /Users/hoge/Library/Developer/Xcode/DerivedData/AppPlayground-avojqrsyaguretehxikmkuemuafx/Build/Intermediates.noindex/AppPlayground.build/Debug-iphonesimulator/AppPlayground.build/AppPlayground.app-Simulated.xcent -Xlinker -sectcreate -Xlinker __TEXT -Xlinker __ents_der -Xlinker /Users/hoge/Library/Developer/Xcode/DerivedData/AppPlayground-avojqrsyaguretehxikmkuemuafx/Build/Intermediates.noindex/AppPlayground.build/Debug-iphonesimulator/AppPlayground.build/AppPlayground.app-Simulated.xcent.der -framework Pods_AppPlayground -Xlinker -no_adhoc_codesign -Xlinker -dependency_info -Xlinker /Users/hoge/Library/Developer/Xcode/DerivedData/AppPlayground-avojqrsyaguretehxikmkuemuafx/Build/Intermediates.noindex/AppPlayground.build/Debug-iphonesimulator/AppPlayground.build/Objects-normal/arm64/AppPlayground_dependency_info.dat -o /Users/hoge/Library/Developer/Xcode/DerivedData/AppPlayground-avojqrsyaguretehxikmkuemuafx/Build/Products/Debug-iphonesimulator/AppPlayground.app/AppPlayground

duplicate symbol '_$s11_BrazeUtils10StringPathV4pathSSvM' in:
    /Users/hoge/Library/Developer/Xcode/DerivedData/AppPlayground-avojqrsyaguretehxikmkuemuafx/Build/Products/Debug-iphonesimulator/XCFrameworkIntermediates/BrazeKit/BrazeKit.framework/BrazeKit(BrazeKit-arm64-master.o)
    /Users/hoge/Library/Developer/Xcode/DerivedData/AppPlayground-avojqrsyaguretehxikmkuemuafx/Build/Products/Debug-iphonesimulator/XCFrameworkIntermediates/BrazeNotificationService/BrazeNotificationService.framework/BrazeNotificationService(BrazeNotificationService-arm64-master.o)
[...]
duplicate symbol '_$sSo12NSURLSessionC18_BrazeAssetsClientE8uncached13configurationABXDSo0A13ConfigurationC_tFZ' in:
    /Users/hoge/Library/Developer/Xcode/DerivedData/AppPlayground-avojqrsyaguretehxikmkuemuafx/Build/Products/Debug-iphonesimulator/XCFrameworkIntermediates/BrazeKit/BrazeKit.framework/BrazeKit(BrazeKit-arm64-master.o)
    /Users/hoge/Library/Developer/Xcode/DerivedData/AppPlayground-avojqrsyaguretehxikmkuemuafx/Build/Products/Debug-iphonesimulator/XCFrameworkIntermediates/BrazeNotificationService/BrazeNotificationService.framework/BrazeNotificationService(BrazeNotificationService-arm64-master.o)
ld: 130 duplicate symbols for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Additional Information

If "use_frameworks!" is not added, the build will succeed.

hokstuff commented 1 year ago

Hi @dazy1030,

As you observed above, our SDK is not meant to be imported withe the use_frameworks! since we distribute our SDK as prebuilt binaries. It looks like you are getting some duplicate symbols since BrazeKit and BrazeNotificationService aren't meant to be compiled into the same target, even though you explicitly have separate targets.

Based on the Cocoapods docs here, can you try to add the use_frameworks! annotation inside your target that imports the BrazeKit package, but not add that annotation for your NotificationService target? Let us know if that addresses your issue - it would look like:


target 'AppPlayground' do
  use_frameworks!
  pod 'BrazeKit'
end

target 'NotificationService' do
  pod 'BrazeNotificationService'
end
dazy1030 commented 1 year ago

Hi @hokstuff, thanks for the quick response.

I have tried and tested the information you provided and the build was successful with the following Podfile. Thank you very much for your help.

# Podfile
platform :ios, '14.0'

target 'AppPlayground' do
  use_frameworks!
  pod 'BrazeKit'
end

target 'NotificationService' do
  use_frameworks! :linkage => :static
  pod 'BrazeNotificationService'
end
hokstuff commented 1 year ago

Great - and thanks for sharing your code as well!