Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build QRCode as an SDK dependency #32

Open
vlasty-proglove opened this issue Dec 12, 2023 · 6 comments
Open

Build QRCode as an SDK dependency #32

vlasty-proglove opened this issue Dec 12, 2023 · 6 comments

Comments

@vlasty-proglove
Copy link

Hi,

I am currently working on an SDK, and I need this framework as a dependency.
The problem I am having is that it will not build as a dependency because of some name collisions.

This problem is only when building the framework in my case also an xcframework and I have QRCode as a dependency.

Mainly, the problem is that the library's name is the same as the main public class (QRCode).

The solution is to rename the library to for example "QRCodeLibrary", and also the Source folder to "Sources/QRCodeLibrary".

That means that the import statement would be import QRCodeLibrary, and it will create a breaking change only there.

I will fork the library for now but can submit a PR for you to check what I mean.

@dagronf
Copy link
Owner

dagronf commented Dec 14, 2023

Hi @vlasty-proglove. Can you send me a simple example project that shows the issue? I'd like to actually see the issue first hand as I'm not fully understanding the scope of your issue. Where is the name collision occurring, and with what?

Is it possible to explicitly import class(es) out of the QRCode package to work around the name collisions? Like this - https://stackoverflow.com/a/67644981/146361

@vlasty-proglove
Copy link
Author

vlasty-proglove commented Dec 15, 2023

Hi @dagronf, yes, here are some examples from the command line when I try to build it using "xcodebuild" command.

note: 'QRCode' declared here
@_inheritsConvenienceInitializers @objc public class QRCode : ObjectiveC.NSObject {

error: 'QRCodeEngine' is not a member type of class 'QRCode.QRCode'
@_inheritsConvenienceInitializers @objc public class QRCodeGenerator_External : ObjectiveC.NSObject, QRCode.QRCodeEngine {

error: 'BoolMatrix' is not a member type of class 'QRCode.QRCode'
@objc public func copyMatrix() -> QRCode.BoolMatrix

This is when I tried the approach from the link that you provided, using
"import class QRCode.QRCode"

The error is the same when using "import QRCode".

Maybe there is something I am missing in the xcodebuild command, because I can build it through Xcode, but not when I want to create an archive, and then an xcframework.

The framework is written in Swift but does support Obj-C.

And as I said, forking and renaming the library in Package.swift file resolved my problem

@dagronf
Copy link
Owner

dagronf commented Dec 17, 2023

I've spent a bit of time trying to reproduce the issue with no luck. Can you please attach a minimal example project that shows the error? The information you've sent has not given any insight as to how your project is set up so I'm having issues understanding the underlying problem.

Also :-

  1. Which os are you targeting with your framework? macOS, iOS, macCatalyst, watchOS etc
  2. Which version(s) of the OS are you targeting with your framework?
  3. Which version of Xcode are you using?
  4. Which OS version are you running?

@vlasty-proglove
Copy link
Author

I've tested multiple times and finally found the problem when setting up the project that I wanted to send you.

I used this command initially:

xcodebuild -scheme "TestFramework" -sdk iphonesimulator -configuration Release archive -archivePath "~/Desktop/TestFramework-iphonesimulator.xcarchive" SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES

The problem is with the override command BUILD_LIBRARY_FOR_DISTRIBUTION.

If this is set in the Build Settings to be true, and not using it in the terminal command, it builds the framework and can be used in Xcframework. If the command is used in the terminal, then it creates a problem that I've described.

Here is a simple project TestFramework that you can use to test it.
TestFramework.zip

I have put back the option to "No" in the Build Settings. Please try the first command and then enable the build settings option and try it without that command in the terminal.

Nonetheless, we can close this.

@dagronf
Copy link
Owner

dagronf commented Dec 18, 2023

@vlasty-proglove good news that you found a workaround.

After some more digging, I've uncovered an existing bug in the Swift forums for this issue that matches the error you're seeing. Annoyingly, it was raised back in 2019 and still doesn't have a fix. There have been suggestions but nothing concrete at this point. The problem arises because BUILD_LIBRARY_FOR_DISTRIBUTION generates a module interface file (the QRCode.private.swiftinterface errors you're seeing during the build) that Swift is having issues with the namespacing.

So that means that it seems like the only clean solution (ie workaround) at this point is to rename the module within the library as you've suggested. I'm thinking using QRCodeKit as the module name -- as I mentioned earlier it's a significant breaking change for this library so I'll need to think about how to best handle it.

@vlasty-proglove
Copy link
Author

@dagronf Thanks for the assistance on this.
But one more solution "workaround" might be added to your documentation instead of creating a breaking change.

If you want to build the xcframework using the command line, most people are using it with the BUILD_LIBRARY_FOR_DISTRIBUTION=YES and the -configuration Release. They just need to remove the BUILD_LIBRARY_FOR_DISTRIBUTION parameter and change that in the Xcode Build Settings for the Release configuration to Yes.

I noticed that it was working ok when not overriding that option in the command line.

The flow would look like this.

Go to Xcode > Select Target > Build Settings and set Build Libraries For Distribution to Yes on the Release configuration (or even Debug if somebody is working with it).
Then the terminal command should NOT include that option when building.
xcodebuild -scheme "TestFramework" -sdk iphonesimulator -configuration Release archive -archivePath "~/Desktop/TestFramework-iphonesimulator.xcarchive" SKIP_INSTALL=NO

I haven't tried a Configuration script since I am not using those but will try it when I get the chance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants