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

` ` env var not set, do you have a build script with…

Error message

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

What it means

The `#[tauri::mobile_entry_point]` macro builds the Android entry-point symbol from environment variables set by tauri-build (TAURI_ANDROID_PACKAGE_NAME_PREFIX and TAURI_ANDROID_PACKAGE_NAME_APP_NAME). If either variable is missing, the macro emits this compile error pointing at the annotated function.

Solutions

  1. Add a build.rs that calls tauri_build::build() to the crate using the macro
  2. Build through the Tauri CLI (`tauri android build` / `tauri android dev`) rather than raw cargo
  3. Verify tauri-build is a build-dependency in Cargo.toml and the build script is not ignored

Example fix

// before (no build script)
// Cargo.toml: only [dependencies]
// after
// build.rs
fn main() { tauri_build::build(); }
// Cargo.toml
[build-dependencies]
tauri-build = { version = "2", features = [] }
Defensive patterns

Strategy: validation

Validate before calling

// build.rs sanity check before the macro runs
fn main() {
  tauri_build::build();
  println!("cargo:rustc-env=CHECK=ok");
}
// shell check:
// [ -n "$TAURI_ANDROID_PACKAGE_NAME_PREFIX" ] || echo "run via tauri android build"

Try / catch

// The macro emits a compile_error!, so the fix is in the build setup, not catch code.
// Ensure build.rs exists and CI invokes `tauri android build`, not bare `cargo build --target=aarch64-linux-android`.

Prevention

When it happens

Trigger: Using `#[tauri::mobile_entry_point]` in a crate whose build script does not run tauri_build::build(), or building outside the normal Tauri CLI flow so those env vars are never exported.

Common situations: Adding a new binary/lib crate to an Android project without a build.rs; running `cargo build` directly instead of via `tauri android build`; stale build cache after adding mobile support.

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@460ec35447 (2026-09-18). Data as JSON: /api/errors/a7940fb74a2da872. Report an issue: GitHub.

Appendix: 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::{ItemFn, parse_macro_input, spanned::Spanned};

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 460ec35447)