Adventures in Swift Package Manager

108 views
Skip to first unread message

Rory Sinclair

unread,
Mar 23, 2022, 1:23:56 PM3/23/22
to j2objc-discuss
Hi,

I'm wondering if anyone has explored wrapping the J2Objc XCFrameworks as Swift Binary Packages, and if anyone can share some wisdom on my experiences.

Swift Package Manager initially only worked with source code, but in the years since it was first introduced its gained some extra capabilities, such as wrapping resources and wrapping binary frameworks. 

To that end, i've created this repo: https://github.com/asmallworldsite/j2objc_JRE

Which provides a 'wrapper' package for the full JRE.xcframework from j2objc 2.8.

This line in the Package.swift file points to a zipped copy of the JRE.xcframework stored on our dev assets server, with a checksum to ensure integrity: https://github.com/asmallworldsite/j2objc_JRE/blob/master/Package.swift#L14

Trying to get this to work in our app project, I had to add headers to the Swift package project https://github.com/asmallworldsite/j2objc_JRE/tree/master/include

And I had to futz with header search paths etc in the project.

The upshot is... it works. The app project compiles and runs, but *at the same time* Xcode complains that it cant find j2objc / Java constructs in scope, such as NSDictionaryMap.

I feel like i'm doing something (or several things) wrong, and i'm a bit lost. 

Should the package have the headers in it? The XCFramework obviously has the headers in that, but unless I add them to the package itself, I don't see how the app hosting the app knows to find them (I had hoped it would be automagic...)

Anyone got any wisdom to share here? I feel like adding the JRE runtime as a Swift Package could be a cleaner way to integrate it, but there are clearly some stumbling blocks.

Thanks!

- Rory

Tom Ball

unread,
Mar 23, 2022, 1:56:15 PM3/23/22
to j2objc-...@googlegroups.com
I don't have any experience or insight to offer, other than that headers are certainly required since that's how Swift imports Objective-C libraries/frameworks/etc. 

You might get decent answers from StackOverflow if you drop any references to j2objc. Since its XCFrameworks are just regular Objective-C static frameworks, a question like "I have an XCFramework and want to create a Swift package from it" is more likely to get useful answers than "I have this weird j2objc thingy..." :-)

--
You received this message because you are subscribed to the Google Groups "j2objc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to j2objc-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/j2objc-discuss/16c41d80-e1dd-488a-9ff6-df440e93e413n%40googlegroups.com.

Rory Sinclair

unread,
Mar 31, 2022, 1:07:42 PM3/31/22
to j2objc-discuss
Haha, good point Tom. Ok, good advice, thank you. I'll see what I can do, when I get some time to futz with it. 

It could be a good way to provide j2objc's JRE emulation runtime to Swift apps in the future, so worth experimenting with, I think.

Regards

Rory Sinclair

unread,
Mar 31, 2022, 1:09:43 PM3/31/22
to j2objc-discuss
(Apologies for the delay in responding, just noticed you replied the very same day! I failed to notice, for my sins)
Reply all
Reply to author
Forward
0 new messages