AgoraIO / AgoraAudio_iOS

Agora's Audio SDK Swift Package for iOS 📦
MIT License
11 stars 5 forks source link

Unable to use SwiftUI Previews with newest version of the SDK #4

Open ethan021021 opened 2 years ago

ethan021021 commented 2 years ago

When I add the AgoraAudio_iOS SDK to my project I can no longer use SwiftUI Previews.

I'm using the latest version of the SDK which is 3.7.0

Here's the error the Preview Canvas is generating:

MessageSendFailure: Message send failure for update

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

|  RemoteHumanReadableError
|  
|  LoadingError: failed to load library at path "/Users/ethanthomas/Library/Developer/Xcode/DerivedData/Serenity-ammhovqgzfuogudxbhivmwhannha/Build/Intermediates.noindex/Previews/Serenity/Products/Debug-iphonesimulator/PackageFrameworks/HAHomeKit_-2D5A25D708B461BD_PackageProduct.framework/HAHomeKit_-2D5A25D708B461BD_PackageProduct": Optional(dlopen(/Users/ethanthomas/Library/Developer/Xcode/DerivedData/Serenity-ammhovqgzfuogudxbhivmwhannha/Build/Intermediates.noindex/Previews/Serenity/Products/Debug-iphonesimulator/PackageFrameworks/HAHomeKit_-2D5A25D708B461BD_PackageProduct.framework/HAHomeKit_-2D5A25D708B461BD_PackageProduct, 0x0000): Library not loaded: @rpath/AgoraCore.framework/AgoraCore
|    Referenced from: /Users/ethanthomas/Library/Developer/Xcode/DerivedData/Serenity-ammhovqgzfuogudxbhivmwhannha/Build/Intermediates.noindex/Previews/Serenity/Products/Debug-iphonesimulator/PackageFrameworks/HAHomeKit_-2D5A25D708B461BD_PackageProduct.framework/HAHomeKit_-2D5A25D708B461BD_PackageProduct
|    Reason: tried: '/Users/ethanthomas/Library/Developer/Xcode/DerivedData/Serenity-ammhovqgzfuogudxbhivmwhannha/Build/Intermediates.noindex/Previews/Serenity/Products/Debug-iphonesimulator/AgoraCore.framework/AgoraCore' (code signature in <1983A79A-6E2B-350B-9C53-C98A2E65A36C> '/Users/ethanthomas/Library/Developer/Xcode/DerivedData/Serenity-ammhovqgzfuogudxbhivmwhannha/Build/Intermediates.noindex/Previews/Serenity/Products/Debug-iphonesimulator/AgoraCore.framework/AgoraCore' not valid for use in process: Trying to load an unsigned library), '/Applications/Xcode 13.3.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/swift/AgoraCore.framework/AgoraCore' (no such file), '/usr/lib/swift/AgoraCore.framework/AgoraCore' (no such file), '/Applications/Xcode 13.3.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/swift/AgoraCore.framework/AgoraCore' (no such file), '/usr/lib/swift/AgoraCore.framework/AgoraCore' (no such file), '/Applications/Xcode 13.3.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/AgoraCore.framework/AgoraCore' (no such file))

This is blocking development currently so i'd be happy to provide any other logs if needed to get this resolved quickly :)

plutoless commented 2 years ago

why would you need preview for audio scenario?

ethan021021 commented 2 years ago

why would you need preview for audio scenario?

Including the SDK in your app and running a SwiftUI Preview will need to load the framework.

plutoless commented 2 years ago

i see. i will try to see if i can reproduce it today.

ethan021021 commented 2 years ago

i see. i will try to see if i can reproduce it today.

Thank you!

maxxfrazer commented 2 years ago

Hey @ethan021021, wanted to check if this is working fine on a physical device? If it's not working there: In Xcode head to your target, build phases, and make sure all the relevant libraries are included under "Link Binary With Libraries".

ethan021021 commented 2 years ago

@maxxfrazer Looks like it's included there. Issue seems to be that the AgoraSDK is bundled with one of my frameworks that I use.

The two frameworks that I use in the application are called HAServiceKit and HAHomeKit. AgoraSDK is bundled with HAServiceKit and HAHomeKit depends on HAServiceKit. Could this be the issue? I'd like to include the AgoraSDK bundled in with HAServiceKit instead of linking the AgoraSDK manually into my app binary

Thanks!

ethan021021 commented 2 years ago

I should also mention for package management on all of these frameworks i'm using Swift Package Manager

maxxfrazer commented 2 years ago

These libraries are private I guess? Have a check in this package that includes the regular rtc package, but since 3.7.0 we've needed to specify the specific product from Agora

https://github.com/AgoraIO-Community/iOS-UIKit/blob/main/Package.swift

line 29 in that file, look for "RtcBasic". You'll need to make sure at least that product is added to HAServiceKit in the same way.

ethan021021 commented 2 years ago

@maxxfrazer

Sorry I forgot to include one other dependency I was using this is what the tree looks like from top down:

HAKit
  HAHomeKit
    HAServiceKit
      AgoraSDK

I'm including AgoraSDK into HAServiceKit like this:

.target(name: "HAServiceKit", dependencies: [.product(name: "RtcBasic", package: "AgoraAudio_iOS")])

Is my Syntax correct? It runs just fine on Simulator / Device but when trying to run a SwiftUI Preview I get that error I originally posted here.

Thanks!

ethan021021 commented 2 years ago

I gave linking the xcframeworks manually a shot:

.library(name: "HAServiceKit", targets: ["HAServiceKit", "AgoraCore", "Agorafdkaac", "AgoraRtcKit", "AgoraSoundTouch"]),
.binaryTarget(
                    name: "AgoraCore",
                    url: "https://download.agora.io/swiftpm_2/AgoraAudio_iOS/3.7.0/AgoraCore.xcframework.zip",
                    checksum: "aecdc190a7c0e3ee9dce269379499c07628fe2c68a78140fe98a6312e128c5e9"
                ),
                .binaryTarget(
                    name: "Agorafdkaac",
                    url: "https://download.agora.io/swiftpm_2/AgoraAudio_iOS/3.7.0/Agorafdkaac.xcframework.zip",
                    checksum: "91f251ea2c73f602c4fb397eb3aeaa89f355a7d5100ad63a7f0909463fdf988a"
                ),
        .binaryTarget(
                    name: "AgoraRtcKit",
                    url: "https://download.agora.io/swiftpm_2/AgoraAudio_iOS/3.7.0/AgoraRtcKit.xcframework.zip",
                    checksum: "88dde0864946ddf2b53682e5286cd0611e77b7898c93b01a6522db8d738308d6"
                ),
                .binaryTarget(
                    name: "AgoraSoundTouch",
                    url: "https://download.agora.io/swiftpm_2/AgoraAudio_iOS/3.7.0/AgoraSoundTouch.xcframework.zip",
                    checksum: "8c3da4a746dacb1b4d530ce1a81a90569853102e53bcf5c062dbe5803fc25ed8"
                ),

And now i'm seeing a different error when trying to compile for SwiftUI Previews:

linker command failed with exit code 1 (use -v to see invocation)

----------------------------------------

SchemeBuildError: Failed to build the scheme "Serenity"

linker command failed with exit code 1 (use -v to see invocation)

Link HAHomeKit_-2D5A25D708B461BD_PackageProduct (arm64):
ld: warning: Could not find or use auto-linked framework 'AgoraRtcKit'
Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_AgoraRtcEngineKit", referenced from:
      objc-class-ref in HAServiceKit.o
  "_OBJC_CLASS_$_AgoraRtcEngineConfig", referenced from:
      objc-class-ref in HAServiceKit.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Link Serenity (arm64):
clang: error: no such file or directory: '/Users/ethanthomas/Library/Developer/Xcode/DerivedData/Serenity-ammhovqgzfuogudxbhivmwhannha/Build/Intermediates.noindex/Previews/Serenity/Products/Debug-iphonesimulator/PackageFrameworks/HAHomeKit_-2D5A25D708B461BD_PackageProduct.framework/HAHomeKit_-2D5A25D708B461BD_PackageProduct'
Command Ld failed with a nonzero exit code

What's odd is that it builds/launches fine on device and simulator but not for SwiftUI Previews

ethan021021 commented 2 years ago

Hi! Any update on this?

This issue is really impacting the speed on my development

ethan021021 commented 2 years ago

Hi,

Is there anyway to get in touch with the team? Thank you

maxxfrazer commented 2 years ago

Did a quick search and found this, does it help with swiftui previews for you? https://developer.apple.com/forums/thread/657913?answerId=628459022#628459022

another thread here: https://stackoverflow.com/questions/70608395/xcode-13-2-1-preview-not-working-but-simulator-works

There seem to be a few people using a variety of frameworks having problems with preview but not simulator.

ethan021021 commented 2 years ago

Did a quick search and found this, does it help with swiftui previews for you? https://developer.apple.com/forums/thread/657913?answerId=628459022#628459022

another thread here: https://stackoverflow.com/questions/70608395/xcode-13-2-1-preview-not-working-but-simulator-works

There seem to be a few people using a variety of frameworks having problems with preview but not simulator.

Hey thanks for the reply,

I just tried these suggestions but still haven't had any luck :/. I believe it's an issue with the RtcBasic framework since I'm linking other frameworks and Preview's works just fine. As soon as I remove RtcBasic from my dependencies my Preview's start to work again. Is there any further information I can provide to help you reproduce this? Thank you

ethan021021 commented 1 year ago

Hey any update on this end? Thank you

aiFigueiredo commented 1 year ago

Any update on this?

I'm facing the same issue on my end but I get it while trying to run the tests target of an internal Swift Package:

Users/.../Build/Products/Debug-iphonesimulator/AgoraCore.framework/AgoraCore' (code signature in <...> '/Users/.../Build/Products/Debug-iphonesimulator/AgoraCore.framework/AgoraCore' not valid for use in process: Trying to load an unsigned library)

Tried the above solutions as well but no luck.