Skip to content

Gradle plugin for building Swift code for Android

License

Notifications You must be signed in to change notification settings

readdle/swift-android-gradle

 
 

Repository files navigation

Swift Android Gradle plugin Maven Central

This plugin integrates Swift for Android builds using swiftly and Swift Android SDK.

Pre-requirements

This plugin requires swiftly and a Swift Android SDK installed.

  1. Install swiftly and Swift 6.2+:
curl -L https://swiftlang.github.io/swiftly/swiftly-install.sh | bash
swiftly install 6.2
  1. Install the Swift Android SDK:
swift sdk install <path-to-sdk.artifactbundle>

Setup

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.

Adding plugin to gradle scripts

  1. Add the following to your root build.gradle
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.readdle.android.swift:gradle:6.2'
    }
}
  1. Add the following to your project build.gradle
apply plugin: 'com.readdle.android.swift'
  1. 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"]
        }
    }
}
  1. 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"
    }
}

Supported Architectures

  • arm64-v8a (aarch64)
  • armeabi-v7a (armv7)
  • x86_64

Usage

In simple cases you can just run ./gradlew assembleDebug and everything will work.

Other SwiftPM to gradle mapping:

Gradle SwiftPM
./gradlew swiftClean swift package clean
./gradlew swiftBuildDebug swift build
./gradlew swiftBuildRelease swift build --configuration release

Sample

See sample app.

About

Gradle plugin for building Swift code for Android

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Groovy 100.0%