Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/flowkey/swift-android-toolchain
Build Swift for Android from your Mac
https://github.com/flowkey/swift-android-toolchain
Last synced: 2 months ago
JSON representation
Build Swift for Android from your Mac
- Host: GitHub
- URL: https://github.com/flowkey/swift-android-toolchain
- Owner: flowkey
- Created: 2018-01-16T17:21:02.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-09-15T18:15:12.000Z (over 1 year ago)
- Last Synced: 2024-07-05T13:23:49.708Z (6 months ago)
- Language: Shell
- Homepage:
- Size: 50.5 MB
- Stars: 49
- Watchers: 19
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: licenses/CLANG
Awesome Lists containing this project
README
# swift-android-toolchain
Build Swift for Android from Mac
## Installation
### For use within a specific project
1. Add `swift-android-toolchain` as a git submodule
2. Use `./path-to-submodule/swift-build.sh` wherever needed[UIKit-cross-platform](https://github.com/flowkey/UIKit-cross-platform) uses this method (along with the Android Studio integration, below).
### For use globally from the command line
1. Clone the repo
1. Add the cloned destination to your `PATH` environment variable (e.g. in `~/.bash_profile` or equivalent)## Usage
### In Android Studio / Gradle
You probably want Gradle to compile your native sources automatically when building the android app. In order to achieve this, you have to create another `CMakeLists.txt` file and reference it from `app/build.gradle`.
```Gradle
externalNativeBuild {
cmake {
version "3.16.2"
path "CMakeLists.txt" // android/app/src/CMakeLists.txt
}
}
```In `android/app/src/CMakeLists.txt`, add the following code after the `cmake_minimum_required(VERSION x.y.z)` declaration.
```CMake
# destination of project level CMakeLists.txt for building native sources
get_filename_component(PROJECT_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/../../ ABSOLUTE)# path to swift-android-toolchain
set(BuildSwiftProject_DIR ../../swift-android-toolchain)
find_package(BuildSwiftProject REQUIRED)build_swift_project(
PROJECT_DIRECTORY ${PROJECT_DIRECTORY}
)
```Check out [getting-started](https://github.com/flowkey/UIKit-cross-platform/tree/master/samples/getting-started) for a working example.
### From the command line
```bash
ANDROID_ABI="armeabi-v7a" CMAKE_BUILD_TYPE="Debug" swift-build.sh
```#### MacOS file permissions
Since we use downloaded versions of the swift toolchain and Android NDK in this build, MacOS complains about potential security issues. Running the build might show you alerts for every binary that is invoked by the build script, asking to manually grant permissions.
Running the [`fixMacOSPermissions.sh`](fixMacOSPermissions.sh) script, after setup, but before invoking the build, should resolve this issue.
## Credits
Making this toolchain was only possible by standing on the shoulders of giants.
Many thanks to [Vlad Gorlov](https://github.com/vgorloff) for his great work with the [swift-everywhere-toolchain](https://github.com/vgorloff/swift-everywhere-toolchain), [Gonzalo Lorralde](https://github.com/gonzalolarralde) for [swifty-robot-environment](https://github.com/gonzalolarralde/swifty-robot-environment) and [John Holdsworth](https://github.com/johnno1962) for his [android_toolchain](https://github.com/SwiftJava/android_toolchain). And to the Swift community as a whole for their ongoing work at making the language great.