Building a mobile app in Rust and React Native, Part 1: Project Setup

Required tools

  • node.js (tested on v7.4.0)
  • npm (tested on 5.2.0)
  • rustup (tested on rustup 1.0.0 (17b6d21 2016-12-15))
  • rustc (tested on 1.19.0 (0ade33941 2017–07–17))
  • cargo (tested on cargo 0.20.0 (a60d185c8 2017–07–13))
  • android_ndk (tested on r13b)
  • Xcode (only, for iOS, tested on Version 8.1 (8B62))
  • $NDK_HOME envarionment variable set to ndk home directory (eg. /usr/local/opt/android-ndk)
  • $JAVA_HOME envarionment variable set to java home directory (eg. /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home)

Setting up cross compilation

# ios
rustup target add i386-apple-ios
rustup target add x86_64-apple-ios
rustup target add armv7-apple-ios
rustup target add armv7s-apple-ios
rustup target add aarch64-apple-ios
# android
rustup target add aarch64-linux-android
rustup target add armv7-linux-androideabi
rustup target add i686-linux-android
react-native init our_project
cargo new our_project
__test__
android
app.json
index.android.js
index.ios.js
ios
node_modules
package.json
rust
/our_project
/Cargo.toml
/src
ARCHS_IOS = i386-apple-ios x86_64-apple-ios armv7-apple-ios armv7s-apple-ios aarch64-apple-ios
ARCHS_ANDROID = aarch64-linux-android armv7-linux-androideabi i686-linux-android
LIB=libsigner.a
all: ios androidios: $(LIB)android: $(ARCHS_ANDROID)
sh copy_android.sh
.PHONY: $(ARCHS_IOS)
$(ARCHS_IOS): %:
cargo build --target $@ --release
.PHONY: $(ARCHS_ANDROID)
$(ARCHS_ANDROID): %:
cargo build --target $@ --release
$(LIB): $(ARCHS_IOS)
lipo -create -output $@ $(foreach arch,$(ARCHS_IOS),$(wildcard target/$(arch)/release/$(LIB)))
#! /bin/bashmkdir -p ../../android/app/src/main/jniLibs
mkdir -p ../../android/app/src/main/jniLibs/x86
mkdir -p ../../android/app/src/main/jniLibs/arm64-v8a
mkdir -p ../../android/app/src/main/jniLibs/armeabi-v7a
cp ./target/i686-linux-android/release/libsigner.so ../../android/app/src/main/jniLibs/x86/libsigner.so
cp ./target/aarch64-linux-android/release/libsigner.so ../../android/app/src/main/jniLibs/arm64-v8a/libsigner.so
cp ./target/armv7-linux-androideabi/release/libsigner.so ../../android/app/src/main/jniLibs/armeabi-v7a/libsigner.so
[target.aarch64-linux-android]
ar = "/Users/marek/projects/ethcore/native-signer/NDK/arm64/bin/aarch64-linux-android-ar"
linker = "/Users/marek/projects/ethcore/native-signer/NDK/arm64/bin/aarch64-linux-android-gcc"
[target.armv7-linux-androideabi]
ar = "/Users/marek/projects/ethcore/native-signer/NDK/arm/bin/arm-linux-androideabi-ar"
linker = "/Users/marek/projects/ethcore/native-signer/NDK/arm/bin/arm-linux-androideabi-gcc"
[target.i686-linux-android]
ar = "/Users/marek/projects/ethcore/native-signer/NDK/x86/bin/i686-linux-android-ar"
linker = "/Users/marek/projects/ethcore/native-signer/NDK/x86/bin/i686-linux-android-gcc"
__test__
android
app.json
index.android.js
index.ios.js
ios
node_modules
package.json
rust
/.cargo
/
config
/our_project
/
Cargo.toml
/copy_android.sh
/Makefile
/src

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Marek Kotewicz

Marek Kotewicz

More from Medium

Setting up Web3Auth with React and Solana

Weather-Based Micro Insurance application using Blockchain and React

Function State Mutability in Solidity

Solana Web3 Tutorial (3) —Create a Program Derived Account(PDA)