Xcode 6 making dynamic and static framework

Source: Internet
Author: User

Http://www.cocoachina.com/ios/20141126/10322.htmlXcode 6 making dynamic and static framework2014-11-26 10:21 Edit: suiling Category: iOS development Source: years.im 135082

Xcode 6 static Framework dynamic FRAMEWOR

Recruitment information:
    • Youku Video Android/web Development Engineer, web Interaction Design Engineer
    • Beijing | Baidu | iOS Development ¥20,000-35,000

Did you write the SDK or do you want to make some common tool classes into the framework experience? You may have written your own script to complete the work, I believe there are a lot of people using ios-universal-framework, with the release of Xcode 6, I believe that the small partners have already known, Xcode 6 support to do the Framework. At the same time, ios-universal-framework developers also announced that the development of this project is not continued, it is recommended that developers use Xcode 6 production, there are many online production of iOS framework, but most of them are not detailed, The next step is to make a detailed introduction to the iOS Framework under Xcode 6.

On the concept of static and dynamic libraries, there are many online materials, there is no narrative here, only to explain the production process.

Create an iOS dynamic library

Create a new project and select the default target for the cocoa Touch Framework:

Do coding work, here I simply wrote a Utils class, and wrote a log method

Set up open header files: Some classes in the framework may be private helpers that need not be seen by the user, where only the open classes are placed under public.

The headers directory of the generated framework can only see the header files of public

Once the encoding is complete, the direct run will be able to successfully generate the framework file, select Xcode->window->organizer->projects->your Project and open the project's derived Data directory, so you can find the generated framework file,

Create a new test project, using the generated framework

Import a framework file into a test project, calling code in the framework

12 MyUtils *utils = [MyUtils new]; [utils log:@"didFinishLaunchingWithOptions"];

Run error (reason:image not Found)

Why is that? Because we are doing a dynamic library, we need to add one more step when we use it, and we want the framework to be added to the ' Embedded Binaries ' at the same time.

Note: There is no such option before Xcode 6 (I did not see it), so theoretically Xcode 5 and previous versions cannot use the framework dynamic Library generated under Xcode 6.

Here, assuming that your entire process is done using the simulator, it will look smooth. This is the time to try to deploy the test project to the real machine.

Ld:warning:ignoring file/work/ios/myframeworktest/myframeworktest/myframework.framework/myframework, File was Built for x86_64 which are not the architecture being linked (ARMV7):/work/ios/myframeworktest/myframeworktest/myframewor K.framework/myframework

Undefined Symbols for Architecture armv7:

"_objc_class_$_myutils", referenced from:

Objc-class-ref in APPDELEGATE.O

Ld:symbol (s) not found for architecture armv7

Clang:error:linker command failed with exit code 1 (use-v to see invocation)

Why is that? The error is already obvious, because when we make the dynamic library, the selected device is the simulator, if the choice of the real machine, then the generated library can only be used on the real machine, then how do we make a generic dynamic library? The simple way is to generate the emulator and the real machine run the library, and then in the merger, this method, each time the dynamic library generated, the process will be very cumbersome, the following we use a script to complete it automatically.

Making a common dynamic library

New Aggregate Target

Add a script to the new target

1234567891011121314151617181920212223242526 # Sets the target folders and the final framework product.# 如果工程名称和Framework的Target名称不一样的话,要自定义FMKNAME# 例如: FMK_NAME = "MyFramework"FMK_NAME=${PROJECT_NAME}# Install dir will be the final output to the framework.# The following line create it in the root folder of the current project.INSTALL_DIR=${SRCROOT}/Products/${FMK_NAME}.framework# Working dir will be deleted after the framework creation.WRK_DIR=buildDEVICE_DIR=${WRK_DIR}/Release-iphoneos/${FMK_NAME}.frameworkSIMULATOR_DIR=${WRK_DIR}/Release-iphonesimulator/${FMK_NAME}.framework# -configuration ${CONFIGURATION}# Clean and Building both architectures.xcodebuild -configuration "Release"-target "${FMK_NAME}"-sdk iphoneos clean buildxcodebuild -configuration "Release"-target "${FMK_NAME}"-sdk iphonesimulator clean build# Cleaning the oldest.if[ -d "${INSTALL_DIR}"]thenrm -rf "${INSTALL_DIR}"fimkdir -p "${INSTALL_DIR}"cp -R "${DEVICE_DIR}/""${INSTALL_DIR}/"# Uses the Lipo Tool to merge both binary files (i386 + armv6/armv7) into one Universal final product.lipo -create "${DEVICE_DIR}/${FMK_NAME}""${SIMULATOR_DIR}/${FMK_NAME}"-output "${INSTALL_DIR}/${FMK_NAME}"rm -r "${WRK_DIR}"open "${INSTALL_DIR}"

Select the newly created Target,run and automatically eject the resulting framework file if there is no exception

This generates a dynamic library that can support both the simulator and the real machine.

Make a generic static library under Xcode 6

As we mentioned above, this generated dynamic library is probably difficult to use on Xcode 5, then why do we have to use the dynamic library, generally not with the static library? So easy! only needs to modify one parameter to generate a static library.

With a static library, you can remove the framework from ' Embedded Binaries '. The pro-test is available under Xcode 5. Import the newly generated library into the test project, try running on the simulator and the real machine, all OK.

Unfortunately, if you use the real machine is IPhone5 C, the tragedy will also be sent, the resulting framework does not support armv7s, I do not know is Xcode 6 bug, or because Apple believes that the use of armv7s devices too little, can not support. Xcode new project, the default architectures unexpectedly does not contain armv7s.

The libraries you want to build support armv7s, add armv7s to architectures, regenerate the framework

Determine which schemas are supported by a framework

How do we verify which platforms are supported by the generated framework? Of course not. The following command is a comparison of the framework generated before and after the armv7s

1234 Yearsdembp:Products Years$ lipo -info ./MyFramework.framework/MyFramework Architectures inthe fat file: ./MyFramework.framework/MyFramework are: i386 x86_64 armv7 arm64 Yearsdembp:Products Years$ lipo -info ./MyFramework.framework/MyFramework Architectures inthe fat file: ./MyFramework.framework/MyFramework are: armv7 armv7s i386 x86_64 arm64

Xcode 6 making dynamic and static framework

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.