All Projects → ivanschuetz → rust_android_ios

ivanschuetz / rust_android_ios

Licence: other
Android / iOS app with shared Rust logic

Programming Languages

rust
11053 projects
swift
15916 projects
kotlin
9241 projects
c
50402 projects - #5 most used programming language
shell
77523 projects
java
68154 projects - #9 most used programming language
objective c
16641 projects - #2 most used programming language

Projects that are alternatives of or similar to rust android ios

Kotlin Mpp Standard
A standard setup for Kotlin multiplatform projects.
Stars: ✭ 92 (-49.45%)
Mutual labels:  ios-app, android-app
Anypicker
jQuery Picker Library for Android, iOS & Windows Phone. eg Date Picker, Time Picker, DateTime Picker, Custom Select etc
Stars: ✭ 114 (-37.36%)
Mutual labels:  ios-app, android-app
One Vue
仿韩寒「ONE · 一个」,基于vue2.0+混合式开发的一款跨终端、高性能、用户体验高的移动端App! 学习Vue的同学可以看下,感谢 Star 和 Fork!!
Stars: ✭ 93 (-48.9%)
Mutual labels:  ios-app, android-app
Chatter App
This is a flutter based modern messaging app where users can sign up and log in to chat with their friends, family, colleagues among groups with enriched User-Experience.
Stars: ✭ 80 (-56.04%)
Mutual labels:  ios-app, android-app
Flutter For Wordpress App
🎃 Cross-platform wordpress news app built with Flutter and WP REST API.
Stars: ✭ 157 (-13.74%)
Mutual labels:  ios-app, android-app
Calenstyle
Responsive Drag-&-Drop Event Calendar Library for Web, Mobile Sites, Android, iOS & Windows Phone
Stars: ✭ 83 (-54.4%)
Mutual labels:  ios-app, android-app
Wordpress App With Flutter
Fully Functional IOS/Android App for WordPress Website with Flutter
Stars: ✭ 109 (-40.11%)
Mutual labels:  ios-app, android-app
Flutter gank
Flutter版 干货集中营
Stars: ✭ 60 (-67.03%)
Mutual labels:  ios-app, android-app
App Privacy Policy Generator
A simple web app to generate a generic privacy policy for your Android/iOS apps
Stars: ✭ 2,278 (+1151.65%)
Mutual labels:  ios-app, android-app
Todayx
🌈Flutter App:🎊「今日份的X」(每天推荐一个:图片、诗歌、名言、音乐、乐评、高等数学、两种配色、化学方程式、Github Repo、知乎问题、文章)
Stars: ✭ 128 (-29.67%)
Mutual labels:  ios-app, android-app
Rust android ios
Android / iOS app with shared Rust logic
Stars: ✭ 69 (-62.09%)
Mutual labels:  ios-app, android-app
Uniapp Admin
Muti-platform management system for uniapp, H5, Android, IOS, Min Program
Stars: ✭ 226 (+24.18%)
Mutual labels:  ios-app, android-app
Flutter Tetris
a tetris game powered by flutter. 使用flutter开发俄罗斯方块。
Stars: ✭ 1,109 (+509.34%)
Mutual labels:  ios-app, android-app
Lbrnmeituan
ReactNative 仿美团项目
Stars: ✭ 84 (-53.85%)
Mutual labels:  ios-app, android-app
Gas Oil Mixture Mobile
Mobile app for calculation of gasoline/oil ratio for 2 stroke engines built with React Native.
Stars: ✭ 61 (-66.48%)
Mutual labels:  ios-app, android-app
Matchimals.fun
🦁 🃏 📱 An animal matching puzzle card game– built with turn-based game engine boardgame.io and React-Native + React-Native-Web
Stars: ✭ 101 (-44.51%)
Mutual labels:  ios-app, android-app
Space Curiosity
All space related agregator, built with Flutter - Spark your curiosity!
Stars: ✭ 56 (-69.23%)
Mutual labels:  ios-app, android-app
Open Source Flutter Apps
📱 List of open source Flutter applications
Stars: ✭ 1,086 (+496.7%)
Mutual labels:  ios-app, android-app
E Commerce Complete Flutter Ui
youtu.be/0z-igs267xw
Stars: ✭ 2,380 (+1207.69%)
Mutual labels:  ios-app, android-app
Ionic Starter Template
Reinventing the wheel, again! Sorry Ionic Team... but there are many newbies learning on Youtube!
Stars: ✭ 208 (+14.29%)
Mutual labels:  ios-app, android-app

Rust core for native Android and iOS apps

Rust Android [TODO iOS badge]

This is an example that shows how to use a shared Rust core in native Android and iOS apps.

⚠️ Looking for maintainers. If you want to help, just open an issue, or email me [email protected]

Why?

This approach gives us the best of all worlds: we prevent code duplication by using a shared library. Rust, as a highly performant and safe language is a great fit for mobile. We keep a fully native UI experience and uncomplicated access to the latest APIs of the platforms.

It's also very flexible, allowing to migrate easily between different platforms, including conventional cross-platform frameworks like Flutter or React Native. For example, you can develop your MVP with Rust+React Native or Rust+Flutter, and migrate later to native iOS/Android, without having to rewrite everything. You even can reuse your core for a web-app, using WebAssembly, or desktop app (where again, you can use native or a cross-platform framework like Electron).

Project structure

  • Rust: Repo's root.
  • iOS app: ios_app directory.
  • Android app: Repo's root as well. TODO move it to a folder android_app, like the iOS app.

Possible setups

There are different ways to integrate Rust:

As source (like in this repo)

  • Simple setup.

  • Rust is built as part of the app's build process.

  • Not ideal if there are team members unfamiliar with Rust.

As binary

The Rust binary is distributed as an external dependency.

  • Better for teams with different skillsets. Everyone works mainly with their familiar tech stack.

  • Better separation of concerns / modularity.

  • Considerably more complicated to setup than monorepo (has to be done only once though).

  • Rust binaries have to be versioned and released.

Note: it is possible to overwrite the external dependency with a local copy for local development.

As "normal" library

Here the external dependency contains the Rust binary and wrapper libraries for Android and iOS respectively (written in Kotlin and Swift), which hide the FFI/JNI, providing a simple and safe interface to the apps. This makes working with this dependency like with regular third parties.

An example for this and the binary approaches can be found here. The Android build contains a wrapper library, which is imported in the Android app with Gradle. The iOS build is distributed directly as a binary (no wrapper), using Carthage.

Note on concurrency

While it's possible to use asynchronous code in core, it's recommended to use blocking apis and add concurrency in the apps. This simplifies the FFI/JNI interfaces (see the CoEpi example, where the apps add concurrency via RxSwift/RxJava).

"Real world" examples

CoEpi

A mobile contact tracing app for epidemics, with Android and iOS frontends.

Xi editor

A text editor with a lot of frontends: MacOS, GTK, Electron and Windows, among others.

Other related projects

WASM-Rust-d3 example

An example that shows how to display chart data with d3/JS, using a Rust core to fetch it.

yew-d3-example

Similar to the above, but using the Yew framework

Quickstart

Install rustup

Android specific steps

  • Ensure the NDK is installed.

  • Set the NDK_HOME environment variable with path to the NDK, e.g:

export $NDK_HOME=$HOME/Library/Android/sdk/ndk/21.3.6528147/
cargo install cargo-ndk
  • Add targets
rustup target add aarch64-linux-android armv7-linux-androideabi x86_64-linux-android i686-linux-android
  • Run the project in Android Studio. This will build Rust, put the binaries in the correct place and start the app.

iOS specific steps

  • Install rust-bitcode 1.46.0 with macOS binary support
wget https://github.com/getditto/rust-bitcode/releases/download/v1.46.0/rust-ios-arm64-1.46.0.zip
unzip rust-ios-arm64-1.46.0.zip
cd rust-ios-arm64-1.46.0
./install.sh

As the binaries are not signed, you'll have to convince macOS that it's safe to run them. One solution is to do the following:

  1. cd rust_android_ios/ios_app
  2. cargo +ios-arm64-1.46.0 build --target aarch64-apple-ios --release --lib
  3. if it fails because macOS doesn't trust the binary, go to System Preferences -> Security & Privacy and Allow to run binary then go to 2.
  • Run the project in Xcode. This will build Rust, put the binaries in the correct place and start the app.

Android specifics

  • Logcat doesn't show stdout and stderr, which means that you'll not see println or panic messages (unless specially configured, like done in this repo).
  • If you're having difficulties, try reproducing the problem in a plain (non Android) Kotlin (or Java) project. The JNI is the same, but it's easier to debug, among other things, because you can see stdout/stderr.

iOS

  • iOS shows stdout/stderr as expected and is overall easier to worth with than Android, given the simpler FFI api.

Inspecting binaries

There are diverse tools to inspect the binaries, e.g.

nm -g libcore.so

Shows the external symbols, useful if you want to check that the library was generated correctly / contains the symbols from your sources.

To look for a specific symbol:

nm -g libcore.so | grep greet

Convenience

iOS

  • cbindgen: generates headers for the FFI Rust declarations. In this project, this would mean that mobileapp-ios.h would be automatically generated.

Android

  • rust-swig: similarly to cbindgen for iOS, this generates the JNI api for the Rust declarations. In this project, this would mean that JNIApi would be generated, and ffi_android.rs mostly too.

Links

Official Rust FFI docs

Rust FFI guide

Official JNI docs (tutorials may be better to start...)

Android JNI tips

Android supported ABIs

Contribute

  1. Fork
  2. Commit changes to a branch in your fork
  3. Push your code and make a pull request
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].