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.
Apply the plugin
Section titled “Apply the plugin”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"}Configure the Swift package
Section titled “Configure the Swift package”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.
Build variants
Section titled “Build variants”The plugin registers one task per Android build variant:
| Variant | Task |
|---|---|
| debug | assembleDebugSwiftPackage |
| release | assembleReleaseSwiftPackage |
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:
./gradlew assembleDebugSwiftPackage./gradlew assembleReleaseSwiftPackageSDK and NDK paths
Section titled “SDK and NDK paths”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" )}Device ABI detection
Section titled “Device ABI detection”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.
Custom toolchain
Section titled “Custom toolchain”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") ) )}Android ViewModel generation
Section titled “Android ViewModel generation”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.
Java version
Section titled “Java version”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}