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 Android Toolchain to Gradle

Pre-requirements

This plugin requires Android NDK and the Swift Android Toolchain. Follow the installation guide to set them up.

The plugin looks up the NDK and toolchain using the environment variables ANDROID_NDK_HOME and SWIFT_ANDROID_HOME, or by reading local.properties in the project root:

ndk.dir=/path/to/ndk
swift-android.dir=/path/to/toolchain

Setup

Plugin build swift code using SwiftPM so you should define you 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.0.3'
    }
}
  1. Add the following to your project build.gradle
apply plugin: 'com.readdle.android.swift'
  1. Configure build types and arhitecture
buildTypes {
    release {
        debuggable false
        // Build Swift in release mode
        jniDebuggable false
        // all 4 arhitectures
    }
    debug {
        debuggable true
        // Build Swift in debug mode
        jniDebuggable true
        // only 2 arhitectures
        ndk {
            abiFilters = ["arm64-v8a", "x86_64"]
        }
    }
}
  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 
    
    // Custom swift flags for debug build
    debug {
        // Set custom preprocessor flags
        extraBuildFlags "-Xswiftc", "-DDEBUG"
    }
    
    // Custom swift flags for release build
    release {
        // enable symbols in relase mode
        extraBuildFlags "-Xswiftc", "-g"
    }
}

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
./gradlew swiftPackageUpdate swift package update

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%