{"id":19223945,"url":"https://github.com/ankidroid/anki-android-backend","last_synced_at":"2025-08-20T02:32:33.321Z","repository":{"id":37112508,"uuid":"319774319","full_name":"ankidroid/Anki-Android-Backend","owner":"ankidroid","description":"JNI bridge between AnkiDroid and Anki Desktop's rust code ","archived":false,"fork":false,"pushed_at":"2024-05-20T16:26:32.000Z","size":1195,"stargazers_count":58,"open_issues_count":16,"forks_count":24,"subscribers_count":12,"default_branch":"main","last_synced_at":"2024-05-21T06:56:07.017Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ankidroid.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-08T22:15:18.000Z","updated_at":"2024-05-28T02:29:47.566Z","dependencies_parsed_at":"2023-10-11T12:51:38.246Z","dependency_job_id":"22f0110c-b1c2-4c55-91d6-31c779d8dd88","html_url":"https://github.com/ankidroid/Anki-Android-Backend","commit_stats":{"total_commits":547,"total_committers":14,"mean_commits":39.07142857142857,"dds":0.6727605118829982,"last_synced_commit":"c04165b36e6f01a6dab33ed61a2121b7f00a1df3"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankidroid%2FAnki-Android-Backend","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankidroid%2FAnki-Android-Backend/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankidroid%2FAnki-Android-Backend/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankidroid%2FAnki-Android-Backend/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ankidroid","download_url":"https://codeload.github.com/ankidroid/Anki-Android-Backend/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230388129,"owners_count":18217755,"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":[],"created_at":"2024-11-09T15:09:57.404Z","updated_at":"2025-08-20T02:32:33.313Z","avatar_url":"https://github.com/ankidroid.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AnkiDroid-Backend\n\nAn interface for accessing Anki Desktop's Rust backend inside AnkiDroid. This\nallows AnkiDroid to re-use the computer version's business logic and webpages,\ninstead of having to reimplement them.\n\nThis is a separate repo that gets published to a library that AnkiDroid consumes,\nso that AnkiDroid development is possible without a Rust toolchain installed.\n\n## Prerequisites\n\nWe assume you already have Android Studio, and are able to build the AnkiDroid\nproject already.\n\nThe repos `Anki-Android` and `Anki-Android-Backend` should be cloned inside the\nsame folder. Furthermore, `Anki-Android-Backend` should not be renamed, as this\nname is hard-coded in AnkiDroid gradle files. Unless stated otherwise, all\ncommands below are supposed to be executed in the current repo.\n\n### Download Anki submodule\n\n    git submodule update --init --recursive\n\n### C toolchain\n\nInstall Xcode/Visual Studio if on macOS/Windows.\n\n### Rust\n\nInstall rustup from \u003chttps://rustup.rs/\u003e\n\n#### macOS / Rust / Android Studio interaction\n\nNote that Android Studio does a gradle sync when you open Anki-Android-Backend as a project,\nand this sync requires the `cargo` command to be in your environment `PATH` variable to succeed.\n\nIf you get an exception related to `cargo` not found, you may need to alter your environment\nbefore starting Android Studio. On macOS at least, you may open `Terminal`, verify `cargo` is\nin the `PATH` with a `which cargo`, and open Android Studio directly with this environment setup\nvia the command `open -a \"Android Studio\"`\n\n### Ninja\n\nAnki can be built with Ninja or N2. N2 gives better status output and may be installed like so:\n\n`./anki/tools/install-n2`\n\nOn Windows:\n\n`bash anki/tools/install-n2`\n\n*Note:* n2 receives occasional mandatory updates. If you see build errors, you may need to re-run this command and re-try the build\n\n### NDK\n\n#### Command-line install\n\nAssuming `sdkmanager` from the \"Command-Line Tools\" package is in your PATH:\n\n```bash\ncargo install toml-cli\nANDROID_NDK_VERSION=$(toml get gradle/libs.versions.toml versions.ndk --raw)\nsdkmanager --install \"ndk;$ANDROID_NDK_VERSION\"\n```\n\n#### GUI install\n\nIn Android Studio, choose the Tools\u003eSDK Manager menu option.\n\n- In SDK tools, enable \"show package details\"\n- Choose NDK version listed in `gradle/libs.versions.tml` for the `ndk` key\n- After downloading, you may need to restart Android Studio to get it to\nsynchronize gradle.\n\n### Windows: msys2\n\nInstall [msys2](https://www.msys2.org/) into the default folder location.\n\nAfter installation completes, run msys2, and run the following command:\n\n```\npacman -S git rsync\n```\n\nWhen following the build steps below, make sure msys is on the path:\n\n```\nset PATH=%PATH%;c:\\msys64\\usr\\bin\n```\n\n## Building\n\nTwo main files need to be built:\n\n- The main .aar file, which contains the backend Kotlin code, web assets, and\nAnki backend code compiled for Android.\n- A .jar that contains the backend code compiled for the host platform, for use\nwith Robolectric unit tests.\n\nYou should do the first build with the provided shell .sh/.bat file, as it will\ntake care of downloading the target architecture library as well. You'll need\nto tell the script to use the Java libraries and NDK downloaded by Android Studio,\neg on Linux:\n\n```\ncargo install toml-cli\nANDROID_NDK_VERSION=$(toml get gradle/libs.versions.toml versions.ndk --raw)\nexport ANDROID_SDK_ROOT=$HOME/Android/Sdk\nexport ANDROID_NDK_HOME=$ANDROID_SDK_ROOT/ndk/$ANDROID_NDK_VERSION\n```\n\nOr macOS:\n\n```\ncargo install toml-cli\nANDROID_NDK_VERSION=$(toml get gradle/libs.versions.toml versions.ndk --raw)\nexport ANDROID_SDK_ROOT=$HOME/Library/Android/sdk\nexport ANDROID_NDK_HOME=$ANDROID_SDK_ROOT/ndk/$ANDROID_NDK_VERSION\n```\n\nOr Windows using Powershell:\n\n```\ncargo install toml-cli\n$env:ANDROID_NDK_VERSION=toml get gradle/libs.versions.toml versions.ndk --raw\n$env:ANDROID_NDK_HOME=\"$env:ANDROID_SDK_ROOT\\ndk\\$env:ANDROID_NDK_VERSION\"\n```\n\nIf you don't have Java installed, you may be able to use the version bundled\nwith Android Studio. Eg on macOS:\n\n```\nexport JAVA_HOME=\"/Applications/Android Studio.app/Contents/jre/Contents/Home\"\n```\n\nor Windows:\n\n```\nset JAVA_HOME=C:\\Program Files\\Android\\Android Studio\\jre\n```\n\nNow build with `./build.sh` or `build.bat`.\n\nAfter you've confirmed building works, you may want to build again with the env\nvar RELEASE=1 defined, to build a faster version.\n\n## Modify AnkiDroid to use built library\n\nNow open the AnkiDroid project in AndroidStudio. To tell gradle to load the\ncompiled .aar and .jar files from disk, edit `local.properties`\nin the AnkiDroid repo, and add the following line:\n\n```\nlocal_backend=true\n```\n\nCheck `Anki-AndroidBackend/gradle.properties`'s `BACKEND_VERSION` and\n`Anki-Android/build.gradle`'s `ext.ankidroid_backend_version`. Both variables\nshould have the same value. If it is not the case, you must edit Anki-Android's\none.\n\nAfter making the change, you should be able to build and run the project on an x86_64\nemulator/device (arm64 on M1 Macs), and run unit tests.\n\n## Release builds\n\nOnly the current platform is built by default. In CI, the .aar and .jar files\nare built for multiple platforms, so one release library can be used on a variety\nof devices. See [the release workflow](https://github.com/ankidroid/Anki-Android-Backend/blob/main/.github/workflows/build-release.yml) for how this is done.\n\n### Testing with a specific version of anki\n\nIn this section, we'll consider that you want to test AnkiDroid with the version\nof Anki at commit `$COMMIT_IDENTIFIER` from the repository `some_repo`.\n\nMost of the time `$SOME_REPO` will simply be `origin`, that is, ankitects\nofficial repository, and `COMMIT_IDENTIFIER` could be replaced by the tag of the\nlatest stable release. You can find the latest tag by running `git tag|sort\n-V|tail -n1` in the `anki` directory.\n\n1. run `cd anki` to change into the anki submodule directory,\n1. run `git fetch $SOME_REPO` to ensure you obtain the latest change from this repo.\n1. run `git checkout $COMMIT_IDENTIFIER --recurse-submodules` to obtain the version of the code at this particular commit.\n1. move back to the root of the repo (not the submodule) and run either `build.sh` or `build.bat` depending on your operating system,\nthen run `cargo check` to update our Cargo.lock with any updated versions from the submodule\n1. make sure `rust-toolchain.toml` matches the rust version in the anki git submodule\n\n\n### Creating and Publishing a release\n\nLet's now consider that you want to release a new version of the back-end.\n\n1. Find the latest stable version of Anki. You can find the latest tag by\nrunning `git tag|sort -V|tail -n1` in the `anki` directory. Let's call it\nversion $ANKI_VERSION.\n1. Ensure you are testing and building the back-end against this version (see\npreceding section to learn how to do it).\n1. In `Anki-Android-Backend/gradle.properties` you will need to update\n`VERSION_NAME`. Its value is of the form\n`$BACKEND_VERSION-$ANKI_VERSION`. `$ANKI_VERSION` should be as defined\nabove. `$BACKEND_VERSION` should be incremented compared to the last release.\n1. Run the Github workflow `Build release (from macOS)` manually with a\nstring argument (I typically use `shipit`, but any string will work) - this will\ntrigger a full release build ready for upload to maven.\n1. Check the workflow logs for the link to Maven Central where **if you have a\nMaven Central user with permissions (like David A and Mike H - ask if you want\npermission)** you may \"close\" the repository\" then after a short wait \"release\"\nthe repository.\n1. Head over to the main `Anki-Android` repository and update the\n`AnkiDroid/build.gradle` file there to adopt the new backend version once it\nshows up in\nhttps://repo1.maven.org/maven2/io/github/david-allison/anki-android-backend/\n\n## Architecture\n\nSee [ARCHITECTURE.md](./docs/ARCHITECTURE.md)\n\n## License\n\n[GPL-3.0 License](https://github.com/ankidroid/Anki-Android/blob/master/COPYING)  \n[AGPL-3.0 Licence](https://github.com/AnkiDroid/anki/blob/main/LICENSE) (anki submodule)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fankidroid%2Fanki-android-backend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fankidroid%2Fanki-android-backend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fankidroid%2Fanki-android-backend/lists"}