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.

Using .binaryTarget

The .binaryTarget is the preferred method to use prebuilt libraries with the Swift toolchain for Android because it does not require to pass additional flags to the scd build tool. This method should be used when you develop a new SPM package which will be used on Android. The .binaryTarget directive

Using .systemLibrary

Clone this wiki locally