add module into ios framework, app get "module not found" - ios

I have a swift framework project(let's call it Framework1), inside it use some 3rd party objective c files. I use module instead of umbrella file because of ambientlight's answer in this post
I create a subfolder(let's call it MiscModule), put module.modulemap under that folder, include all oc headers, and configure the Build Setting. The framework build fine, I can get framework build.
But after I put Framework1 in app project, build the app. It complain about "Module MisModule not found".
I saw the Framework1-swift.h file have an line of "#import MisModule". I had thought MisModule is build into binary in Framework1's bundle.
Do I miss something?

When you built it, those files that in modules did not be embedded into the framework, it would change the relative path to absolute path.
such as import YourModule change $SRCROOT/... to User/YourProject/
so, not use custom module in framework, it will change the import paths to
absolute path.
Your can build a framework for the oc files.

Sometimes cleaning Xcode, restarting both the simulator and xcode, and then trying to run again helps. If worst comes to worst, try heading into finder and doing a deep-clean. Delete ~/Library/Developer/Xcode/DerivedData/

Related

How to create a close source SDK for iOS with other framework dependencies

I have multiple projects that build into XCFramework. For example:
FeatureA.xcframework
FeatureB.xcframework
FeatureC.xcframework
When I build MySDK, it produces a .xcframework with a "frameworks" folder in it. FeatureA, B and C are inside that folder. This means that the frameworks were embeded.
But, when I add MySDK into another project and try to build I get: no such module "FeatureA" OR Could not build "FeatureA" to Objc.
The only way that my test project builds is by adding each .xcframework dependency. I tried using the search paths, but no luck.
I also tried change the modulemap file, but the error describe above continues.
I want to build a SDK, MySDK.xcframework that contains all depencency frameworks. In this way I hope that someone who wants to use my library will only have to import MySDK.xcframework.
What I want is even possible for iOS?

Custom framework cannot find other pod that required Bridging-Header file: "No such module 'InsiderMobile'"

Currently we are developing a custom framework which need to use InsiderMobile cocoapods. According to this guideline, we will need o create Bridging-Header File to use InsiderMobile. However, Bridging-Header or Umbrella file did not work inside our framework so we have to use MapModule with Build Settings/Import Paths method, then the framework compile just fine.
The actual problem occur when we try to apply our framework to an application. The framework recognize all other pods except InsiderMobile. Here our current settings:
We got both our custom framework and InsiderMobile in Pods folder,
Our custom framework is Embed,
MapModule with Build Settings/Import Paths method is also apply,
Here is some methods that we've already tried:
pod install again, delete derived data, clean and rebuild project,
Manually edit custom framework -umbrella file, but bump into new error: "Include of non-modular header inside framework module ", also try to set Allow Non-modular Includes In Framework Modules in Build Settings to Yes
Also Embed InsiderMobile framework,
None of these above methods solve the problem. Is there anyway to allow our custom framework to import InsiderMobile? Thanks in advance.
In case it's helpful, i have found a way to temporary solve this issue. Not the best but help us unstuck the developing process. Basically, i have been trying to work with .modulemap method the whole time, you can find the docs here. Then i found this topic, and there this guys repo. I just follow the repo with a little change on the .modulemap file and everything work fine for me. Here's my .modulemap file:
module InsiderMobile [system] {
// Framework complier
// header "../../../../Pods/InsiderMobile/InsiderMobile.framework/Headers/Insider.h"
//App complier
header "../../../../../../Pods/InsiderMobile/InsiderMobile.framework/Headers/Insider.h"
export *
}
Cause .modulemap file directory might change when it go remote, so i have to change to suitable path before deploy it. I know it inconvenience but it work for now.

Embedding XCFramework in application with project framework dependencies

I have an Xcode workspace which features a project with an iOS Application target, and another project with a Framework target. The framework target is dependent on another framework, which is integrated in the form of an xcframework:
MyApp
MyFramework
OtherFramework
Using regular OtherFramework.framework would require it to be linked to MyFramework and then embedded in MyApp even though MyApp doesn't require the framework itself. However when integrating with xcframework, this project then fails to build with a No such module 'OtherFramework' error.
Project settings:
MyFramework Project
MyApp Project
Removing OtherFramework.xcframework from the MyApp target fixes the build issue, but then causes library not loaded errors as the framework is not present in the application.
Demo project here: https://github.com/msaps/XCFramework-Link-Issue
How are you meant to link an xcframework in an application and link in a dependent framework?
Why?
pyckamil just posted this article which explains the issue in detail: Everything wrong with XCFrameworks.
It turns out Xcode has an optimisation for the ProcessXCFrameworkLibrary step which extracts the correct .framework from an .xcframework for the active build architecture. This is only run once which causes issues for additional targets that try to link the same framework.
Update
This issue is resolved in Xcode 12.0
UPDATED - Resolved in Xcode 12.0
shinsuk came up with a reliable workaround that works by adding architecture-explicit framework search paths to ensure the correct .framework within an XCFramework is found.
Details can be found in the README.
Check build settings and defining the Framework Search Paths to a folder which contains the frameworks in question. If the frameworks are placed in your project directory, simply set the framework search path to $(SRCROOT) and set it to recursive.
check the response Getting error "No such module" using Xcode, but the framework is there
IMO, It seems not xcframework issue.
Check out this answer: https://stackoverflow.com/a/59435627/2661407
Umbrella frameworks are not supported on iOS, watchOS, or tvOS.
OtherFramework.xcframework should be signed and embedded in your host app.
and add "#executable_path/Frameworks" setting into your MyFramework.framework > Build settings > Runpath Search Paths.
I had this issue as well after using xcframework instead of framework. So I changed my project structure:
The MyFramework Peoject embed OtherFramework.xcframework,Then make it exported using #_exported import OtherFramework in MyFramework Project. And the MyApp just link MyFramework but can both import/use MyFramework and OtherFramework.
BTW, It seems to custom the #rpath and manual codesign the OtherFramework.
I had an issue like that as well.
First, make sure if you have MyFramework.framework file within the same directory as MyApp.
Second, when building MyFramework.framework, make sure that OtherFramework.xcframework is as well in MyFramework's project directory.
And one more thing, check target SDK versions. They should be somewhere on the same level.
I had the same issue as you, and after seeing your pbxproj I think it can be solved the same way.
Change your framework search path to recursive (either through UI or manually editing the pbxproj "$(SRCROOT)/../Frameworks" => "$(SRCROOT)/../Frameworks/**"), like so: https://github.com/msaps/XCFramework-Link-Issue/pull/1/files

Socket.IO error: zlib no such module (Swift 3, Xcode 8.3)

I followed the instructions of Socket.IO's README.md of manually implementing Socket.IO. I dragged in the Source folder into my project and I double-checked to make sure 'Add to target' was selected. When I try to run my project, I get an error 'No such module' because zlib can't be found in Compression.swift. Am I supposed to add any other files or folder to my project? What am I missing here?
Okay, I managed to find the answer on my own, even though the documentation of Socket.IO is very unclear about this and doesn't mention anything about zlib. To import zlib, go to your project's Build Settings and scroll to Swift Compiler - Search Paths. There, you should create a new path by clicking the + in both Release and Debug. Then, add the folder path to the zlib folder that was included in the Github file you downloaded. You can either direct your folder path to its original location inside the Github folder you downloaded, or you can place the zlib folder inside your project folder. It doesn't matter where you leave the folder, as long as you're referring to it correctly. Now, build and run and the No such module error should disappear.
I also got this error when compiling the project after having added socket.io. I fixed it by adding libz.tbd to the Linked Frameworks and Libraries (clicked the + button in the General tab of the target, then I picked it from the list).
After doing that however, I got another error:
No such module 'CZLib'
I'm not sure which version of socket.io I added as I copied the entire folder from one of our previous projects. Anyway, the socket folder had a module.modulemap file which seemed to define the missing module. So I tried to fix the error by adding the socket.io folder containing the module map to the targets Import Paths, found in Build Settings under Swift Compiler - Search Paths.
The project would now compile without errors. At this point I tried to remove the linked libz.tbd and it would still compile. I have still not tried to establish a socket connection, but for now I'm moving forward without linking libz.tbd.

Framework import issue in xcode

Here the problem: For a project at work we need to include an extern API: mobileAppTrackeriOS from HasOffers.
It gives us a framework to include in our projet and instruction to enter in our code.
So I copy the framework in the project directory and drag it into xcode to include it.
But when i want to use it with:
#import <framework/mainheader.h>
The build give me an error :
Lexical or Processor issue 'MobileAppTrackeriOS_arc/MobileAppTracker.h' file not found
I check the framework search path in my target build setting, my main directory where is the framework is here.
I test with "" instead of <> same issue...
i cleaned and rebuilt, try to include directly the header... many ridiculous things... no changes.
So what I forget?
I'm on Xcode 4.5 and develop for iOS 6.0.
A question, can you see if the framework is in Build Phases -> Link binary with Libraries?
If answer is not, you must add in this section.

Resources