Xcode 6 creates dynamic and static universal frameworks (solving the problem that armv7s arm64 armv7 is not supported) and xcodearmv7s

Source: Internet
Author: User

Xcode 6 creates dynamic and static universal frameworks (solving the problem that armv7s arm64 armv7 is not supported) and xcodearmv7s

Have you ever written an SDK or want to make some common tool classes into the Framework? You may have completed this task by writing scripts on your own. I believe many people use iOS-Universal-Framework. With the release of Xcode 6, I believe all of you know it, xcode 6 supports the Framework. at the same time, iOS-Universal-Framework developers also announced that they are not continuing to develop this project. We recommend that developers use Xcode 6 for production. Currently, there are a lot of materials on the Internet for iOS Framework production, but most of them are not detailed enough. Next, this article will introduce how to create iOS Framework in Xcode 6.

There are a lot of online materials about the concepts of static and dynamic libraries. I will not describe them here, but I will only explain the production process.

Create an iOS dynamic library

Create a project and select Cocoa Touch Framework as the default Target ,:


For coding, here I simply wrote a Utils class and wrote a log method.


Set the open header file: some classes in the Framework may be private auxiliary tools. You do not need to see them. Here, you only need to put the open classes under Public,


In this way, only the Public header file can be seen in the Headers directory of the generated Framework.


After coding, Run the code to generate the Framework file. Select xCode> Window> Organizer> Projects> Your Project to open the Derived Data directory of the Project, in this way, you can find the generated Framework file,



Create a test project and use the generated Framework

Import the Framework file to the test project and call the code in the Framework.


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

Running error (Reason: Image Not Found)


Why? Because we are working on a dynamic library, we need to add an additional step when using it. We need to add the Framework to 'embedded binaries' at the same time.


Note: This option was not available before XCode 6 (I did not find it), so in theory XCode 5 and earlier versions cannot use the Framework dynamic library generated under Xcode 6.

Here, assuming that you are using a simulator throughout the process, it looks very smooth. At this time, I tried to deploy the test project on the real machine.

Ld: warning: ignoring file/work/ios/MyFrameworkTest/MyFramework. framework/MyFramework, file was built for x86_64 which is not the architecture being linked (armv7):/work/ios/MyFrameworkTest/MyFramework. 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? The error message is obvious, because when we create a dynamic library, the selected device is a simulator. If we select a real machine, the generated library can only be used on the real machine, how can we create a universal dynamic library? The simple method is to generate the libraries run on the simulator and the real machine separately, and then merge them. This method is cumbersome every time a dynamic library is generated, next we will use a script to automatically complete it.

Create a universal dynamic library

Create Aggregate Target


Add a script to the new Target


# Sets the target folders and the final framework product. # If the project name is different from the Target name of the Framework, you need to customize FMKNAME # For example: 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 ubuntures. xcodebuild-configuration "Release"-target "$ {FMK_NAME}"-sdk iphoneos clean buildxcodebuild-configuration "Release"-target "$ {FMK_NAME}"-sdk iphonesimulator clean build # Cleaning 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 and Run. If no exception exists, the generated Framework file is automatically displayed.


In this way, the dynamic library can support both simulators and real machines.

Create a general static library under Xcode 6

As we mentioned above, it is difficult to use the dynamic library generated in Xcode 5. Why do we have to use a dynamic library? Generally, it is better not to use a static library? So Easy! You only need to modify a parameter to generate a static library.



With the static library, you can delete the Framework from 'embedded binaries'. It is available in Xcode 5. Import the new library to the test project, and try running it on the simulator and real machine. Everything is OK.

Unfortunately, if the real machine you use is iPhone5 C, the tragedy will become again. The generated Framework does not support armv7s. I don't know if it is a bug in Xcode 6, because Apple thinks there are too few devices using armv7s, which is not supported. create a project in Xcode. The default ubuntures does not contain armv7s.



To generate a library that supports armv7s, add armv7s to ubuntures and regenerate the Framework.


Determine the architectures supported by a Framework

How can we verify the platforms supported by the generated Framework? Can't we test them one by one? Of course not. The following command is used to compare the framework generated before and after armv7s.

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


Related Article

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.