A pit created by iOS Framework reason:image not found dyld:library not loaded:

Source: Internet
Author: User

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.

...

For details, please see

Http://www.cocoachina.com/ios/20141126/10322.html





To prevent the connection from failing, I'll just copy the text.


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 an introduction to the iOS Framework under Xcode 6. For the concept of static and dynamic libraries, there is a lot of information online, there is no narrative, only to explain the production process. Create an iOS dynamic library new project and select default target for Cocoa Touch Framework: 11.png do coding work, here I simply write a utils class, and write a log method 12.png set open header file: Some of the classes in the framework may be private auxiliary tools that do not need to be seen by the user, where only the open classes need to be placed under public, 13. PNG This generated framework of the headers directory can only see the public header file 14.png encoding is complete, the direct run will be able to successfully generate the framework file, select Xcode->window-> Organizer->projects->your Project, open the project's derived data directory so you can find the resulting framework file, 15. Png16.png new test project, use the generated framework to import the framework file into the test project, call the code in the framework 12MyUtils *utils = [Myutils new]; [Utils log:@ "didfinishlaunchingwithoptions"]; Operation error (Reason:image not Found) 18.png why would that be? Because we are doing a dynamic library, we need to add a step in the use of the framework at the same time to the "Embedded Binaries" 19.png Note: There is no such option before Xcode 6 (I did not find), so theoretically xcode The framework dynamic Library generated under Xcode 6 cannot be used in versions 5 and earlier. Come here and assume that your wholeThe process is done using the simulator, and that looks pretty smooth. This is the time to try to deploy the test project to the real machine, the problem is 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/myfra meworktest/myframework.framework/myframeworkundefined Symbols for Architecture armv7: "_objc_class_$_myutils", Referenced from:objc-class-ref in AppDelegate.old:symbol (s) not found for Architecture Armv7clang:error:linker Co Mmand failed with exit code 1 (use-v to see invocation) Why is this so? 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. Create a generic dynamic library new aggregate target20.png add script to the newly created target21.png1234567891011121314151617181920212223242526# sets the Target folders and the final framework product.# if the project name and the framework's target name are different, customize the fmkname# for example: Fmk_name = "Myframework" fmk_name=${project_name}# Install dir'll being the final output to the FRAmework.# the following line create it at the root folder of the current project. install_dir=${srcroot}/products/${fmk_name}.framework# working DIR would be a 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 new target, Run, if there is no exception, will be self-Moving out of the generated framework file 22.png This generated dynamic library can support both the simulator and the real machine. Xcode 6 to make a general static library above we also mentioned that this generated dynamic library is difficult to use in Xcode 5, then why do we have to use the dynamic library, generally not with the static library is good? So easy! only needs to modify one parameter to generate a static library. 23.png using 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 and try to run it on the emulator and the real machine, all OK. Unfortunately, if you use the real machine is IPhone5 C, the tragedy is to be sent, the resulting framework does not support armv7s, I do not know is Xcode 6 bug, Or because Apple thinks there are too few devices to use armv7s, it is not supported. Xcode new project, the default architectures unexpectedly does not contain armv7s.24.png want to build the library support armv7s, add armv7s to architectures, Regenerate the framework to 25.png determine which architectures a framework supports what do we do to 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 armv7s 1234yearsdembp: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:a Rmv7 armv7s i386 x86_64 arm64


A pit created by iOS Framework reason:image not found dyld:library not loaded:

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.