ios静态库依赖其他静态库_如何使用XCFramework构建通用的iOS静态库

ios静态库依赖其他静态库

模块化iOS (Modular iOS)

Compiled static libraries are not easy to integrate with. A build only supports iOS simulators or devices but not both. To allow integrators use the static library for simulators and devices you must provide separate builds for each target destination. Integrators will need to switch to the correct build variant based on the target destination.

编译后的静态库不易于集成。 构建仅支持iOS模拟器或设备,但不同时支持两者。 要允许集成商将静态库用于模拟器和设备,必须为每个目标位置提供单独的构建。 集成商将需要根据目标目的地切换到正确的构建版本。

Furthermore an integrator also needs to configure their app’s build setting to consume the static library. At the very least an integrator need to tell Xcode where the public interface of the static library is located. That is how Xcode knows what code is consumable from the static library.

此外,集成商还需要配置其应用程序的构建设置以使用静态库。 至少集成商需要告诉Xcode静态库的公共接口在哪里。 这就是Xcode从静态库中知道可使用哪些代码的方式。

Static libraries public interfaces (.swiftmodule directory) are distributed separately from the static library (.a file).

静态库公共接口( .swiftmodule目录)与静态库( .a文件)分开分发。

Icons provided by icons8.com icons8.com提供的图标

So the integration experience with static libraries is cumbersome. But is there a way to distribute a single artefact which supports simulators and devices? There are 2 ways:

因此,与静态库的集成经验非常繁琐。 但是,是否有一种方法可以分发支持仿真器和设备的单个工件? 有两种方法:

  1. Compiled static frameworks

    编译的静态框架

  2. Using XCFrameworks

    使用XCFrameworks

The first is hacky method (not supported by Apple) to distribute static libraries that look like frameworks and suuport both iOS devices and simulators. The second is using a new format that supports hosting both build variants in a single artefact and supported by Apple. In this post we’ll be focusing on the latter.

第一种是hacky方法(Apple不支持),用于分发看起来像框架的静态库并支持iOS设备和模拟器。 第二种是使用一种新格式,该格式支持在单个工件中托管两个构建变体,并由Apple支持。 在本文中,我们将重点讨论后者。

In this post I will first cover what XCFramework is and why use them. Then I will show you how to build a universal iOS static library in an XCFramework form. Finally I will show you how to consume the XCFramework.

在本文中,我将首先介绍XCFramework是什么以及为什么使用它们。 然后,我将向您展示如何以XCFramework表单构建通用的iOS静态库。 最后,我将向您展示如何使用XCFramework。

I assume you are already familiar with static libraries, compiled static libraries, basic iOS and Swift.

我假设您已经熟悉静态库 , 编译的静态库 ,基本的iOS和Swift。

什么是XCFramework? (What is XCFramework?)

XCFramework is a structured directory that can contain multiple build variants of the same module — static library or dynamic framework. At least it needs to contain one build variant.

XCFramework是一个结构化目录,可以包含同一模块的多个构建变体-静态库或动态框架。 至少它需要包含一个构建变体。

A build variant is a module transformed from source code (Swift, Objective-C, etc…) into computer instructions or binary for a specific platform and CPU architecture.

构建变体是一个模块,可从源代码(Swift,Objective-C等)转换为针对特定平台和CPU体系结构的计算机指令或二进制代码

For example iOS can run in simulators on macs which speak in a language (

你可能感兴趣的:(ios,java)