google-ar / arcore-ios-sdk

ARCore SDK for iOS
https://developers.google.com/ar/
Apache License 2.0
281 stars 84 forks source link

Cannot properly include ARCore as a dependency to a custom Swift Framework #55

Closed kkaun closed 2 years ago

kkaun commented 2 years ago

Our team is developing partner iOS Swift Framework (SDK) with some 3rd-party dependencies inside.

Framework itself has several 3rd-party dependencies all embedded with CocoaPods, and they're working like a charm either during compile time or while testing on device/simulator, while being embedded inside a simple test "partner" app. No general problems here.

But there is an issue with ARCore embedding via CocoaPods suite similar to https://github.com/google-ar/arcore-ios-sdk/issues/43 .

So we're currently stuck with using common workspace and 2 projects (test app and framework itself) within it, also with CocoaPods base structure on top workspace level:

Знімок екрана 2022-06-21 о 20 46 37 Знімок екрана 2022-06-21 о 21 49 49

The Podfile here currently looks like this, inspired by the structure mentioned here https://stackoverflow.com/a/42480097/6405022:

# platform :ios, '11.0'
workspace 'Untitled.xcworkspace'

abstract_target 'CommonPods' do
    # ... some other common 3rd-party dependencies here ...
    pod 'ARCore/AugmentedFaces', '~> 1.30.0'

    target 'TestApp' do
        project 'TestApp/TestApp.xcodeproj'
    end

    target 'Framework' do
        project 'Framework/Framework.xcodeproj'
    end

end

With that said, partner test app builds just fine.

The problem which we're facing happens right after partner app launch and is always supported by crash:

... Lots of similar duplication warnings like below comes here ...

objc[58698]: Class GARPseudonymousID is implemented in both /private/var/containers/Bundle/Application/21A274AC-31B1-4AE6-9E3F-1BF720C9B221/TestApp.app/Frameworks/Framework.framework/Framework (0x103d9e0d8) and /private/var/containers/Bundle/Application/21A274AC-31B1-4AE6-9E3F-1BF720C9B221/TestApp.app/TestApp (0x10131e440). One of the two will be used. Which one is undefined. objc[58698]: Class GARPseudonymousIDStore is implemented in both /private/var/containers/Bundle/Application/21A274AC-31B1-4AE6-9E3F-1BF720C9B221/TestApp.app/Frameworks/Framework.framework/Framework (0x103d9e128) and /private/var/containers/Bundle/Application/21A274AC-31B1-4AE6-9E3F-1BF720C9B221/TestApp.app/TestApp (0x10131e490). One of the two will be used. Which one is undefined. F0621 20:33:23.600151 1 registration.h:175] Function with name CallbackPacketCalculator already registered.

Check failure stack trace: dyld4 config: 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:/usr/lib/libMTLCapture.dylib dyld4 config: 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:/usr/lib/libMTLCapture.dylib

What we already know:

Any help will be much appreciated!

kkaun commented 2 years ago

So, after some headache and playing with pods/configurations, I somehow managed to successfully launch the whole project with following structure, but only by editing scheme to Run in Release configuration:

platform :ios, '11.0'

workspace 'Common.xcworkspace'

abstract_target 'CommonPods' do
    # ... some other common 3rd-party dependencies here ...

    target 'TestApp' do
        project 'TestApp/TestApp.xcodeproj'
    end

    target 'Framework' do
        pod 'ARCore/AugmentedFaces', '~> 1.30.0'
        project 'Framework/Framework.xcodeproj'
    end

end

Seems like a bit poor workaround, but at least custom framework has the access to all desired 3rd-party dependencies and remains fully testable as for now. Still have no clue why it normally works only for Release configuration runs on physical device.

jrullman commented 2 years ago

It seems like your framework includes parts of ARCore, so those parts are getting duplicated. Note that ARCore is statically linked instead of a dynamic library. You need to somehow exclude the dependencies from your binary when you link it.

In general I would highly recommend using a system like CocoaPods or SPM to distribute your SDK, as that will take care of a lot of details for you and make things easier for developers.

rbadoux commented 1 year ago

@kkaun Did you manage to package your framework as a pod itself ?

When adding my framework as a pod in a client app, the app can see ARCore but my pod can't. I keep getting 'no such module ARCore' in my framework. When I use 'import ARCoreGeospatial" instead of "import ARCore" it works, but the framework doesn't compile anymore.

Your help would be so appreciated ! Thank you in advance.