Skip to content

Android

The io.scade.gradle.plugins.android.swiftpm plugin extends the base plugin with Android-specific integration: per-variant task registration, automatic SDK/NDK path resolution, connected-device ABI detection, and Android ViewModel generation.

In build.gradle.kts, apply both the Android application plugin and the SPM Android plugin:

plugins {
id("com.android.application")
id("io.scade.gradle.plugins.android.swiftpm") version "1.4.5"
}
swiftpm {
path = file("../MySwiftPackage")
product = "MySwiftPackage"
platforms = listOf(
TargetPlatform.Android(
archs = listOf("arm64-v8a", "x86_64")
)
)
}

archs sets the Android ABIs to build for. Supported values: arm64-v8a, armeabi-v7a, x86_64, x86. If archs is empty, the plugin defaults to arm64-v8a and x86_64.

The plugin registers one task per Android build variant:

VariantTask
debugassembleDebugSwiftPackage
releaseassembleReleaseSwiftPackage

Each task builds the Swift package in the matching configuration (Debug / Release) and registers the native library output as a JNI libs folder for that variant, so it is packaged into the APK automatically.

Run a specific variant:

Terminal window
./gradlew assembleDebugSwiftPackage
./gradlew assembleReleaseSwiftPackage

The plugin reads the Android SDK and NDK paths from the Android Gradle Plugin automatically. No manual configuration is needed unless you want to override them via scdOptions:

swiftpm {
path = file("../MySwiftPackage")
product = "MySwiftPackage"
scdOptions = listOf(
"--android-sdk", "/path/to/sdk",
"--android-ndk", "/path/to/ndk"
)
}

In debug builds, the plugin checks for a connected Android device via ADB and, if found, builds only for that device’s ABI. This speeds up development builds when you are targeting a single device. If no device is connected or the ABI is not in the supported set, the plugin falls back to the archs list.

To use a specific Swift for Android toolchain instead of the one managed by scd:

swiftpm {
path = file("../MySwiftPackage")
product = "MySwiftPackage"
platforms = listOf(
TargetPlatform.Android(
archs = listOf("arm64-v8a"),
toolchain = file("/path/to/swift-android-toolchain")
)
)
}

For Swift types annotated with @Observable, the plugin automatically passes --generate-android-viewmodels to the bridging generator, producing ViewModel and ViewModelFactory subclasses with StateFlow properties for each observed property. No extra configuration is needed.

See Observable for details on the generated ViewModel API.

If your minSdk is below API 33, the plugin automatically sets javaVersion = 8 for the bridging generator. You can override this explicitly:

swiftpm {
path = file("../MySwiftPackage")
product = "MySwiftPackage"
javaVersion = 11
}