google-ar / arcore-ios-sdk

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

Swift Package Manger Support – GeoSpatial API #52

Closed arthurschiller closed 1 year ago

arthurschiller commented 2 years ago

Hello,

are there any plans to distribute this project via Swift Package Manager? Specifically I want to utilise the GeoSpatial API within an existing ARKit-based app that already migrated away from CocoaPods over a year ago. We are also using Firebase via Swift Package Manger and as ARCore via CocoaPods lists Firebase as a dependency it would effectively build Firebase twice. Would greatly appreciate a reply.

Best regards Arthur

maxxfrazer commented 2 years ago

Skipping Swift Package Manager with an SDK of this size and reach is a bit silly. Is there a technical reason why? There's also some extremely outdated practices in the examples.

Such a great piece of technology, but the SDK's developer experience needs some TLC.

jrullman commented 2 years ago

ARCore 1.33 has beta support for SPM - you can download the pod bundle (here for 1.33), unzip it and use it as a local Swift Package. Follow the instructions in the bundled README file.

arthurschiller commented 2 years ago

Amazing @jrullman! 🙏 Thanks a lot, will check it out!

arthurschiller commented 2 years ago

Hi @jrullman,

quick update: so far I wasn't able to get this working. I also created a barebones super simple project with the following steps:

It always shows me a linker error, telling my bitcode is missing. If I disable bitcode for the target I get even more errors. Screenshots attached. Tested with both Xcode 13 and 14, minimum deployment target iOS 15.4. Anything obvious I might be missing?

Thanks a lot!

settings bitcode_enabled bitcode_disabled

jrullman commented 2 years ago

1) About bitcode, as mentioned in the CHANGELOG for 1.33 we have removed bitcode from our binaries, as Apple has deprecated it. As of Xcode 14, it will no longer be enabled by default, but for Xcode 13 you would have to disable it manually on your project. (The CocoaPod disables it for you, but unfortunately SPM doesn't provide a way to manipulate the project settings like this.)

2) For the linker errors, it's not linking libc++ or a bunch of other Apple SDK frameworks. We could add these in Package.swift using .linkedFramework() and .linkedLibrary(), but with the frameworks there is the issue of weak linking - it seems to always strongly link the frameworks. Instead we are relying on the magic of auto-linking, where Xcode figures out which libraries and frameworks to link (and whether to use strong or weak linking) based on #import/@import statements and modulemap files. To get this to work you just need to: a) #import or @import ARCore somewhere in your code (you probably didn't do this yet). b) Make sure the Build Settings "Enable Modules" and "Link Frameworks Automatically" are set to "Yes". I know it's strange for something to build only after adding an import statement; we need to document this better.

(Quick note: you don't need to add dependencies on "GARSession" and "Base", as these are just shared dependencies for other components, but it doesn't hurt anything either.)

arthurschiller commented 2 years ago

Ahh okay 2. did the trick but I think this definitely needs to be documented better. My projects are Swift only and to get this working I had to create an Objective-C bridging header where I added the @import ARCore; statement. As I suppose most new projects nowadays would be Swift exclusive I think that's a crucial step for the documentation. Thanks for the help and hints @jrullman!

arthurschiller commented 2 years ago

Nevermind, so it all builds fine but at runtime I get the following exception:

Screenshot 2022-08-24 at 14 41 04 Screenshot 2022-08-24 at 14 42 13

Did you get it to run in a Swift-only project? The previous version 1.32.0 ran fine via CocoaPods.

jrullman commented 2 years ago

The unrecognized selector issue happens when you don't have the linker flag "-ObjC", which prevents the linker from throwing away Objective-C categories.

For the import statement, I believe it can just be a regular import statement in Swift, which is equivalent to @import in Objective-C.

arthurschiller commented 2 years ago

Thanks, it's working now. Forgot the linker flag this time. Appreciate the patience!

sinano1107 commented 1 year ago

Hi @jrullman Can you please tell me how to download the pod bundle? I am looking for pod bundles for versions other than 1.33 (e.g. 1.34), but I don't know how to get them on my own.

arthurschiller commented 1 year ago

Hi @jrullman Can you please tell me how to download the pod bundle? I am looking for pod bundles for versions other than 1.33 (e.g. 1.34), but I don't know how to get them on my own.

Hi, you can find the download link in the podspec: https://github.com/CocoaPods/Specs/blob/master/Specs/4/e/a/ARCore/1.34.0/ARCore.podspec.json

Podspec can be retrieved here: https://cocoapods.org/pods/ARCore (Right sidebar – »See Podspec«)

iuriipleskach commented 1 year ago

Hi! I'm also interested in full SPM support. Hopefully it's still on the radar :)

jrullman commented 1 year ago

Stay tuned ;)

15kingben commented 1 year ago

Starting from release 1.36.0, Swift Package Manager is officially supported. Please see the README for installation instructions.