Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude a library out of framework when distributing it?

We created a IOS framework which is distributed to various people. But now we came across an interesting problem. We use protobuf in our framework and one of our clients started using Expo Kit which also recently included protobuf and now our client gets a crash with our framework:

Class Foo is implemented in both ... One of the two will be used. Which one is undefined.

We can't use the Cocoapods Protobuf-ios because it is outdated.

My only option that I can think of is to build the framework without our protobuf files included for this client. So our framework will then use their Expo Kit profobuf files. How do I go about doing this in Xcode or is there an alternative solution.

Edit:

What I want to achieve but just can't seem to get it right. I want to distribute my Framework without my Protobuf.a file. Protobuf.a must be a dependancy on the client apps.

like image 828
Lian van der Vyver Avatar asked Mar 08 '19 12:03

Lian van der Vyver


People also ask

What is an XCFramework?

What is XCFramework? Apple defines XCFrameworks as a distributable binary package created by Xcode that contains variants of a framework or library so that it can be used on multiple platforms (iOS, macOS, tvOS, and watchOS), including Simulator builds.

How do I compile a framework in Xcode?

Creating Your Framework. From Xcode, choose File > New Project to create your project. Follow the prompts to select the type of framework you want and where you want to put your project directory. The default templates that come with Xcode let you specify whether you want to create a Carbon or Cocoa framework.

What is an iOS framework?

What is a Framework? Frameworks are self-contained, reusable chunks of code and resources you can import into many apps. You can even share them across iOS, tvOS, watchOS and macOS apps. When combined with Swift's access control, frameworks help define strong, testable interfaces between code modules.


3 Answers

Have you considered moving to another, more maintained, Protobuf framework like the one from Apple (bonus points for being made for Swift).

https://github.com/apple/swift-protobuf

Hope it helps ;-)

like image 198
Ethenyl Avatar answered Nov 06 '22 02:11

Ethenyl


You need to have a dynamic link to the package and avoid embedding 3rd party binaries in your framework unless neccessary.

Checkout these articles, hope they help you:

https://theswiftdev.com/2018/01/25/deep-dive-into-swift-frameworks/ https://www.bignerdranch.com/blog/it-looks-like-you-are-trying-to-use-a-framework/

Also this is interesting one:

When should we use "embedded binaries" rather than "Linked Frameworks" in Xcode?

like image 22
Amir.n3t Avatar answered Nov 06 '22 04:11

Amir.n3t


You don't need to link Protobuf in you client application, if it is already embedding/linking your framework which contains Protobuf.

In you client application, you can provide the path of the Protobuf embedded inside framework. You just need to modify the Framework Search Path for client application and provide the path to protobuf embedded inside the framework.

like image 23
abhinavroy23 Avatar answered Nov 06 '22 04:11

abhinavroy23