1、第三屆中國第三屆中國Rust開發者大會開發者大會利用利用Rust重塑移動應用開發重塑移動應用開發陳東 Aaron ChenCTO AccountLabsRust China Conf 20232023 移動應用開發移動應用開發有那些選擇?有那些選擇?1.Native2.Flutter 3.React Native?利用Rust重塑移動應用開發React Native is an open-source JavaScript framework,designed for building apps on multiple platforms.-Code reusability-Hot reloa
2、d-Javascript ecosystem iconFlutter,is an open source framework by Google for building beautiful,natively compiled,multi-platform applications from a single codebase.-Single codebase-Hot reload-Rendering Engine利用Rust重塑移動應用開發跨平臺開發的優勢和局限性跨平臺開發的優勢和局限性Pros:-Fast-Single Codebase-Third-party support(Javasc
3、ript better than Dart)利用Rust重塑移動應用開發跨平臺開發的優勢和局跨平臺開發的優勢和局限性限性Cons:-Performance-Native feature utilize-Existing Codebase跨平臺開發到到底跨平臺開發到到底應該跨什么?應該跨什么?UI or Logic?利用Rust重塑移動應用開發Rust在移動端應在移動端應用的價值用的價值 Rust is the only advanced choice for cross platform development.利用Rust重塑移動應用開發Rust的特點的特點Why Rust?-Cross p
4、latform-Performance-Thread Safe-Memory Safe-Love利用Rust重塑移動應用開發Rust在移動應用在移動應用開發中的應用開發中的應用Why Rust?-Cross platform-Performance-Memory Safe-Love利用Rust重塑移動應用開發PhoTto/image/chartKeystoneKeystone is aiming to develop the most secure and easyuse hardware wallet for the Web3 world利用Rust重塑移動應用開發Photo/image/c
5、hart采用采用Rust重構業務邏輯重構業務邏輯的背景和動機的背景和動機 PerformanceThe same business logic will run on different platforms such as embedded devices,IOS,Android,etc.It is an inevitable choice for our business to choose a language that can support multiple platforms.Share Logic利用Rust重塑移動應用開發Keystone App is a mobile appl
6、ication developed with React native.Due to some computationally intensive tasks,using Javascript is very poor.Therefore,we plan to use Rust to provide high performance 2);Photo/image/chartRust FFIRust FFI(Foreign Function Interface)refers to the ability of Rust programming language to interface with
7、 code written in other languages,typically C or C+.FFI allows Rust to call functions and use data structures defined in other languages,and vice versa.利用Rust重塑移動應用開發Photo/image/chartRust FFI on Android-NDK The Android NDK is a toolset that lets you implement parts ofyour app in native code,using lan
8、guages such as C and C+.For certain types of apps,this can help you reuse code libraries written in those languages.-JNIJNI is an interface that allows Java to interact with code written in another language.Motivation for JNI is code reusability and performance.WIth JNI,you can reuse existing/legacy
9、 code with Java(mostly C/C+).利用Rust重塑移動應用開發Photo/image/chartRust FFI On IOS-Rust targets for IOS-Build the static universal library for different target-Call the function on the swift code利用Rust重塑移動應用開發Photo/image/chartRust在在Keystone業務業務上的實踐上的實踐Rust Crypto Core利用Rust重塑移動應用開發RCC_androidRCC_ioshttps:/
10、 Crypto CoreCore business logic library,can be shared on different platform.-Signer-cryptography support-Blockchain Support-Publish each module as independent package利用Rust重塑移動應用開發Photo/image/chartRCC_Android利用Rust重塑移動應用開發-RCC_Andorid is an rust library which is to binding Rust code into Android app
11、lication.-Use the crate rifgen,flapigen to generate the java interface for rust code.-Wrap the whole rust code as an independent android libraryRCC_IOS利用Rust重塑移動應用開發-RCC_IOS is an rust library which is to binding Rust code into IOS application.-Use the crate lipo to generate the staticlib for ios ap
12、plication-Use the cbindgen to generate the header file for this library-Introduce the library as linked library into the applicationProtocol Buffers利用Rust重塑移動應用開發Directly expose the function to IOS/Android?-Hard to maintain-Hard to define the return value-Hard to process the error?Panic?App Crash?Tr
13、eat the rust module as an independent service-Command Response-Using the protobuf as the data encoding/decoding protocol Tools-cargo-dinghy-rust-android-gradle-cargo-lipo-android-logger利用Rust重塑移動應用開發SummaryRusts application on mobile platforms is increasingly gaining attention from developers.With i
14、ts impressive performance,memory safety,and concurrency features,Rust has become an ideal choice for building high-performance mobile applications.-Cross-Platform Support:Rusts cross-platform capabilities allow developers to share code across different mobile platforms.Developers can easily port it
15、to different platforms such as Android and iOS.This cross-platform support reduces development effort and improves code maintainability.-High Performance:Rust provides performance comparable to C and C+.This makes Rust a powerful tool for developing high-performance mobile applications.利用Rust重塑移動應用開發Thank you!