0

I have a swift framework and in that framework I am using GoogleMLKit/SegmentationSelfie. Because MLKit is only available via cocoa pods I have had to convert my project to a pods project and I import the MLKit library as follows.

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'MyFramework' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for MyFramework
  pod 'GoogleMLKit/SegmentationSelfie'

end

I compile my framework into a .framework folder and I then add that to my app and do import MyFramework in the file where I want to use it. I get the error Missing required module 'MLKit' This is what I expected because as the pod file shows im using the flag use_frameworks! so it should be dynamic ie the app that is consuming my framework will need to import MLKit as a dependancy. So again given that MLKit is only on cocoa pods I change my app to be a pods project and add a pod file that is exactly the same as the one above (but for my app obviously). Now when I run the app there is no compile error because its now got MLKit. However when my app starts im getting errors for what seems like almost every file in MLKit below is an example of one of the errors.

objc[10782]: Class MLKSegmentationMask is implemented in both /private/var/containers/Bundle/Application/AD152823-400E-4F1C-B553-B8EE680E64B7/MyApp.app/Frameworks/MyFramework.framework/MyFramework (0x1059b7950) and /private/var/containers/Bundle/Application/AD152823-400E-4F1C-B553-B8EE680E64B7/MyApp.app/MyApp (0x10180f5b0). One of the two will be used. Which one is undefined.

I have tried pointing the apps library search paths at the framework to see if it would resolve its need for MLKit without having to separately import MLKit in the apps pod file which didnt work. I have also tried a number of different things in the framework to try and get it to not compile MLKit into the framework and instead just simply depend on the framework.

What im trying to achieve here is to have MyFramework simply depend on MLKit without compiling it in, that way my app can import MLKit and MyFramework should be happy.

It needs to be this way round because for the purposes of this I have been using MyApp as an example app that doesn't otherwise use MLKit, but I have other apps I will be using this framework in that already use MLKit for other reasons so I don't want the framework to compile in MLKit otherwise my apps that happen to also use MLKit will always see this huge list of errors, never mind the fact the obvious issue with this error is that there are two versions of the same files and it will arbitrarily choose one of them.

Having said this I can't even get MyFramework to build in such a way that MLKit is just compiled in, I though if I can get it to compile into the framework or embed, then I could remove it from the bundle and then hopefully I could import it in the app and it would resolve the dependancy.

But I haven't been able to get any of this to work and have been looking for a week now for information online about using MLKit in a Framework and found nothing of use so far. I have found some threads about how to build xcframeworks from MLKits pods in the hope that I may be able to use them instead of cocoa pods and hopefully have a bit more control over how it gets embedded/depended on.

https://gist.github.com/MapaX/5dc58ccb16ad1f772907154ae4991dca

AngryDuck
  • 4,358
  • 13
  • 57
  • 91

1 Answers1

0

for the issue of duplicate MLKSegmentationMask implementations, it seems to me a general cocopod issue, some similar article talking about this like Class is implemented in both, One of the two will be used. Which one is undefined.

And yes, unfortunately MLKit SDKs are only available on cocopod for now(not on swift manager etc. yet).

vedopar
  • 56
  • 1