All Projects → i-schuetz → Rust_android_ios

i-schuetz / Rust_android_ios

Android / iOS app with shared Rust logic

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Rust android ios

Flutter One App
🎊Flutter 仿「ONE·一个」APP,兼容Android、iOS双平台,Flutter的练手学习,覆盖了各种基本控件使用、下拉刷新上拉加载、HTML解析、音乐播放、图片预览下载、权限申请等,使用Android Studio的FlutterJsonBeanFactory插件完成JSON转Dart实体
Stars: ✭ 316 (+357.97%)
Mutual labels:  android-app, ios-app
Flutter Tetris
a tetris game powered by flutter. 使用flutter开发俄罗斯方块。
Stars: ✭ 1,109 (+1507.25%)
Mutual labels:  android-app, ios-app
Furniture app flutter
watch it on YouTube
Stars: ✭ 322 (+366.67%)
Mutual labels:  android-app, ios-app
Flutter gank
Flutter版 干货集中营
Stars: ✭ 60 (-13.04%)
Mutual labels:  android-app, ios-app
Gas Oil Mixture Mobile
Mobile app for calculation of gasoline/oil ratio for 2 stroke engines built with React Native.
Stars: ✭ 61 (-11.59%)
Mutual labels:  android-app, ios-app
flippingCards
iOS & Android flashcards app for learning German words faster 🃏
Stars: ✭ 23 (-66.67%)
Mutual labels:  ios-app, android-app
Material Kit React Native
Material Kit React Native
Stars: ✭ 424 (+514.49%)
Mutual labels:  android-app, ios-app
TemporaryContacts
Android/iOS mobile application for adding contacts that are automatically deleted after a set or default interval and are synced with main address book
Stars: ✭ 15 (-78.26%)
Mutual labels:  ios-app, android-app
React Natives App
App for the React & React Native developer community as a demo project for the React Native meetups in Germany
Stars: ✭ 20 (-71.01%)
Mutual labels:  android-app, ios-app
Kotlin Native Superhero App
Android and iOS master detail application for list Marvel Super Heroes
Stars: ✭ 15 (-78.26%)
Mutual labels:  android-app, ios-app
flutter-Anniversary
一款界面优美,功能简洁的纪念日APP
Stars: ✭ 57 (-17.39%)
Mutual labels:  ios-app, android-app
Space Curiosity
All space related agregator, built with Flutter - Spark your curiosity!
Stars: ✭ 56 (-18.84%)
Mutual labels:  android-app, ios-app
been-pwned
App that leverages the haveibeenpwned.com API by Troy Hunt. This app is available in the App Stores and is used in several of my talks as well as my book Xamarin.Forms Essentials.
Stars: ✭ 19 (-72.46%)
Mutual labels:  ios-app, android-app
Aawazein
A News Application 🗞️ built under 24 hours ⏰. It is built 🚧 with React Native ⚛️. 🚀 and 3 cups of Chai ☕
Stars: ✭ 28 (-59.42%)
Mutual labels:  ios-app, android-app
lndr-mobile
LNDR mobile app in React Native
Stars: ✭ 14 (-79.71%)
Mutual labels:  ios-app, android-app
Bangumi
💫 An unofficial bgm.tv app client for Android and iOS, built with React Native. 类似专门做ACG的豆瓣, 已适配 iOS/Android, mobile/Pad, light/dark theme, 并加入了很多独有的增强功能
Stars: ✭ 409 (+492.75%)
Mutual labels:  android-app, ios-app
Ionic-ElastiChat-with-Images
Ionic Magic Chat with Angular Elastic, Autolinker.js and more!
Stars: ✭ 66 (-4.35%)
Mutual labels:  ios-app, android-app
Monthly-App-Challenge-2022
Retos mensuales de la comunidad MoureDev para crear pequeñas aplicaciones en base a requisitos
Stars: ✭ 153 (+121.74%)
Mutual labels:  ios-app, android-app
React Native Nw React Calculator
Mobile, desktop and website Apps with the same code
Stars: ✭ 5,116 (+7314.49%)
Mutual labels:  android-app, ios-app
Flutter Tasky App
A Flutter Task App
Stars: ✭ 48 (-30.43%)
Mutual labels:  android-app, ios-app

Rust core for native Android and iOS apps

logos

Rust Android [TODO iOS badge]

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

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 asynchronous tasks and reactive programming

While it's possible to use asynchronous code in core, it's recommended to write it synchronously and execute it asynchronously / with reactive programming in the apps. This greatly simplifies things (see the CoEpi example, which uses Rx in the apps).

"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.

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

  • Add targets
rustup target add x86_64-apple-ios aarch64-apple-ios
  • 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. You'd have to write no JNI. I personally recommend against this, at least for the beginning, as it's better to understand what's going on and JNI, while tedious, is not so complicated.

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].