{"id":13503241,"url":"https://github.com/kennytm/rust-ios-android","last_synced_at":"2025-03-29T14:31:14.809Z","repository":{"id":28455824,"uuid":"31971461","full_name":"kennytm/rust-ios-android","owner":"kennytm","description":"Example project for building a library for iOS + Android in Rust.","archived":true,"fork":false,"pushed_at":"2018-10-26T14:44:49.000Z","size":160,"stargazers_count":661,"open_issues_count":6,"forks_count":61,"subscribers_count":30,"default_branch":"master","last_synced_at":"2024-10-31T23:30:52.696Z","etag":null,"topics":["android","cross-platform","ios","rust"],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kennytm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-10T17:26:40.000Z","updated_at":"2024-10-13T20:53:12.000Z","dependencies_parsed_at":"2022-09-20T08:35:19.278Z","dependency_job_id":null,"html_url":"https://github.com/kennytm/rust-ios-android","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kennytm%2Frust-ios-android","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kennytm%2Frust-ios-android/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kennytm%2Frust-ios-android/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kennytm%2Frust-ios-android/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kennytm","download_url":"https://codeload.github.com/kennytm/rust-ios-android/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246196909,"owners_count":20739192,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","cross-platform","ios","rust"],"created_at":"2024-07-31T22:02:43.187Z","updated_at":"2025-03-29T14:31:14.510Z","avatar_url":"https://github.com/kennytm.png","language":"Shell","funding_links":[],"categories":["Shell"],"sub_categories":[],"readme":"rust-ios-android\n================\n\n[![Build status](https://travis-ci.org/kennytm/rust-ios-android.svg?branch=master)](https://travis-ci.org/kennytm/rust-ios-android/)\n\nExample project for building a library for iOS + Android in Rust. macOS is\nrequired for iOS development.\n\n* ✓ Rust 1.20 – 1.25\n* ✓ Android 4.1 – 8.1 (Jelly Bean – Oreo) (API 16–27)\n* ✓ iOS 7 – 11\n\n\u003csmall\u003e(probably works on earlier versions but I don't bother to check 😛)\u003c/small\u003e\n\n*Note: The purpose of this project is not to create a pure Rust app, but rather\nuse Rust as a shared native component between the mobile platforms.*\n\nYou may also want to check \u003chttps://github.com/Geal/rust_on_mobile\u003e.\n\nSetup\n-----\n\n1. Install the common build tools like C compiler and linker. On macOS, get\n    Xcode, and install the command line tools.\n\n    ```sh\n    xcode-select --install\n    ```\n\n2. Get Android NDK. We recommend installing it via Android Studio or\n    `sdkmanager`:\n\n    ```sh\n    sdkmanager --verbose ndk-bundle\n    ```\n\n    Otherwise, please define the environment variable `$ANDROID_NDK_HOME` to the\n    path of the current version of Android NDK.\n\n    ```sh\n    export ANDROID_NDK_HOME='/usr/local/opt/android-ndk/android-ndk-r14b/'\n    ```\n\n3. Create the standalone NDKs.\n\n    ```sh\n    ./create-ndk-standalone.sh\n    ```\n\n4. Download [rustup](https://www.rustup.rs/). We will use this to setup Rust for\n   cross-compiling.\n\n    ```sh\n    curl https://sh.rustup.rs -sSf | sh\n    ```\n\n5. Download targets for iOS and Android.\n\n    ```sh\n    # iOS. Note: you need *all* five targets\n    rustup target add aarch64-apple-ios armv7-apple-ios armv7s-apple-ios x86_64-apple-ios i386-apple-ios\n\n    # Android.\n    rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android\n    ```\n\n6. Copy the content of `cargo-config.toml` (consists of linker information of\n   the Android targets) to `~/.cargo/config`\n\n    ```sh\n    cat cargo-config.toml \u003e\u003e ~/.cargo/config\n    ```\n\n7. Install cargo-lipo to generate the iOS universal library.\n\n    ```sh\n    cargo install cargo-lipo\n    ```\n\nCreating the libraries\n----------------------\n\nYou use use the `sample/` project as an example. (Note that the sample itself\ndoes not contain proper error checking.)\n\n1. Write the library and expose a C interface. See [the FFI chapter in the Rust\n   Book](https://doc.rust-lang.org/book/first-edition/ffi.html) for an\n   introduction.\n\n2. Expose the Java interface with JNI when `target_os=\"android\"`.\n\n3. Build the libraries.\n\n    ```sh\n    cd sample/cargo\n\n    # iOS\n    cargo lipo --release\n\n    # Android\n    cargo build --target aarch64-linux-android --release\n    cargo build --target armv7-linux-androideabi --release\n    cargo build --target i686-linux-android --release\n\n    cd ../..\n    ```\n\n4. Build the Xcode project.\n\n    ```sh\n    cd sample/ios\n    xcodebuild -configuration Release -scheme RustSample | xcpretty\n    cd ../..\n    ```\n\n    When you create an Xcode project yourself, note the following points:\n\n    * Add the C header `rust_regex.h` to allow using the Rust functions from C.\n    * Copy `target/universal/release/lib???.a` to the project. You may need\n      to modify `LIBRARY_SEARCH_PATHS` to include the folder of the `*.a` file.\n    * Note that `cargo-lipo` does not generate bitcode yet. You must set\n      `ENABLE_BITCODE` to `NO`. (See also \u003chttp://stackoverflow.com/a/38488617\u003e)\n    * You need to link to `libresolv.tbd`.\n\n5. Build the Android project.\n\n    ```sh\n    cd sample/android\n    ./gradlew assembleRelease\n    cd ../..\n    ```\n\n    When you create an Android Studio project yourself, note the following\n    points:\n\n    * Copy or link the `*.so` into the corresponding `src/main/jniLibs` folders:\n\n        Copy from Rust | Copy to Android\n        ---|---\n        `target/armv7-linux-androideabi/release/lib???.so` | `src/main/jniLibs/armeabi-v7a/lib???.so`\n        `target/aarch64-linux-android/release/lib???.so` | `src/main/jniLibs/arm64-v8a/lib???.so`\n        `target/i686-linux-android/release/lib???.so` | `src/main/jniLibs/x86/lib???.so`\n\n    * Don't forget to ensure the JNI glue between Rust and Java are compatible.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkennytm%2Frust-ios-android","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkennytm%2Frust-ios-android","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkennytm%2Frust-ios-android/lists"}