Xcodebuild cannot build framework library for simulator sdk - ios

I'm having some issues when I try to build a framework using xcodebuild. My xcode version is 6.1.
This line works well:
xcodebuild -target Knot3DLib -configuration Release -sdk iphoneos
However it doesn't work:
xcodebuild -target Knot3DLib -configuration Release -sdk iphonesimulator
It says:
No architectures to compile for (ARCHS=i386 x86_64, VALID_ARCHS=arm64
armv7 armv7s).
I've no defined neither i386 nor x86_64 as archs in my project, so why does xcodebuild try to build i386? Here's my architecture build settings:
I can run the project from Xcode in both simulator and devices.
I've tried other similar questions but none of them worked for me.

The simulator is just that, a simulator. Xcode builds code that runs on a simulated environment on your computer. Your computer has an intel CPU and your phone has an ARM CPU. The compiler generates different code for these processors.
The error:
No architectures to compile for (ARCHS=i386 x86_64, VALID_ARCHS=arm64 armv7 armv7s).
Tells you that the architecture you are trying to compile for: ARCHS=i386 x86_64 is not in the list of VALID_ARCHS.
i386 and x86_64 are the architectures that intel CPUs use. If you are trying to build a framework with xcodebuild and you want to be able to link against the simulator sdk you need to add i386 and x86_64 to your list of VALID_ARCHS

Related

Build framework for multiple architectures (arm64, armv7, armv7s)

I'm trying to upload to TestFlight a project build for arm64, armv7, and armv7s. It is using a framework from another project. But the frameowork appears to be built only for arm64 and not arm64 (file was built for arm64 which is not the architecture being linked (armv7)).
The question is how do I make the framework containing all architectures? I want to keep the projects separated. And I don't care for simulators. I want to make sure it is built for release.
This is the framework target:
EDIT: My project is Cordova based. So it is using a plugin which utilize a pre-built framework. There are instructions out there for building a fat framework, containing simulators and device, then concatenating it with lipo. What I need is the architecture from the device I don't have as well. Does that actually mean I need three devices from arm64, armv7, and armv7s to be able to concatenating them altogether?
Apple has discontinued support for 32-bit in iOS 11. You can neither run 32 bit apps on iOS 11 nor run iOS 11 on 32 bit processors. Thus, you have to set your Deployment Target to an iOS version earlier than iOS 11 for your framework.
You can try to create an aggregate target and write an script which will support all the platform. This is sample script from one of my project.
unset TOOLCHAINS #Xcode 7.3 BUG FIX http://stackoverflow.com/questions/36184930/xcodebuild-7-3-cant-enable-bitcode
# define output folder environment variable
C_PROJECT_NAME="<<YOUR_FRAMEWORK_NAME>>"
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# Step 1. Build Device and Simulator versions
xcodebuild -target <<YOUR_FRAMEWORK_NAME>> ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"
xcodebuild -target <<YOUR_FRAMEWORK_NAME>> ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphonesimulator -arch i386 -arch x86_64 BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
rm -rf ./${C_PROJECT_NAME}.framework
cp -R ${BUILD_DIR}/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}/${C_PROJECT_NAME}.framework ./
# Step 2. Create universal binary file using lipo
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${C_PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${C_PROJECT_NAME}.framework/${C_PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${C_PROJECT_NAME}.framework/${C_PROJECT_NAME}"
mv ${UNIVERSAL_OUTPUTFOLDER}/${C_PROJECT_NAME} ./${C_PROJECT_NAME}.framework/${C_PROJECT_NAME}

iOS Aggregate Shell Script for Static Framework to support Both Device and All Simulator Architecture

I am creating Framework, I used aggregate target in that framework where we can write shell script to Build the framework for device as well as simulator based on script based on that i will have executable framework that can be imported in any project and we can use that class and method of framework.
But issue is that when we create executable framework with "schema device" then i can able to run on all device but if i make build using particular iOS5/iOS6 simulator then it will run only selected iOS5/iOS6 simulator in client project.
if i have created framework build using iOS5 simulator and if i run that framework in client project and i used iOS6 simulator it gives Undefined symbols for architecture x86_64.
I need shell script which support both architecture i386 and x86_64 means my framework should be executable for all device and all simulator in client project.
Any insights into this would be really helpful.
Create aggregate target and inside its Build Phases -> Run script write script to:
Build 2 separate frameworks:
1. Framework with architectures for mobile devices (armv7, arm64, etc.)
2. Framework with architectures for simulator (i386 and x86_64).
For example:
xcodebuild -workspace MyApp.xcworkspace -scheme MyFrameworkScheme -arch i386 -arch x86_64 ONLY_ACTIVE_ARCH=NO -sdk iphonesimulator -configuration ${CONFIGURATION} clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphonesimulator BUILD_DIR=${BUILD_DIR}
xcodebuild -workspace MyApp.xcworkspace -scheme MyFrameworkScheme -arch armv7 -arch armv7s -arch arm64 ONLY_ACTIVE_ARCH=NO -sdk iphoneos -configuration ${CONFIGURATION} clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphoneos BUILD_DIR=${BUILD_DIR}
Then, use lipo to merge the libraries inside both frameworks to a fat library, and replace one of them inside the framework => you have a fat framework.

No architectures to compile for (ARCHS=i386, VALID_ARCHS=arm64 armv7 armv7s)

Preface: I did look at similar questions and none of the answers seemed to fix my problem.
I am trying to build my xcode (version 5.1.1) project using:
xcodebuild clean build -sdk iphonesimulator7.0 -arch "armv7s" ONLY_ACTIVE_ARCH=NO,
when I run this I get: No architectures to compile for (ARCHS=armv7s, VALID_ARCHS=i386 x86_64) as an error. I tried the above command with all of the VALID_ARCHS (rm64 armv7 armv7s) as inputs. So I then tried running this command:
xcodebuild clean build -sdk iphonesimulator7.0 -arch "i386" ONLY_ACTIVE_ARCH=NO
and I then get No architectures to compile for (ARCHS=i386, VALID_ARCHS=arm64 armv7 armv7s) as an error. I tried running the above command with all the other VALID_ARCHS (i386 x86_64) and no luck with that either. I don't know why these architecture errors are occurring. I have cocoapods in my project, and the first answer in the link above didn't fix my issue.
You can override your default variables:
Try to use this:
xcodebuild clean build -sdk iphonesimulator7.0 -arch "i386" ONLY_ACTIVE_ARCH=NO VALID_ARCHS="i386 x86_64"
If you building for Simulator - always build for i386/x86_64.
Go to your project settings (not targets). Then open Build Settings and add a value to Valid architectures: i386

How to update our static library architecture for suporting arm64 Build?

Few days ago i create static-library (Universal) that work's fine with Xcode5.0 SDK7. After Update Xcode5.1 with SDK7.1 that not work if i select simulator iPhone Retina(4-inch 64-bit). Then i am going to update my lib with Bellow setting change.
I do the same for three Target:-
For sporting simulator as well as device i put Universal lib and in to this i run script this:-
After this i Build Again lib and used as i done Before in to my project. But still getting same issue with iPhone Retina(4-inch 64-bit) Undefined symbols for architecture x86_64:
So, My question is that is there any additional change required for updating lib for arm64 or i did any mistake in above step. Please current me if i am wrong.
what change needed for update my static-library for supporting 64Bit architecture
NOTE:
I am asking for my own created Library Update. i am not using third-party Library.
Update
I used this lipo -info testingLibImport/libLibNSlog.a command in to my Terminal that output is:
Architectures in the fat file: testingLibImport/libLibNSlog.a are: armv7 armv7s i386 arm64
Another solution I found with XCode 6.4 is to add ONLY_ACTIVE_ARCH=NO and not specify the architecture. So
xcodebuild -target TargetName ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphonesimulator BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"
Will build i386 and x86_64 architectures in your library.
Here's my full universal lib run script to build all the architectures.
# define output folder environment variable
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# Step 1. Build Device and Simulator versions
xcodebuild -target TargetName ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"
xcodebuild -target TargetName ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphonesimulator 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}/"
I too ran into the same problem yesterday and after lot of googling and trying on different solutions, i gave up and tried on my own. All i could understand from the different solutions provided was that when i run "lipo -info library.a" it was not built for x86_64 architecture. So, decided to give up the aggregate approach and made a simple attempt.
as advised in this post, i added armv7, armv7s and arm64 to the architectures.
build the static library project with iphone simulator (32 bit)
build the static library project with iphone simulator (64 bit)
build the static library project with iOS device
go to the build path (under derived data)
copied both simulator and device output to a common folder
used lipo command in terminal window to create the universal library
lipo command: lipo -create -output newlibraryname.a simulatorlibraryname.a devicelibraryname.a
integrated the newly created universal static library and it WORKED!!!
After lots of stuff i got solution. some of xcode dont know there is automatic appear Standard architectures (including 64-bit) (armv7,armv7s,arm64) but in my case there is not option into my Static Library Project. so i am going to add this Manually like:-
and select this Option:-
After this i re-Build My static Library and used in to in my project that working fine now. and I also checked with lipo command in to terminal that output going to different now:-
testingLibImport/libLibNSlog.a are: armv7 armv7s i386 x86_64 arm64
Sorry for posting another solution so late. I had found this solution long time back when i was trying to find a solution that would save me from the manual work of creating a universal library using lipo command every time i had to build the universal library.
So, here is the another approach, for those using aggregate approach to build the universal library
just make one small change as mentioned below in your aggregate script for simulator to build the universal library -
xcodebuild -target ProductName -configuration ${CONFIGURATION} -sdk iphonesimulator ARCHS="i386 x86_64" BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" SYMROOT="${SYMROOT}"
Please observe the inclusion of multiple architectures instead of using single architecture approach -
xcodebuild -target ProductName -configuration ${CONFIGURATION} -sdk iphonesimulator -arch i386 BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" SYMROOT="${SYMROOT}"
Just ARCHS="i386 x86_64" will do the magic for you.
You can confirm this by using the following lipo command
lipo -info newLibraryName.a
Hope this saves time for many others like me!!!

xcodebuild test command for using with jenkins doesn´t work

I am having one problem that is killing me. Here it is: I have and app project in xCode that goes perfect when I tried to do everything in xCode UI. Which that I mean build, run, test or whatever in all the different targets that I have (3), 2 of the App and one for the tests.
THe problem comes when I tried to install a continous integration to my system in Jenkins. I need to execute some commands in shell for it. Command like this one:
xcodebuild -project MYPROJECT -sdk iphonesimulator -scheme TESTS_SCHEME TEST_AFTER_BUILD=YES
I also have tried with this other one that in the end it does the same:
xcodebuild -project MY_PROJECT -target TEST_TARGET -sdk iphonesimulator -configuration "Debug"
Then is when the problems cames out, the terminal says the following:
....PrecompiledHeaders/MYLIBRARY-Prefix-hhjuztynfruquodlgqxroyfibfkh/MYLIBRARY-Prefix.pch.d
clang: error: invalid architecture 'arm' for deployment target '-mios-simulator-version-min=4.3'
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang failed with exit code 1
** BUILD FAILED **
The following build commands failed:
ProcessPCH /Users/nicoyuste/Library/Developer/Xcode/DerivedData/MY_APP-bxpgsdbefuawmiexyikbtvsatlsf/Build/Intermediates/PrecompiledHeaders/MYLIBRARY-Prefix-hhjuztynfruquodlgqxroyfibfkh/MYLIBRARY-Prefix.pch.pth MYLIBRARY-Prefix.pch normal armv7 objective-c com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)
I´ve been looking in the Internet (almost in here) but everything what I found with same problem didn´t work for me. The xCode version is 4.5 and if you do xcodebuild -version is what I get so that´s fine.
I also have tried changing headers files and everything what I have found around but nothing fixes my problem...
any suggestions...
If you're using a custom build script, you can pass -arch i386 to xcodebuild
For instance:
xcodebuild -project MY_PROJECT -target TEST_TARGET -sdk iphonesimulator -configuration "Debug" -arch i386
(Scroll all the way to the right in the code sample above. The relevant flag is -arch i386)
Should force it to build against i386. However, you need to make sure i386 is in your VALID_ARCHS settings for the target.
In case anyone running into the same annoying problem again, I will share my script here:
Remember to run this command under the directory that has the xcodeproj file.
xcodebuild \
-project "full-path-to-your-xcodeproj-file" \
-target YOUR_TARGET \
-sdk iphonesimulator6.1 \
-arch i386 \
-configuration Debug \
VALID_ARCHS="armv6 armv7 i386" \
ONLY_ACTIVE_ARCH=NO \
TARGETED_DEVICE_FAMILY="1" \
clean install
I modified the TARGETED_DEVICE_FAMILY because I only build for iPhone. If you want to build for both iPhone and iPad, delete this line or replace with TARGETED_DEVICE_FAMILY="1, 2".
I am seeing people who is still wondering about this. I posted this question a long time ago. I stopped using xcodebuild and I am using xctool now, it works much better. This tool is developed by Facebook.
I think that the problem reside in that your are building for the simulator specifying arm as the architecture, try changing it to i386
I ran into a similar problem after upgrading to Xcode 4.5 on my build machine. In my case, I have a third-party library that can't be built for armv7s (yet) and so, I set the Architectures build setting to armv7. Worked fine for unit tests, simulator builds, and the like inside of Xcode. However, when I did the command-line build, it failed with the same message.
I changed my Architectures to armv7 i386 and now it seems to build fine at the command line for the simulator.
Despite the GUI indicating that Architectures of Standard (armv7,armv7s) includes just those two, I'm pretty sure there's an i386 hiding there when you build for the simulator.
In the end, that setting works fine now with Jenkins.
I tried below command:
xcodebuild -arch i386 -sdk iphonesimulator7.1
But failed with similar error as clang: error: invalid architecture 'arm' for deployment target '-mios-simulator-version-min=6.0'
Here is how I solved :
xcodebuild -arch i386 VALID_ARCHS="i386 armv7 armv7s" ONLY_ACTIVE_ARCH=NO -sdk iphonesimulator7.1
U need to make u set VALID_ARCHS and ONLY_ACTIVE_ARCH correctly and it will work. You can make these settings on Xcode directly too.

Resources