Comments (6)
Currently @ephemer is working on https://github.com/SwiftAndroid/swift-jni, which allows access to Java JNI. Then, one can write wrapper functions that convert JNI arguments to/from native Swift datatypes, and use them as native methods from Java. A very simple proof of concept can be found at https://github.com/SwiftAndroid/swift-android-samples/blob/master/swifthello/src/main/swift/Sources/main.swift
I would suggest that you also look at other projects for Swift on Android if you don't need full compatibility with the reference toolchain, such as the (more mature) RemObjects Silver.
from swift.
The problem is that I do need compatibility with the reference toolchain. I'll take a look at the other projects; thanks for the info!
from swift.
What do you mean exactly by compatibility?
@zhuowei has made a gradle plugin that will compile your swift code alongside other native code. Personally I've just used swiftc-android to build shared libraries which can be loaded / linked against by any other native come you compile (regardless of toolchain)
Either way you'll very likely have to deal with the JNI/NDK, unless you use RemObjects Silver or the like (which may or may not have its own issues- I don't know how it works under the hood, I did read some question marks re: Arrays being passed by reference rather than by value, but I suspect the actual issues there will be more along the lines of interfacing with other native / Java code down the line)
from swift.
@ephemer @zhuowei So if I have a pure Swift project, understandably I would end up dealing with the JNI or NDK (which is C++, so how is Swift doing that?). Is there a way for me to expose all the library functions/classes/structs to the Java side of things and call them directly?
from swift.
@avaidyam, you expose certain top-level (non-class) functions to Java, currently using some undocumented (but very easy to use) compiler features. In a nutshell, that is what the JNI does.
Maybe I'm missing something but from what I can see the JNI and NDK have C (in addition to C++) APIs, which is no problem for Swift. What I've done is wrap those C APIs to make them look closer to their C++ equivalents and more idiomatically "Swift-like" in their usage.
from swift.
@ephemer Got it, thanks!
from swift.
Related Issues (16)
- Setting up environment HOT 2
- JNI Support HOT 6
- Cross-compile for Android from OSX HOT 19
- 1_stdlib/VarArgs.swift HOT 10
- IRGen/objc_simd.sil HOT 5
- stdlib/FixedPoint.swift.gyb
- libicu data files need to be pushed to device HOT 2
- Problem building on Ubuntu 15.10 HOT 2
- find public domain/LLVM code to replace current third-party code HOT 10
- Lib Bionic doesn't compile HOT 5
- Enums and Protocol conformance causes segfault on android HOT 3
- Get tests running HOT 8
- libicu doesn't link at runtime on android systems with their own icu HOT 13
- Find the correct way to package libicu data files HOT 10
- Can share info about how to start porting to Windows.. HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swift.