9

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.

Lian van der Vyver
  • 2,096
  • 1
  • 17
  • 26
  • Is protobuf visible outside of your framework? – HereTrix Mar 12 '19 at 08:52
  • @HereTrix How do you mean is protobuf visible outside of the framework? Maybe this will answer your question. We have a static library of Protobuf. I was hoping to build my framework so that the static lib will be a dependency but I can't seem to build my framework without the static lib included in the bundle. It keeps including it in my framework. I did try to use the Library Search paths and not link or embed it in my framework. – Lian van der Vyver Mar 12 '19 at 15:00
  • Try marking it as optional in Link Binary with Libraries in Build Phases – Tibin Thomas Mar 15 '19 at 12:02
  • @TibinThomas I did try it. – Lian van der Vyver Mar 15 '19 at 13:07

3 Answers3

3

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 ;-)

Ethenyl
  • 666
  • 11
  • 20
  • I did not go with this solution. It does not help me in my case. But at this point it looks like the only option for others. I end up removing Protobuf completely and using JSON. I gave you an upvote. – Lian van der Vyver Mar 18 '19 at 08:14
  • Well, sorry it didn't help that much. I hope you'll find a better solution in the end. – Ethenyl Mar 18 '19 at 09:14
2

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?

Amir.n3t
  • 2,859
  • 3
  • 21
  • 28
  • I did came across the first to articles. Your 3rd article is interesting. I think I understand what I need to do but how to do it is my problem. I just need someone to explain or point me in the right direction how I can achieve it. I tried a lot of things but could not get it. My framework keeps adding my Protobuf.a file in the build file. – Lian van der Vyver Mar 15 '19 at 06:50
2

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.

abhinavroy23
  • 3,630
  • 1
  • 14
  • 19
  • not sure if you did not understand my question. We don't want to link Protobuf in our client application. The client is using Expo Kit which also has Protobuf which now clashes with our Framework. What I'm trying to achieve is to build the framework without Protobuf linked inside. – Lian van der Vyver Mar 15 '19 at 06:41
  • Are you sure that you don't want to embed your version of Protobuf in your framework? Because in that case application may have conflicting requirements like different versions of Protobuf needed by your framework and some other framework. – Andrey Kuznetsov Mar 17 '19 at 05:29
  • @AndreyKuznetsov Yeah that is the reason why we embedded the library in the first place now Expo kit did the same and now we have classes that are clashing. – Lian van der Vyver Mar 17 '19 at 16:44
  • Ok. Maybe this question could lead you how to avoid that effect https://stackoverflow.com/q/31781301/979822 – Andrey Kuznetsov Mar 18 '19 at 04:02