tauri-apps/tauri · error · syn::Error

`{name}` env var not set, do you have a build script with ta

Error message

`{name}` env var not set, do you have a build script with tauri-build?

What it means

#[tauri::mobile_entry_point] generates the start_app symbol the Tauri CLI expects in mobile builds and, for Android, splices the package identifier from two compile-time env vars: TAURI_ANDROID_PACKAGE_NAME_PREFIX (reverse-domain prefix) and TAURI_ANDROID_PACKAGE_NAME_APP_NAME. get_env_var reads them during macro expansion; if either is unset the macro emits a compile error spanned over the whole function, with the hint 'do you have a build script with tauri-build?'.

Source

Thrown at crates/tauri-macros/src/mobile.rs:19

// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

use proc_macro::TokenStream;
use proc_macro2::TokenStream as TokenStream2;
use quote::{format_ident, quote};
use std::env::var;
use syn::{parse_macro_input, spanned::Spanned, ItemFn};

fn get_env_var(name: &str, error: &mut Option<TokenStream2>, function: &ItemFn) -> TokenStream2 {
  match var(name) {
    Ok(value) => {
      let ident = format_ident!("{value}");
      quote!(#ident)
    }
    Err(_) => {
      error.replace(
        syn::Error::new(
          function.span(),
          format!("`{name}` env var not set, do you have a build script with tauri-build?",),
        )
        .into_compile_error(),
      );
      quote!()
    }
  }
}

pub fn entry_point(_attributes: TokenStream, item: TokenStream) -> TokenStream {
  let function = parse_macro_input!(item as ItemFn);
  let function_name = function.sig.ident.clone();

  let mut error = None;
  let domain = get_env_var("TAURI_ANDROID_PACKAGE_NAME_PREFIX", &mut error, &function);
  let app_name = get_env_var("TAURI_ANDROID_PACKAGE_NAME_APP_NAME", &mut error, &function);

View on GitHub (pinned to 52e4b6e71d)

Solutions

  1. Build and check through the CLI: `tauri android dev` or `tauri android build` — it sets both env vars plus TAURI_ENV_*
  2. Ensure [build-dependencies] tauri-build is present and build.rs calls tauri_build::build()
  3. For ad-hoc cargo/rust-analyzer runs, export the vars yourself: TAURI_ANDROID_PACKAGE_NAME_PREFIX=com.example TAURI_ANDROID_PACKAGE_NAME_APP_NAME=myapp cargo check
  4. Align tauri-cli and tauri crate versions (cargo update -p tauri; npm i -D @tauri-apps/cli@latest)

Example fix

# before:
cargo check
# error: `TAURI_ANDROID_PACKAGE_NAME_PREFIX` env var not set, do you have a build script with tauri-build?
# after (option 1 - CLI):
pnpm tauri android build
# after (option 2 - manual env for editor/CI):
export TAURI_ANDROID_PACKAGE_NAME_PREFIX=com.example
export TAURI_ANDROID_PACKAGE_NAME_APP_NAME=myapp
cargo check
Defensive patterns

Strategy: validation

Validate before calling

# gate direct cargo use of a mobile crate
[ -n "${TAURI_ANDROID_PACKAGE_NAME_PREFIX:-}" ] || { echo 'TAURI_ANDROID_PACKAGE_NAME_PREFIX unset — use `tauri android build` or export it'; exit 1; }
[ -n "${TAURI_ANDROID_PACKAGE_NAME_APP_NAME:-}" ] || { echo 'TAURI_ANDROID_PACKAGE_NAME_APP_NAME unset — use `tauri android build` or export it'; exit 1; }
cargo check "$@"

Prevention

When it happens

Trigger: Compiling a crate that uses #[tauri::mobile_entry_point] outside the Tauri mobile flow: plain `cargo check`/`cargo build` on the host, or driving the android target with cargo directly. The vars are injected by `tauri android dev` / `tauri android build` (and mobile project generation), not by cargo itself.

Common situations: rust-analyzer or an editor running cargo check on a mobile lib; CI jobs that build with cargo instead of the tauri CLI; a missing or broken build.rs (no tauri_build::build()); tauri-cli and tauri crate versions out of sync.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of tauri-apps/tauri@52e4b6e71d (2026-08-20). Data as JSON: /api/errors/a7940fb74a2da872. Report an issue: GitHub.