Xcode change dynamic framework Product Module Name - ios

I’m trying to change the product module name of a dynamic framework.
The main reason I’m doing this is that my framework is customised for each client, so I have different targets with different names and output files that I want to keep different as they are, but I would like the framework to be imported for all the targets with the product name.
The framework is in objective C and consumed by a swift application.
In the Xcode build settings the DefinesModule is set to YES.
Let’s say the product name is CustomerSDK and I want it to be imported as ProductSDK.
For example: The framework file will be CustomerSDK.framework and the import statement import ProductSDK.
If I use the $(PRODUCT_NAME:c99extidentifier) as the module name (the default option in Xcode) by calling import CustomerSDK it works, but when I try to change the Product Module Name field in build settings to another one the code completion of Xcode in the host application project doesn’t find the module name and even if I write it I get the “No such module ProductSDK” error. Looking inside the resulting product framework I can see that no modulemap file is generated.
I tried also to create a custom module.modulemap file, in this case the code completion of Xcode in the host application project proposes the new name, but when I try to compile I still get the “No such module ProductSDK” error.
framework module ProductSDK {
umbrella header "CustomerSDK.h"
export *
module * { export * }
}

Related

module map naming in iOS for static library

When I used the name module.modulemap for a framework, I got an error saying "redefinition" of module. Which turns out to be a bug from Apple:
Known Issues
When building a framework that has module maps in both the source and the install directories that define the same module, the compiler will show a redefinition message. (28638816)
Workaround: Rename the module map file in the source directory to a non-default name (the default name is
module.modulemap
or
module.map
), and set the Module Map File build setting to the renamed module map.
So after changing the name to my_module.modulemap (and updating the build settings path), it worked fine. When I build it, Xcode will generate a module.modulemap file, with the content of my_module.modulemap prepended.
However, when I tried out the static library, I can't use my_module.modulemap anymore. Even if I write non-exist files it's not complaining:
module Foo {
header "NonExistFile.h"
}
When I look at the exported header in final product, the module map file does not show up at all. How do I fix it?

File 'ProjectTests.swift' is part of module 'Project'; ignoring import

I'm trying to implement a unit test for my project.
When I use :
#testable import Project
it says:
"File 'ProjectTests.swift' is part of module 'Project'; ignoring
import". So I can't use project classes
I read similar questions and use all answers, but it gives no results.
Seems like I have some trouble:
Xcode - File is part of module, ignoring import
tried:
Check product module name in Project -> Build Settings -> Packaging
-> Product Module Name. (it is same for sure)
Enable testability in Build Options
Make Legacy Build system
Target Membership is on Tests target(not project, and this is right)
Full clean Derive Data and project
copy content of project, delete all content, copy back.

Module map location and compiler settings with mixed Objective-C/Swift frameworks

Background: I'm converting a large old mixed language codebase to a framework. I'm having problems, so I thought I'd start with a minimal test project to see how things work. I ran into more problems. This is Swift 5.0 with Xcode 10.2.1.
I created a new iOS framework project called TestFramework. TestFramework has the following source files:
OCTest.[hm], with a single private class
OCPublic.[hm], with a single public class. It calls OCTest.
STest.swift, with a single public class. It calls both OCPublic and OCTest.
I also have the following two umbrella headers, in the same folder as the source files:
TestFramework.h, which is the one Xcode created automatically. I only added #import "OCPublic.h".
TestFramework_Private.h. It has two lines:
#include "TestFramework.h"
#include "OCTest.h"
They all reside in the TestFramework folder, along with Info.plist and everything else Xcode creates automatically.
I managed to make this compile, build a framework package with carthage build --archive and use the resulting framework successfully in a test app with the following module maps and build settings:
TestFramework/module.modulemap exists and is empty.
TestFramework/module.private.modulemap exists with these lines:
module TestFramework_Private {
umbrella header "TestFramework_Private.h"
export *
}
Both MODULEMAP_FILE and MODULEMAP_PRIVATE_FILE in build settings are unset.
SWIFT_INCLUDE_PATHS is $(PROJECT_DIR)/TestFramework.
DEFINES_MODULE is true.
If I add any content (framework module TestFramework { … }) to module.modulemap or try to make MODULEMAP_FILE or MODULEMAP_PRIVATE_FILE point to their files (with the values TestFramework/module.modulemap and TestFramework/module.private.modulemap) I get various build errors (can't find TestFramework_Private, redefinition of module TestFramework, etc.)
If I remove the empty main module map, I get No such module 'TestFramework_Private' where STest.swift tries to import it.
If I try to move the private things into a separate folder and change SWIFT_INCLUDE_PATHS and MODULEMAP_PRIVATE_FILE I get more build errors.
Are there some values for the MODULEMAP* settings that should work, with or without content inside the main module map? What should I do if I wanted to move things into different folders?
It seems at least some of my problems were caused by this:
When building a framework that has module maps in both the source and the install directories that define the same module, the compiler will show a redefinition message. (28638816)
Workaround: Rename the module map file in the source directory to a non-default name (the default name is module.modulemap or module.map), and set the Module Map File build setting to the renamed module map.
Renaming my module map file to anything other than module.modulemap — the name used in, for example, all over Clang documentation — made it possible to point MODULEMAP_FILE at it, and allowed me to move the headers to a different location etc.

Shared internal framework not found after renaming project

I have a swift Xcode project say named Motorcycle and it has an internal framework shared among targets called MotorcycleKit. After I rename my project to Rollerblades I see in the project overview I now have a RollerbladesKit instead of MotorcycleKit. After doing a find and replace on import MotorcycleKit to import RollerbladesKit and running the app I get a module not found error on my import RollerbladesKit. How do I fix this error?
The Xcode rename function has a bug where it renames shared internal framework's Project Name to the exact literal of the new project name if the shared internal framework's name has the name of the original project in it. So from the question. MotorcycleKit has Motorcycle in its name and it gets replaced with Rollerblades instead of RollerbladesKit. You can fix this by going to your framework's Build Settings > Packaging > Product Name and correcting the name there, in this case by appending it with 'Kit'.

Duplicate class issue while linking a framework in iOS

How to Link a framework in your project where framework containing a class whose name is exactly the same of yours.?.I know that there is solution if we need to import same header name in two different target,because targets can be configurable.My case is different . For me I have a framework which have a file named a.h and it's a.m (For clarity let "a" be AppDelegate).The project where I want to use that framework also contains both(AppDelegate).So how to configure that I can run framework inside that project

Resources