Static Library import - ios

I created a static Library but I am unable to import it. Here are the steps that i followed to add it to my project.
1) From finder, I dragged my library .xcodeproj into my main project.
2) I selected the main project, went to target and then build phases.
3) I added the library under Link Binary With Libraries and Target Dependencies.
4) Under Build Settings -- Header Search Paths, I added $(BUILT_PRODUCTS_DIR).
5) I also added -ObjC to Other Linker Flags.
However when I try importing the library, it's not being recognised.
Can anyone help with this?

You can include library by two ways either u can drag and drop library.xcodeproj into your project or you can include .lib file into your project. It might be possible that your lib file was not build properly.
You could build ur lib file by opening ur library.xcodeproj in xcode select build target as iOS Device and build the project.
If build is successful u could find the newly created .lib file to the following path LIbrary/Developer/Xcode/DerivedData now remove the previous lib file and include the new lib.

Related

How to fix Apple Mach-O Linker Error Group issue in xcode?

I try to implement push notification:
Source
But I Got this issue :
Apple Mach-O Linker Error Group
no such file or directory:
'/Users/arunkumar/Library/Developer/Xcode/DerivedData/sample-bskvypzxnjnnszbjeelvenubespf/Build/Products/Debug-iphonesimulator/libRCTPushNotification-tvOS.a
How to fix that issue ?
Run react-native link this will all for you.
Or use these steps
Step 1
.xcodeproj file inside it's folder. Drag this file to your project on Xcode (usually under the Libraries group on Xcode)
Step 2
Click on your main project file (the one that represents the .xcodeproj) select Build Phases and drag the static library from the Products folder inside the Library you are importing to Link Binary With Libraries
Step 3
project's file, select Build Settings and search for Header Search Paths. There you should include the path to your library (if it has relevant files on subdirectories remember to make it recursive, like React.
refer this one
link

Deploying static library in Xcode 6

I want to deploy a static library that I've been writing in Xcode 6. I've already managed to compile the library into a .a file. Now I want to use it in another project. Also, note that including the library project is not an option, as this library is supposed to be distributed in binary.
I also managed to import the .a file into a new project, but I'm not sure what the best way to find the header files is. Should I copy them to a system folder? Should I just link to the framework's (downloaded) folder? Should I import the headers directly in the project? As the framework is meant for distribution, I think that ideally I would copy them to a system folder.
Finally, I've read that I need to build two different versions if I want the framework to be compatible with both iOS and the simulator. Is this true? Can it not be distributed in the same binary?
I distribute such a library for my company. I essentially put the .a file (built up with lipo) into a folder along with the headers. The client then needs to add the .a file to their project in the Build phases, Link Binary With Libraries. Then, they should add the path to the header files using a project relative path to the "User Header Search Paths". From my readme:
Process to Add the SDK to Your Project
1) Copy the xxx folder to the app folder, which contains the
".xcodeproj" project file, then add the directory to your project,
but don't add it to any targets (unselect the checkbox).
2) Add the appropriate library (iOS 6.0 or 7.0) folder, by going to your target's Build Phase tab, Link Binary with Libraries, tap
on "+", then navigate to the appropriate folder and select
libXXX.a
3) Add the following to the Project's Build Settings:
Search Paths -> Library Search Paths:
$PROJECT_DIR/xxx/ios // I have multiple folders each with a lib
Search Paths -> User Header Search Paths: $PROJECT_DIR/xxx
Linking -> Other Link Flags: -ObjC NOTE: If you fail to do this, your app will crash on launch (if it uses categories)
I use lipo to add both the Simulator .a files too - even thought this is not officially sanctioned. As others have said, Apple frowns on this yet offers no easy way for users of your library to use different .a files - the "official" solution would be for you to write a custom build script.

Any way to make bundle xcode project to include a static library xcode project?

I have a static library xcode project (.a) and a bundle xcode project (.bundle)
I added the (.a) as a sub project of (.bundle) and added to [Target Dependencies] and [Link Binary With Libraries].
After run the bulid the (.bundle) still not contain any binary file inside (.bundle).
It's work if I add the .c and .h files to under (.bundle) directly, but that make me need to handle two project files. Any way can make (.bundle) just build with the (.a) ?
This question same as what I asked, I tried to follow his 11 steps without the step 10 because he said lastly no need that step. But the generated (.bundle) still without contain any binary
Finally, I make it work.
The step 10 still important and below is corrected step 10.
create a dummy.c under (.bundle) project and the dummy.c can just totally empty. remove the setting for the library you want to link inside Link Binary With Libraries instead use -Wl,-force_load,$(CONFIGURATION_BUILD_DIR)/libYourLib.a or -all_load to Other Linker Flags
PS: And also can use sub-project instead of workspace. and use Target Dependencies instead of Edit Scheme to achieve the same effect.
The testing project

How to make XCode add the linked project headers and implementaion files to the static library and framework

I have a static library project and in that project I linked a .xcodeproj to the source code so I can update easily actually and to not copy and paste files in the static library project for easy update.
The purpose thought it's to embed this .xcodeproj with my code into the result static library or .framework that I will build using a script.
Although I can see that there is nothing added in the compile sources or the copy header files which I added. If I try to add with drag and drop files from the linked project to my static library build phases copy header section it copies the file to my project again, but I don't want this.
And if I add a header file #import to one of my public headers and try to use the static library to the client project it complains that the header is not found!
So, in the end, what I want is the whole linked project files to be copied in the resulting static library or .framework with the scripts and target I have.
Is this possible to achieve, I think I miss some project setting that I'm not aware about that will see and copy all header and implementation files to my result static library or .framework?
Is my approach overall correct? I don't think that there is no option to use a linked project in a static library and embed it when the build is happening since I am using it in my project!
I could add the .framework of the third party component too and merge to my static library. I have created this question earlier today. Is it possible to include a .framework in a .framework and how?
Regards.
Not sure if your #import-not-found issue is a linker issue, but...
Make sure to use the -ObjC flag in "Other Linker Flags" in the library's Build Settings. This gets the linker to build everything in the library.
Mentioned here:
https://developer.apple.com/library/ios/technotes/iOSStaticLibraries/Articles/configuration.html
And also make sure you link in the library in the build settings for the project that needs it.

Linked Static Libraries are NOT Rebuilt Together with Main Project

In my workspace I have 2 projects: my main project, and a static library project. I link the resulting .a of the library project into the main project. Problem is, when I make a change to a source file in the library project, and run the main project, the library project does not get rebuilt, and the old .a library gets used. This leads to strange runtime errors.
Is there a way to enable correct compilation of dependency projects?
This is a bug in Xcode there for ages.
Workaround:
In Project Navigator find the reference to the library .a file in the main project.
In Utilities pane, change to "Relative to Build Products"
Edit project.pbxproj and find the line the static library lib*.a
file is referenced by "path=...".
Remove the path, so just lib*.a is left.

Resources