Unable to build framework - ios

I am unable to build a framework doing following->
1.Select a simulator in run devices
2.Under Product -> build in Xcode tool bar
3.Right click on the product section ->show in finder
now in terminal I execute following command->
lipo -info /path/to/debugfolder/
it gives me follwing error -
fatal error: /Applications/Xcode
app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo:
can't map input file:
/Users/Imacshubhendra/Library/Developer/Xcode/DerivedData/SendOTPFramework-hkrvnvttlmwijudmlfcaxdowqhpz/Build/Products/Debug-iphoneos/SendOTPFramework.framework
(Invalid argument)
I am follwing these steps->
In the framework project:
Set the build setting for the target (and for the project, just to be safe) 'Build Active Architectures only' to NO. We want to build all architectures so that the binary can be used in all supported devices, not just the one we happen to build for. Depending on your deployment target (and as a consequence of that, the devices you support), you might need to add the architecture ARMv7s
Build for simulator and build for device, this will produce two frameworks in the derived data folder.
In Terminal:
Find the derived data path for the project. Look for the folder 'Build->Products'. Inside it should be '-iphoneos' and '-iphonesimulator'. Inside each is a .framework folder. Copy one of those to some nice folder. From each of those .frawework folders, copy the binary that is in there to one folder.
In terminal run the command 'lipo -create -output '. This will create a fat binary with all architectures for both simulator and devices. Replace the one in the copied .framework directory with the newly generated one.
To use the framework in another app:
Select the Project in the Project Navigator, select the target, and select 'General' tab.
drag the .framework folder onto where it says 'Add embedded binaries here'.
In the build settings of the target, add the path to the .framework folder to 'Framework Search Paths'.
Import files in your source code using #import

Related

Will changing the info.plist of custom framework manually create problems in installing on device?

I made a custom framework from a xcode project with "example.com.a" bundle identifier using lipo -create command by joining simulator and iphone architecture frameworks. So it has a bundle identifier "example.com.a" in it's info.plist file by default. I am able to use this framework in my app and my app installs on device without any error
Now when i try to change the bundle identifier of the custom framework to something like "myapp.custom.framework" by manually editing the info.plist inside the framework folder instead of xcode project .
By doing this I am unable to install the .ipa in the device. It shows "Unable to install the app".
So my question is
1) Is manually changing the bundle identifier or adding keys to custom framework's info.plist affects the custom framework functionality ?
2) For changing the bundle identifier of custom framework do we need to change it in the main xcode project? Right now i am changing and adding keys in the info.plist which is there in framework folder.
After long research and trial i found that if we change the bundle identifier in info.plist inside the custom framework folder, it will create error while adding in a sample project, instead we need to change the bundle identifier from the XCode project for framework and then generate iPhone and Simulator .framework and use lipo -create output to combine them and create a universal library.
Following are the steps :
To build and distribute universal/fat frameworks:
In the framework project:
Build xcode framework project for simulator and build for device, this will produce two frameworks in the derived data folder.
Find the derived data path for the project. Look for the folder Build->Products. Inside it should be '-iphoneos' and '-iphonesimulator'. Inside each is a .framework folder. Copy one of those to some nice folder. From each of those .frawework folders, copy the binary that is in there to one folder.
In Terminal:
In terminal run the command lipo -create -output <outputName> <binaryFromiphoneos> <binaryFromiphonesimulator>. This will create a fat binary with all architectures for both simulator and devices. Replace the one in the copied .framework directory with the newly generated one preferably inside the folder of iPhone platform framework.
Run lipo -info <framework path> in terminal to know about the architecture of the framework . Eg: X86 denotes simulator , arm64, arm7 denotes iphone devices.
To use the framework in another app:
Select the Project in the Project Navigator, select the target, and select General tab.
drag the .framework folder onto where it says 'Add embedded binaries here'.
In the build settings of the target, add the path to the .framework folder to 'Framework Search Paths'.
Import files in your source code using #import <frameworkName/frameworkName.h>

Xcode project giving pod file error for FIRAnalyticsConnector.framework . How to solve it?

I'm working on a book project and the project is connected by API . I'm working on the book app which has different libraries imported from the various places.
Recently, i cloned the project from bitbucket in Xcode and tried to run it. The result i got i error as follows:
enter image description here
It shows :
ld: in /Users/ishinfoservices/Documents/vadltaldhambooks/Pods/FirebaseAnalytics/Frameworks/FIRAnalyticsConnector.framework/FIRAnalyticsConnector(FIRAnalyticsConnector_a8eeba373b74508311b8b22b8d3202a6.o), building for iOS Simulator, but linking in object file built for iOS, file '/Users/ishinfoservices/Documents/vadltaldhambooks/Pods/FirebaseAnalytics/Frameworks/FIRAnalyticsConnector.framework/FIRAnalyticsConnector' for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Help needed to fix the error, as the project has lots of mixes of old libraries along with .h and .m files, the swift files with wireframes
According to the image I saw that you are trying run the app on the iOS simulator, then you could try to add the arm64 to the Excluded Architectures on the Build Settings section of your project or target, it would be like:
Take in mind that if you use Cocoa Pods is possible that also you should add the arm64 to the Exclude Architectures into the Pods project
After the above, clean, build and run the project on the iOS simulator, is possible that on your physical device you must remove the arm64 from the Exclude Architectures, it could depend on what you use in your project.
On the other hand, you can try the following: Select the project -> Select the target -> Go to the Build Phases -> Expand the Link Binary with libraries and add all pod libraries (remove if they exist in embedded binaries or Remove the old FrameWorks), after that, clean and build the project

Lipo Error while creating Universal frameworks in xcode 12

I am facing problem while making universal frameworks in xcode 12. following is the command that i ran:-
lipo -create build/simulator/FrameworkName.framework/FrameworkName build/devices/FrameworkName.framework/FrameworkName -output build/universal/FrameworkName.framework/FrameworkName
And following is the error that i am facing:-
fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: build/simulator/FrameworkName.framework/FrameworkName and build/devices/FrameworkName.framework/FrameworkName have the same architectures (arm64) and can't be in the same fat output file
when i googled this error i found solution to set my 'Architectures', in 'Build Settings', to Standard, however it was already set to standard find the screenshot attached
Note: I was following this tutorial:- https://medium.com/#anuragajwani/how-to-build-universal-ios-frameworks-74b6b07bf31d
The error tells you that both your frameworks in build/simulator and build/device folders have been built for the same architecture (arm64, which is a device architecture). You can verify this by yourself, by looking inside the .framework file: FrameworkName.framework/Modules/FrameworkName.swiftmodule.
It is possible, that one of the folders (or both) contain more than one architecture like this:
Personally, I like to build my 'fat' frameworks outside the Xcode.app folders (just to make sure I have complete control over what is where). First, run your framework for simulator (select any simulator as build target). After the process has completed, go to Products folder in Xcode Navigator, click Show in Finder on FrameworkName.framework file. Copy the shown .framework somewhere more convenient (e.g. Desktop/simulator folder)
Then, build the framework again, only this time for device (select Any iOS device as build target). Copy second .framework somewhere like Desktop/iphone folder.
Create empty Desktop/universal folder for output framework. Copy .framework file there from Desktop/iphone folder and remove Desktop/universal/FrameworkName.framework/Framework executable file. This file will later be replaced by lipo.
Next, do the lipo magic:
lipo -create ~/Desktop/iphone/FrameworkName.framework/FrameworkName ~/Desktop/simulator/FrameworkName.framework/FrameworkName -output ~/Desktop/universal/FrameworkName.framework/FrameworkName
Last step, go to Desktop/simulator/FrameworkName.framework/Modules/FrameworkName.swiftmodule copy all files that start with x86_64 prefix, and paste them to Desktop/universal/FrameworkName.framework/Modules/FrameworkName.swiftmodule. Now your Desktop/universal/FrameworkName.framework contains both device and simulator architectures. Congrats, you've got your 'fat' library!
Disclaimer: Yes, I realise there are easier ways to do this with various scripts and terminal commands, but all of them do pretty much the same thing. Once you try to do this manually step by step, it will help you understand what goes where, and what are architectures and how they can be combined.
Disclaimer 2: Starting from Xcode 12, Apple insists you build .xcframeworks instead of 'fat' libraries. See here

"No such module" error in Xcode 8

I get the "No such module" compilation error in Xcode 8.2.1 in my Swift project. I use Carthage with two modules: Alamofire and Fuzi. The Carthage/Build/iOS directory exists with the two framework files. The Build Settings/Framework Search Paths points to that directory. I have embedded the two framework files in General/Embedded Binaries. What am I missing?
You shouldn't need to embed the libraries; they should be added to Linked Frameworks and Libraries underneath the "General/Embedded Binaries" section. Make sure you have the Carthage copy-frameworks script added to your Build Phases.
From the Carthage documentation:
On your application targets’ “General” settings tab, in the “Linked
Frameworks and Libraries” section, drag and drop each framework you
want to use from the Carthage/Build folder on disk. On your
application targets’ “Build Phases” settings tab, click the “+” icon
and choose “New Run Script Phase”. Create a Run Script in which you
specify your shell (ex: bin/sh), add the following contents to the
script area below the shell:
/usr/local/bin/carthage copy-frameworks
and add the paths to the frameworks you want to use under “Input
Files”, e.g.:
$(SRCROOT)/Carthage/Build/iOS/Box.framework
$(SRCROOT)/Carthage/Build/iOS/Result.framework
$(SRCROOT)/Carthage/Build/iOS/ReactiveCocoa.framework
This script works around an App Store submission bug triggered by
universal binaries and ensures that necessary bitcode-related files
and dSYMs are copied when archiving.
Firstly you check Carthage installed or not in your machine like the following command in your terminal
carthage version
If carthage is not installed in your machine try the following.
Download the latest release of Carthage, and double-click Carthage.pkg to run the installer. Click Continue, select a location to install to, then click Continue again, and finally click Install.
Then you can check carthage version.
If you are using existing project then move to project folder like
cd ~/Path/To/Starter/Project
Try the following command for update cartfile
carthage update —platform iOS
After installation/updation completed then try the following command
open carthage
You should see a Finder window pop up that contains two directories: Build and Checkouts.
In the Carthage Finder window, navigate into Build\iOS. Now, drag Alamofire.framework(for example) into the Linked Frameworks and Libraries section in Xcode:
Next, switch over to Build Phases and add a new Run Script build phase. Add the following command:
/usr/local/bin/carthage copy-frameworks
Click the + under Input Files and add an entry for each framework:
$(SRCROOT)/Carthage/Build/iOS/Alamofire.framework

Unity 4.6.5 project won't run on iOS simulator

Unity 4.6.5 project won't run on iOS simulator and I'm getting runtime error:
dyld: Symbol not found: _OBJC_CLASS_$_CBAnalytics
Referenced from: /Users/diverseconnection/Library/Developer/CoreSimulator/Devices/983BAC55-2713-423B-B5F3-C135ECCC2768/data/Containers/Bundle/Application/D4CAC0C7-E3D6-48F5-B264-E6EB715F9709/trouble.app/trouble
Expected in: flat namespace
in /Users/diverseconnection/Library/Developer/CoreSimulator/Devices/983BAC55-2713-423B-B5F3-C135ECCC2768/data/Containers/Bundle/Application/D4CAC0C7-E3D6-48F5-B264-E6EB715F9709/trouble.app/trouble
(lldb)
Any ideas how to fix it?
Well this error is usually rather broad as there can be number of causes. You can try these fixes
Add the correct libraries in the Link Binary With Libraries section of the Build Phases.
If you want to add a library outside of the default search path you can include the path in the Library Search Paths value in the Build Settings and add -l{library_name_without_lib_and_suffix} (eg. for libz.a use -lz) to the Other Linker Flags section of Build Settings.
You copy files into your project but forgot to check the target to add the files to. To resolve:
Open the Build Phases for the correct target, expand Compile Sources and add the missing .m files.
You include a static library that is built for another architecture like i386, the simulator on your host machine. To resolve:
If you have multiple library files from your libraries vendor to include in the project you need to include the one for the simulator (i386) and the one for the device (armv7 for example).
Optionally, you could create a fat static library that contains both architectures.
Also try this
Remove Build Active Architecture Only (build setting parameter key is 'ONLY_ACTIVE_ARCH') from all of your static libraries' project build settings or overwrite it with 'NO'

Resources