This plugin integrates Swift for Android builds using swiftly and Swift Android SDK.
This plugin requires swiftly and a Swift Android SDK installed.
- Install swiftly and Swift 6.2+:
curl -L https://swiftlang.github.io/swiftly/swiftly-install.sh | bash
swiftly install 6.2- Install the Swift Android SDK:
swift sdk install <path-to-sdk.artifactbundle>Plugin builds Swift code using SwiftPM so you should define your code inside SwiftPM modules. Root module should be located inside app/src/main/swift. See sample.
- Add the following to your root build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.readdle.android.swift:gradle:6.2'
}
}- Add the following to your project build.gradle
apply plugin: 'com.readdle.android.swift'- Configure build types and architecture
buildTypes {
release {
debuggable false
// Build Swift in release mode
jniDebuggable false
// all 3 architectures: arm64-v8a, armeabi-v7a, x86_64
}
debug {
debuggable true
// Build Swift in debug mode
jniDebuggable true
// limit architectures for faster builds
ndk {
abiFilters = ["arm64-v8a"]
}
}
}- Optionally you can add some extra configuration to your project build.gradle. For example:
swift {
// Enables swift clean when ./gradlew clean invoked. Default true
cleanEnabled false
// Android API level. Default 29
apiLevel 31
// Path to swiftly executable. Default: ~/.swiftly/bin/swiftly
swiftlyPath "/custom/path/to/swiftly"
// Swift version to use with swiftly. Default: "6.2"
swiftlyVersion "6.2"
// Path to Swift Android SDK. Default: ~/Library/org.swift.swiftpm/swift-sdks/readdle-swift-6.2.1-RELEASE_android.artifactbundle
swiftSdkPath "/custom/path/to/sdk.artifactbundle"
// Custom swift flags for debug build
debug {
// Set custom preprocessor flags
extraBuildFlags "-Xswiftc", "-DDEBUG"
}
// Custom swift flags for release build
release {
// enable symbols in release mode
extraBuildFlags "-Xswiftc", "-g"
}
}arm64-v8a(aarch64)armeabi-v7a(armv7)x86_64
In simple cases you can just run ./gradlew assembleDebug and everything will work.
| Gradle | SwiftPM |
|---|---|
./gradlew swiftClean |
swift package clean |
./gradlew swiftBuildDebug |
swift build |
./gradlew swiftBuildRelease |
swift build --configuration release |
See sample app.