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

青春壹個敷衍的年華 提交于 2019-11-28 17:36:27

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.

  1. as advised in this post, i added armv7, armv7s and arm64 to the architectures.
  2. build the static library project with iphone simulator (32 bit)
  3. build the static library project with iphone simulator (64 bit)
  4. build the static library project with iOS device
  5. go to the build path (under derived data)
  6. copied both simulator and device output to a common folder
  7. 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!!!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!