Search code examples
iosswiftcocoapodsgoogle-mlkit

Missing required module 'MLKit' error while using a framework that uses MLKit


Recently I created a iOS Framework called "MLKit Framework" that uses MLKit Face Detection library. In order to achieve that, I just imported the library in Podfile according to documentation.

As expected, that created a xcworkspace called MLKit Framework. In order to test that new framework, I created an app called MLKitApp and added that app to the same workspace. Then I added the framework MLKitFramework to that app and tried to build it but I get the error statement: "Missing required module 'MLKit'" as the image below.

Error statement: Missing required module 'MLKit'

Why Am I getting that error? What I'm doing wrong?

Reproducible Example

I created a Reproducible Example here. In order to execute that example execute the following:

  1. Execute pod install for MLKitFramework;
  2. Add MLKitApp to MLKitFramework.xcworkspace;
  3. Add MLKitFramework.framework as a MLKitApp Frameworks, Libraries and Embedded Content;
  4. Try to build MLKitApp.

And voilà


Solution

  • The issue you're encountering is a result of Google's decision to conceal the MLKit header for the primary module. To resolve this problem, you can opt to import the standalone libraries individually, rather than importing the main module as a whole.

    To rectify the situation, replace your current imports like import MLKitFramework or import MlKit with the specific modules you intend to utilize. Here's an example of how you can modify your imports:

       import MLKitCommon
       import MLKitFaceDetection
       import MLKitVision
       ...
    

    Besides fixing your problem, by importing these individual modules, you also gain more control and transparency over which MLKit components you include in your project. This way, you can fine-tune your dependencies and ensure that only the necessary components are included, potentially reducing the overall footprint of your application and avoiding conflicts or hidden headers.