Tauri Android Init
Use this skill to turn a desktop/web Tauri project into a working Android development setup, and to debug common Tauri Android traps around Gradle, NDK, WebView dev mode, and APK signing.
First Read
This skill is self-contained for distribution. Do not assume the user's project has the original notes this skill was distilled from.
Read the bundled reference when the request involves setup details, errors, signing, or device debugging:
references/tauri-android-workflow.md: setup checklist, configuration snippets, and diagnostic flow.
Working Rules
- Inspect the existing project before editing:
package.json,vite.config.*,src-tauri/tauri.conf.json,src-tauri/gen/android/gradle.properties,src-tauri/gen/android/app/build.gradle.kts,src-tauri/gen/android/keystore.properties(if signing exists), andsrc-tauri/.cargo/config.tomlif present. - Treat generated Android files as project-local state. Do not blindly regenerate or overwrite
src-tauri/gen/androidif the user already has signing, namespace, SDK, or Gradle fixes there. - Keep machine-specific paths out of reusable config when possible. Prefer environment variables such as
ANDROID_HOME,ANDROID_SDK_ROOT, andANDROID_NDK_HOME; only hard-code NDK paths when the user asks or the environment cannot resolve them. - Do not expose or commit signing secrets. If a
keystore.propertiesfile contains a real password, avoid printing it back. Recommend.gitignorecoverage for*.jksandkeystore.properties. - When the user has a concrete error, route through the diagnostic flow before making broad changes. Most failures fall into Gradle networking, NDK linker selection, device/WebView connectivity, Vite host/HMR config, or release signing.
Default Workflow
Follow this order for Android initialization:
- Confirm prerequisites: Android SDK, NDK, Java/JDK, Rust Android targets, Tauri CLI, connected phone/emulator, and USB debugging.
- Check ALL of these env vars (users may use different names):
ANDROID_HOME,ANDROID_SDK_ROOT,NDK_HOME,ANDROID_NDK_HOME,JAVA_HOME. - Tauri specifically reads
ANDROID_NDK_HOME— if the user only hasNDK_HOME, the NDK will not be discoverable and linkers must be hardcoded incargo/config.toml. - Also verify these binaries are on PATH:
adb(from platform-tools),sdkmanager(from cmdline-tools),keytool(from JDK).
- Check ALL of these env vars (users may use different names):
- For a fresh
npm create tauri-app@latestproject, runnpm installfirst, thennpm run tauri android init. - Initialize or inspect Tauri Android output:
npm run tauri android initif Android has not been initialized; otherwise inspect existingsrc-tauri/gen/android. - Fix frontend dev server settings for device live reload:
package.jsondev script should run Vite with host binding, usuallyvite --host.vite.config.*should use port1420,strictPort: true, andhost: process.env.TAURI_DEV_HOST || false.- If HMR is configured, align it with
TAURI_DEV_HOST, commonly WebSocket port1421.
- Fix Gradle dependency resolution when networking fails:
- Add proxy values to
src-tauri/gen/android/gradle.propertiesonly when the user uses a local proxy. - Validate with
cd src-tauri/gen/androidthen./gradlew tasks --info.
- Add proxy values to
- Fix Rust Android linking:
- First check if
ANDROID_NDK_HOMEis set. If not, checkNDK_HOMEand suggestset -gx ANDROID_NDK_HOME $NDK_HOME(fish) orexport ANDROID_NDK_HOME=$NDK_HOME(bash/zsh). - If Cargo still cannot resolve linkers (env var expansion in
config.tomlis unreliable), createsrc-tauri/.cargo/config.tomlwith absolute paths to the NDK linker binaries foraarch64-linux-android,armv7-linux-androideabi,i686-linux-android, andx86_64-linux-android. - Always verify the linker binaries actually exist at the expected NDK path before writing them into config.
- First check if
- Run on a real device:
- Ensure the phone is connected and authorized before
npm run tauri android dev -- --verbose. - If the app is white, inspect the Android WebView through Chrome at
chrome://inspect/#devices.
- Ensure the phone is connected and authorized before
- Configure release signing only after debug builds run:
- Generate a keystore in
src-tauri/gen/android/app/. - Create
src-tauri/gen/android/keystore.properties. - In
app/build.gradle.kts: addsigningConfigsBEFOREbuildTypes(ordering matters — Gradle will fail withSigningConfig not foundifsigningConfigscomes afterbuildTypes). - Add
signingConfig = signingConfigs.getByName("release")in thereleasebuild type. - Add
*.jksandkeystore.propertiesto.gitignore. - Build with
npm run tauri android build(NOTnpm run tauri buildwhich targets desktop).
- Generate a keystore in
Output Style
When helping a user:
- Start with a short diagnosis of which bucket the issue belongs to.
- Give exact files and commands.
- Prefer small patches over large rewrites.
- For signing, include placeholders for secrets instead of real values.
- End with the next verification command.