Skip to content

Native Libraries

Alexandr Esilevich edited this page Apr 1, 2024 · 21 revisions

This article describes how to use native prebuilt libraries with the Swift toolchain for Android. An example of such a library is the sqlite3 library, which is required for using the GRDB.swift and SQLite.swift libraries.

There are two ways to define and use native libraries in SPM manifest:

  1. Define a binary target using the .binaryTarget method
  2. Define a system library target using the .systemLibrary method

The scd build tool from the Swift toolchain for Android supports both methods and automatically embeds all required dynamic libraries into the resulting Android archive. However, using the .systemLibrary method requires passing additional include and library paths to the scd build tool.

Binary targets

The binary target is the preferred method for using prebuilt libraries with the Swift toolchain for Android because it does not require passing additional flags to the scd build tool. This method should be used when developing a new SPM package intended for use on Android.

The .binaryTarget method in the SPM manifest defines a new binary target, which references either a local XCFramework or a remote archive containing an XCFramework. The Swift toolchain for Android and the scd build tool both support Android platforms within XCFrameworks.

Creating XCFramework for Android

Adding XCFramework in SPM project

System libraries

Clone this wiki locally