tauri-apps / tauri

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
https://tauri.app
Apache License 2.0
85.36k stars 2.58k forks source link

[bug] `tauri add` doesn't add the conditional inclusion for desktop vs mobile #11737

Open dionysuzx opened 2 days ago

dionysuzx commented 2 days ago

If you follow the docs to add updater like cargo tauri add updater, it adds everything but you'll get this error: error[E0433]: failed to resolve: use of undeclared crate or module tauri_plugin_updater.

The reason for this is because in the Cargo.toml it will add tauri-plugin-updater conditionally excluding mobile builds:

[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
tauri-plugin-updater = "2.0.2"

Thus, the program cannot find tauri-plugin-updater when referenced in the lib.rs builder.

I fixed this by doing:

    let mut builder = tauri::Builder::default()
        .plugin(tauri_plugin_dialog::init())
        .plugin(tauri_plugin_fs::init())
        .plugin(tauri_plugin_os::init())
        .invoke_handler(tauri::generate_handler![
            ...
        ]);

    #[cfg(not(any(target_os = "android", target_os = "ios")))]
    {
        builder = builder.plugin(tauri_plugin_updater::Builder::new().build());
    }

One option is we can update the install script to also do this by default.