{"id":16373115,"url":"https://github.com/bbqsrc/cargo-ndk","last_synced_at":"2025-05-13T23:08:38.505Z","repository":{"id":38148077,"uuid":"129519978","full_name":"bbqsrc/cargo-ndk","owner":"bbqsrc","description":"Compile Rust projects against the Android NDK without hassle","archived":false,"fork":false,"pushed_at":"2025-01-13T12:33:50.000Z","size":256,"stargazers_count":766,"open_issues_count":3,"forks_count":71,"subscribers_count":15,"default_branch":"main","last_synced_at":"2025-04-11T10:01:05.689Z","etag":null,"topics":["android","cargo","ndk","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/bbqsrc.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["bbqsrc"],"custom":"https://necessary.nu"}},"created_at":"2018-04-14T13:34:46.000Z","updated_at":"2025-04-10T07:35:35.000Z","dependencies_parsed_at":"2024-05-13T14:54:21.127Z","dependency_job_id":"a46b5a6b-3ad4-4897-b302-19fc874a25e5","html_url":"https://github.com/bbqsrc/cargo-ndk","commit_stats":{"total_commits":127,"total_committers":15,"mean_commits":8.466666666666667,"dds":0.3307086614173228,"last_synced_commit":"da7f44b7d4298be8f57e3b903abdcbe91354214a"},"previous_names":[],"tags_count":41,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbqsrc%2Fcargo-ndk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbqsrc%2Fcargo-ndk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbqsrc%2Fcargo-ndk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbqsrc%2Fcargo-ndk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bbqsrc","download_url":"https://codeload.github.com/bbqsrc/cargo-ndk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254041738,"owners_count":22004762,"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","cargo","ndk","rust"],"created_at":"2024-10-11T03:13:24.366Z","updated_at":"2025-05-13T23:08:33.484Z","avatar_url":"https://github.com/bbqsrc.png","language":"Rust","readme":"# cargo-ndk - Build Rust code for Android\n\n[\u003cimg alt=\"CI\" src=\"https://github.com/bbqsrc/cargo-ndk/actions/workflows/ci.yml/badge.svg\"\u003e](https://github.com/bbqsrc/cargo-ndk/actions)\n\u003cimg alt=\"Minimum supported Rust version: 1.73\" src=\"https://img.shields.io/badge/MSRV-1.73-informational\"\u003e\n\nThis cargo extension handles all the environment configuration needed for successfully building libraries\nfor Android from a Rust codebase, with support for generating the correct `jniLibs` directory structure.\n\n## Installing\n\n```\ncargo install cargo-ndk\n```\n\nYou'll also need to install all the toolchains you intend to use. Simplest way is with the following:\n\n```\nrustup target add \\\n    aarch64-linux-android \\\n    armv7-linux-androideabi \\\n    x86_64-linux-android \\\n    i686-linux-android\n```\n\nModify as necessary for your use case.\n\n## Usage\n\nIf you have installed the NDK with Android Studio to its default location, `cargo ndk` will automatically detect\nthe most recent NDK version and use it. This can be overriden by specifying the path to the NDK root directory in\nthe `ANDROID_NDK_HOME` environment variable.\n\n### Examples\n\n#### Building a library for 32-bit and 64-bit ARM systems\n\n```\ncargo ndk -t armeabi-v7a -t arm64-v8a -o ./jniLibs build --release\n```\n\nThis specifies the Android targets to be built (ordinary triples are also supported), the output directory to use for placing the `.so` files in the layout\nexpected by Android, and then the ordinary flags to be passed to `cargo`.\n\n![Example](./example/example.svg)\n\n#### Linking against and copying `libc++_shared.so` into the relevant places in the output directory\n\nCreate a `build.rs` in your project with the following:\n\n```rust\nuse std::{env, path::{Path, PathBuf}};\n\nfn main() {\n    if env::var(\"CARGO_CFG_TARGET_OS\").unwrap() == \"android\" {\n        android();\n    }\n}\n\nfn android() {\n    println!(\"cargo:rustc-link-lib=c++_shared\");\n\n    if let Ok(output_path) = env::var(\"CARGO_NDK_OUTPUT_PATH\") {\n        let sysroot_libs_path =\n            PathBuf::from(env::var_os(\"CARGO_NDK_SYSROOT_LIBS_PATH\").unwrap());\n        let lib_path = sysroot_libs_path.join(\"libc++_shared.so\");\n        std::fs::copy(\n            lib_path,\n            Path::new(\u0026output_path)\n                .join(\u0026env::var(\"CARGO_NDK_ANDROID_TARGET\").unwrap())\n                .join(\"libc++_shared.so\"),\n        )\n        .unwrap();\n    }\n}\n```\n\n### Controlling verbosity\n\nAdd `-v` or `-vv` as you ordinarily would after the cargo command.\n\n### Providing environment variables for C dependencies\n\n`cargo-ndk` derives which environment variables to read the same way as the `cc` crate.\n\n### `cargo-ndk`-specific environment variables\n\nThese environment variables are exported for use in build scripts and other downstream use cases:\n\n- `CARGO_NDK_ANDROID_PLATFORM`: the Android platform API number as an integer (e.g. `21`)\n- `CARGO_NDK_ANDROID_TARGET`: the Android name for the build target (e.g. `armeabi-v7a`)\n- `CARGO_NDK_OUTPUT_PATH`: the output path as specified with the `-o` flag\n- `CARGO_NDK_SYSROOT_PATH`: path to the sysroot inside the Android NDK\n- `CARGO_NDK_SYSROOT_TARGET`: the target name for the files inside the sysroot (differs slightly from the standard LLVM triples)\n- `CARGO_NDK_SYSROOT_LIBS_PATH`: path to the libraries inside the sysroot with the given sysroot target (e.g. `$CARGO_NDK_SYSROOT_PATH/usr/lib/$CARGO_NDK_SYSROOT_TARGET`)\n\n### Printing the environment\n\nSometimes you just want the environment variables that `cargo-ndk` configures so you can, say, set up rust-analyzer in VS Code or similar.\n\nIf you want to source it into your bash environment:\n\n```\nsource \u003c(cargo ndk-env)\n```\n\nPowerShell:\n\n```\ncargo ndk-env --powershell | Out-String | Invoke-Expression\n```\n\nRust Analyzer and anything else with JSON-based environment handling:\n\nFor configuring rust-analyzer, add the `--json` flag and paste the blob into the relevant place in the config.\n\n## Supported hosts\n\n- Linux\n- macOS (`x86_64` and `arm64`)\n- Windows\n\n## Local development\n\n`git clone` and then install the crate with `cargo`:\n\n```bash\ncargo install --path .\n```\n\n## Similar projects\n\n* [cargo-cocoapods](https://github.com/bbqsrc/cargo-cocoapods) - for building .a files for all Apple platforms, and bundling for CocoaPods\n\n## License\n\nThis project is licensed under either of\n\n * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your option.\n","funding_links":["https://github.com/sponsors/bbqsrc","https://necessary.nu"],"categories":["Rust"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbbqsrc%2Fcargo-ndk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbbqsrc%2Fcargo-ndk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbbqsrc%2Fcargo-ndk/lists"}