Giter Club home page Giter Club logo

swift-android-gradle's Introduction

Swift Android Gradle plugin Maven Central

This plugin integrates Swift Android Toolchain to Gradle

Pre-requirements

This plugin require Android NDK r21e 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 {
        mavenCentral()
    }
    dependencies {
        classpath 'com.readdle.android.swift:gradle:1.4.0'
    }
}
  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 {
    // 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.

swift-android-gradle's People

Contributors

andriydruk avatar johnno1962 avatar ybiletskyi avatar zayass avatar zedorff avatar zhuowei avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.