Creating Static Library from a workspace - ios

I managed to get static libraries working and its all fine. Now that I have moved onto the proper library I want to create Im having issues. Im using cocoapods to import other files and it creates a workspace. Now the script I have for compiling no longer works and my assumption is because I am working in a framework now. I have been googling for hours trying to get an answer but all the things I have found only relate to turning a single project into a library
My questions are:
1) Is it possible to combine a workspace into one single library?
2) should I be trying to create a framework instead?
3) Is it just my script that isnt right?
XCODEBUILD_PATH=/Applications/Xcode.app/Contents/Developer/usr/bin
XCODEBUILD=$XCODEBUILD_PATH/xcodebuild
$XCODEBUILD -project T5Pusher.xcodeproj -target "T5Pusher" -sdk "iphoneos" - configuration "Release" clean build
$XCODEBUILD -project T5Pusher.xcodeproj -target "T5Pusher" -sdk "iphonesimulator" - configuration "Release" clean build
lipo -create -output "build/libT5Pusher.a" "build/Release-iphoneos/libT5Pusher.a" "build/Release-iphonesimulator/libT5Pusher.a"
also tried this
XCODEBUILD_PATH=/Applications/Xcode.app/Contents/Developer/usr/bin
XCODEBUILD=$XCODEBUILD_PATH/xcodebuild
$XCODEBUILD -workspace T5Pusher.xcworkspace -scheme "T5Pusher" -sdk "iphoneos" - configuration "Release" clean build
$XCODEBUILD -workspace T5Pusher.xcworkspace -scheme "T5Pusher" -sdk "iphonesimulator" - configuration "Release" clean build
lipo -create -output "build/libT5Pusher.a" "build/Release-iphoneos/libT5Pusher.a" "build/Release-iphonesimulator/libT5Pusher.a"
The errors I get are
** BUILD FAILED **
The following build commands failed:
Libtool build/PusherTest.build/Release-iphoneos/PusherTest.build/Objects- normal/armv7/libPusherTest.a normal armv7
Libtool build/PusherTest.build/Release-iphoneos/PusherTest.build/Objects-normal/armv7s/libPusherTest.a normal armv7s
(2 failures)
lipo: can't open input file: build/Release-iphoneos/libPusherTest.a (No such file or directory)
Showing first 200 notices only
and for the second, the build succeeds but the library (.a) files are never created so it cannot combine them

I have found the solution. You have to use the command:
pod install --no-integrate
when installing the pod. This will not create a workspace and allow the use of the script
XCODEBUILD_PATH=/Applications/Xcode.app/Contents/Developer/usr/bin
XCODEBUILD=$XCODEBUILD_PATH/xcodebuild
$XCODEBUILD -project T5Pusher.xcodeproj -target "T5Pusher" -sdk "iphoneos" - configuration "Release" clean build
$XCODEBUILD -project T5Pusher.xcodeproj -target "T5Pusher" -sdk "iphonesimulator" - configuration "Release" clean build
lipo -create -output "build/libT5Pusher.a" "build/Release-iphoneos/libT5Pusher.a" "build/Release-iphonesimulator/libT5Pusher.a"
Then to set the config file for pods:
-Go to project editor -> info -> configuration
-Set the target to use pods.xconfig file for debug and release

I was having the same issue myself and found that if I specified the output directories and then told lipo to look there then it worked while still letting me use the workspace. The may be different in Xcode 5 but when I use it as a custom build phase then it works without specifying the output directories and I only have to direct lipo to ${BUILD_DIR} to find the generated files.
$XCODEBUILD -project T5Pusher.xcodeproj \
-target "T5Pusher" \
-sdk "iphoneos" \
-configuration "Release"
OBJROOT=${env_variable_to_some_directory}/Obj.root \
SYMROOT=${env_variable_to_some_directory}/Sym.root \
DSTROOT=${env_variable_to_some_directory}/Dst.root \
clean build

Related

is there any change with ios static library run script with xcode 10?

I have created a static ios library, and I have created Aggregate target to get an universal library as output for that i have included shell script in the build phase section:
# define output folder environment variable
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# Step 1. Build Device and Simulator versions
xcodebuild -target OffsetCalLib-Universal ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"
xcodebuild -target OffsetCalLib-Universal -configuration ${CONFIGURATION} -sdk iphonesimulator -arch i386 BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"
# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
# Step 2. Create universal binary file using lipo
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/lib${PROJECT_NAME}.a" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/lib${PROJECT_NAME}.a" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/lib${PROJECT_NAME}.a"
# Last touch. copy the header files. Just for convenience
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/include" "${UNIVERSAL_OUTPUTFOLDER}/"
But on build it throws error like:

Unable to create iOS static library .a file using make command

My Makefile is as the following and it gives error as make:
No targets specified and no makefile found. Stop.
XBUILD=/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild
PROJECT_ROOT=/Users/AshrafMac/Desktop/iOSSDK/
PROJECT=$(PROJECT_ROOT)/InfColorPicker.xcodeproj
TARGET=/Users/AshrafMac/Desktop/iOSSDK/
all: libInfColorPickerSDK.a
libInfColorPicker-i386.a:
$(XBUILD) -project $(PROJECT) -target $(TARGET) -sdk iphonesimulator -configuration Release clean build
-mv $(PROJECT_ROOT)/build/Release-iphonesimulator/lib$(TARGET).a $#
libInfColorPicker-armv7.a:
$(XBUILD) -project $(PROJECT) -target $(TARGET) -sdk iphoneos -arch armv7 -configuration Release clean build
-mv $(PROJECT_ROOT)/build/Release-iphoneos/lib$(TARGET).a $#
libInfColorPickerSDK.a: libInfColorPicker-i386.a libInfColorPicker-armv7.a
xcrun -sdk iphoneos lipo -create -output $# $^
clean:
-rm -f *.a *.dll
Unable to create ios static library .a file using make command.
xcodebuild -project 'MyProject.xcodeproj' -configuration 'Release'
-sdk 'iphoneos9.3' clean build ARCHS='armv7 armv7s' IPHONEOS_DEPLOYMENT_TARGET='5.0' TARGET_BUILD_DIR='./build-arm'
BUILT_PRODUCTS_DIR='./build-arm'
xcodebuild -project 'MyProject.xcodeproj' -configuration 'Release'
-sdk 'iphoneos9.3' clean build ARCHS='arm64' IPHONEOS_DEPLOYMENT_TARGET='6.0' TARGET_BUILD_DIR='./build-arm64'
BUILT_PRODUCTS_DIR='./build-arm64'
xcodebuild -project 'MyProject.xcodeproj' -configuration 'Release'
-sdk 'iphonesimulator9.3' clean build ARCHS='i386' IPHONEOS_DEPLOYMENT_TARGET='5.0' TARGET_BUILD_DIR='./build-i386'
BUILT_PRODUCTS_DIR='./build-i386'
xcodebuild -project 'MyProject.xcodeproj' -configuration 'Release'
-sdk 'iphonesimulator9.3' clean build ARCHS='x86_64' VALID_ARCHS='x86_64' IPHONEOS_DEPLOYMENT_TARGET='6.0'
TARGET_BUILD_DIR='./build-x86_64' BUILT_PRODUCTS_DIR='./build-x86_64'
lipo -create './build-arm/MyProject.a'
'./build-arm64/MyProject.a' './build-i386/MyProject.a'
'./build-x86_64/MyProject.a' -output 'Mylibrary.a'
EXECUTE the above code in TERMINAL.
In the above code MyProject.xcodeproj should be replaced with your Xcode project name and iphoneos9.3 should be replaced by maximum supported deployment target by your Xcode (For Example I am using Xcode 7.3.1 and maximum supported deployment by it is 9.3 see in: YourProject >> target >>> General Tab)

Getting lipo Errors while creating the static libraries in ios

I am working with the creation of static library file.In that i added aggregate and i did the following steps
1.Clicked on the Project Navigator
2.Next clicked on the UniversalLib(Name of the Aggreagte which i have given)
3.Build settings
4.Add build Phase
5.Add Run Script and I expanded the Run Script Module and i wrote the following code
# define output folder environment variable
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
 
# Step 1. Build Device and Simulator versions
xcodebuild -target ImageFilters ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"
xcodebuild -target ImageFilters -configuration ${CONFIGURATION} -sdk iphonesimulator -arch i386 BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"
 
# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
 
# Step 2. Create universal binary file using lipo
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/lib${PROJECT_NAME}.a" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/lib${PROJECT_NAME}.a" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/lib${PROJECT_NAME}.a"
 
# Last touch. copy the header files. Just for convenience
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/include" "${UNIVERSAL_OUTPUTFOLDER}/"
6.Then I selected the aggregate target in the Scheme Selection drop down.
7.I am getting the following errors…
fatal error: lipo: can't open input file: /Users/admin/Library/Developer/Xcode/DerivedData/StaticLibrary-frasjhywfplfpoetbcefljbwhqcd/Build/Products/Debug-iphoneos/libStaticLibrary.a (No such file or directory)
cp: /Users/admin/Library/Developer/Xcode/DerivedData/StaticLibrary-frasjhywfplfpoetbcefljbwhqcd/Build/Products/Debug-iphoneos/include: No such file or directory
can anyone please help me to solve this.I searched in so many sites but i didn't find the solution for this.
I am doing this example by following this tutorial....
http://www.raywenderlich.com/41377/creating-a-static-library-in-ios-tutorial

how to build ios framework to support i386 and armv7

I need to build dynamic library as framework. I have building settings as follows:
ARCHS: armv7 armv7s arm64 i386 x86_64
ONLY_ACTIVE_ARCH: NO
VALID_ARCHS: arm64 armv7 armv7s x86_64 i386
I built target for ios device, and used lipo -info to check the architectures, the result is :
Architectures in the fat file: dyl are: armv7s armv7 arm64
So, does xcode can not build for both i386 and arm?
You need to select iOS simulator and build a framework for i386 arch. Then you can use lipo -create command to merge the two framework into one.
There is a way of doing it without exiting the Xcode. First you need to identify the latest iOS versions (64 bits) do not support i386 architecture. So if you still need i386 compatible framework, you have to build your project by selecting an old iOS version. I tried with iOS 10.
Next thing that you have to do is, add all the architectures that you need under Valid Architectures filed in the Build Settings.
Then, add a Run Script with your lipo commands to create the FAT file. (Following script I've taken from the Internet sometime back & credit goes to those who wrote that)
#!/bin/sh
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
# Step 1. Build Device and Simulator versions
xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
xcodebuild -target "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
# Step 2. Copy the framework structure (from iphoneos build) to the universal folder
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/"
# Step 3. Copy Swift modules from iphonesimulator build (if it exists) to the copied framework directory
SIMULATOR_SWIFT_MODULES_DIR="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule/."
if [ -d "${SIMULATOR_SWIFT_MODULES_DIR}" ]; then
cp -R "${SIMULATOR_SWIFT_MODULES_DIR}" "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule"
fi
# Step 4. Create universal binary file using lipo and place the combined executable in the copied framework directory
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework/${PROJECT_NAME}"
# Step 5. Convenience step to copy the framework to the project's directory
cp -R "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework" "${PROJECT_DIR}"
# Step 6. Convenience step to open the project's directory in Finder
open "${PROJECT_DIR}"
Finally what you have to do is, build the framework by selecting Generic iOS Device option.
Then to verify, run the lipo -info command

iOS: How to create an independent framework

I am creating a little SDK, I want to release a Foo.framework.
What I have done is the following:
1- Create a project framework.
2- Add my code.
3- Add an agregator.
In the Agregator Build Phases I added the this run script
#!/bin/sh
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
//make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
//Step 1. Build Device and Simulator versions
xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
xcodebuild -target "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
//Step 2. Copy the framework structure (from iphoneos build) to the universal folder
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/"
//Step 3. Create universal binary file using lipo and place the combined executable in the copied framework directory
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework/${PROJECT_NAME}"
//Step 4. Convenience step to copy the framework to the project's directory
cp -R "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework" "${PROJECT_DIR}"
//Step 5. Convenience step to open the project's directory in Finder
open "${PROJECT_DIR}"
Then I build the Agregator and get the Foo.framwork
My problem is, to be able to use the framework in another application I should:
step 1 - drag and drop the framework to my project.
step 2- And add it to the embedded binaries.
If I don't do the step 2 I get this error
dyld: Library not loaded: #rpath/Foo.framework/Foo
Referenced from: /private/var/mobile/Containers/Bundle/Application/00A2E4FD-23F4-43E8-AA85-505785A4FF16/foo.app/foo
Reason: image not found
How should I do if I want to use the framework only by dragging it to my project
(In other words add it only to Link Binary with Library) to make it simple to integrate.
Thanks in advance.
For All People facing this kind of issue the solution is here.
Just follow those instruction to build a Framework
https://github.com/jverkoey/iOS-Framework#walkthrough

Resources