Skip to content

Latest commit

 

History

History
82 lines (60 loc) · 2.86 KB

README.md

File metadata and controls

82 lines (60 loc) · 2.86 KB

This plugin integrates Swift Android Toolchain to Gradle

Pre-requirements

This plugin require Android NDK r15c and Swift Android Toolchain

Plugin lookup NDK and toolchain by environment variables ANDROID_NDK_HOME and SWIFT_ANDROID_HOME or local.properties in 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 {
        jcenter()
    }
    dependencies {
        classpath 'com.readdle.android.swift:gradle:1.1.5'
    }
}
  1. Add the following to your project build.gradle
apply plugin: 'com.readdle.android.swift'
  1. Optionally you can add some extra configuration to your project build.gradle. For example:
swift {
    // helpers to forward flags from Swift Package Manager to Swift Compiler Frontend
    def passToFrontend = ["-Xswiftc", "-Xfrontend", "-Xswiftc"]
    def disableObjcAttr = passToFrontend + "-experimental-disable-objc-attr"
    
    // 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"
        // Disable @objc and dynamic
        extraBuildFlags disableObjcAttr
    }
    
    // Custom swift flags for release build
    release {
        // enable symbols in relase mode
        extraBuildFlags "-Xswiftc", "-g"
        // Disable @objc and dynamic
        extraBuildFlags disableObjcAttr
    }
}

Usage

In simple cases you can just run ./gradlew assembleDebug and everything will work. If your use swift package manager dependencies with external build process you should firstly invoke ./gradlew swiftInstallDebug

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 android app.