iOS Static Framework with Resources Inside

IOS Static Framework with resources inside

Short answer: you can't.

When you compile the app, the bundle is generated with the resources of the "main" project, ignoring the resources in linked frameworks. This includes images, xib's, plist's, etc. (anything that isn't a source file)

What you need to do is add those resources to your main project so that they are available for use inside your application, not the happiest way around it but it'll work.

How to compile resource files into a custom framework or static library or Mach-O file?

Assuming by "resource files" you mean arbitrary binary files, you can include them into any binary by creating an assembly file (e.g. resources.S) like so:

.section __RESOURCE,__file1
_symbol_file1:
.incbin "file1.zip"
.no_dead_strip _symbol_file1

.section __WHATEVER,__file2
_symbol_file2:
.incbin "file2.bin"
.no_dead_strip _symbol_file2

// etc, you get the pattern

If you don't have a project in which you can include this file already, then you can turn it into an iOS arm64 framework by itself like so:

mkdir MyResources.framework
xcrun -sdk iphoneos clang -arch arm64 -shared -o MyResources.framework/MyResources resources.S

Why do we have this confusing setup about Static Library and Framework in Xcode

There are many concepts that must be clear

Libraries have two categories based on how they are linked to the executable file

  1. Static library .a, .so. link at compile time. wiki
  2. Dynamic libraries .dylib .dll etc. link at runtime. only apple can use it for iOS for some safe reason, we cannot build this.

ps, a special kind in apple platform

Text Based .dylib stubs — .tbd

Framework

Framework is a package that can contain resources such as dynamic libraries, strings, headers, images, storyboards etc.
vs Libraries, Framework has more features

Framework also has static and dynamic

iOS 8 later, we can use a dynamic framework, why Apple releases this. maybe Extension and App share code
this Dynamic Framework for iOS is named embedded frameworks, because when we build the app copy the framework in app bundle.
so the embedded framework is different from system dynamic Frameworks like UIKit.Framework

Why there's no "Dynamic Library" option?

the embedded library is allowed with the Framework option, but dynamic framework shared in muti app is also not allowed

Given that we can already link framework statically, why do we still need a "Static Library"? (isn't StaticFramework = StaticLibrary + Bundle? )

well, Xcode not only support Objective-c and Swift, but also support C, C++ which may use the static library



Related Topics



Leave a reply



Submit