From b0012424c5f432debfa42ba145e2672966d5f6d5 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Mon, 6 Oct 2025 13:11:48 -0300 Subject: [PATCH] fix(cli): resolve IP when dev URL host is unspecified, closes #13356 (#14115) currently the `use_network_address_for_dev_url` function already detects Ipv4Addr::UNSPECIFIED to resolve the local IP address for mobile development when the dev URL host is 0.0.0.0, but we only call it when `--host` is provided or running on a physical device. This change detects the unspecified host early and force the resolution to run even for simulator builds --- .changes/fix-unspeficied-dev-host.md | 6 ++++++ crates/tauri-cli/src/mobile/android/dev.rs | 19 +++++++++++++++++-- crates/tauri-cli/src/mobile/ios/dev.rs | 19 +++++++++++++++++-- crates/tauri-cli/src/mobile/mod.rs | 4 +--- 4 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 .changes/fix-unspeficied-dev-host.md diff --git a/.changes/fix-unspeficied-dev-host.md b/.changes/fix-unspeficied-dev-host.md new file mode 100644 index 000000000..488585513 --- /dev/null +++ b/.changes/fix-unspeficied-dev-host.md @@ -0,0 +1,6 @@ +--- +"@tauri-apps/cli": patch:bug +"tauri-cli": patch:bug +--- + +Resolve local IP address when `tauri.conf.json > build > devUrl` host is `0.0.0.0`. diff --git a/crates/tauri-cli/src/mobile/android/dev.rs b/crates/tauri-cli/src/mobile/android/dev.rs index e5a3b2124..05540d26c 100644 --- a/crates/tauri-cli/src/mobile/android/dev.rs +++ b/crates/tauri-cli/src/mobile/android/dev.rs @@ -33,8 +33,9 @@ use cargo_mobile2::{ opts::{FilterLevel, NoiseLevel, Profile}, target::TargetTrait, }; +use url::Host; -use std::{env::set_current_dir, path::PathBuf}; +use std::{env::set_current_dir, net::Ipv4Addr, path::PathBuf}; #[derive(Debug, Clone, Parser)] #[clap( @@ -231,12 +232,26 @@ fn run_dev( metadata: &AndroidMetadata, noise_level: NoiseLevel, ) -> Result<()> { - // when running on an actual device we must use the network IP + // when --host is provided or running on a physical device or resolving 0.0.0.0 we must use the network IP if options.host.0.is_some() || device .as_ref() .map(|device| !device.serial_no().starts_with("emulator")) .unwrap_or(false) + || tauri_config + .lock() + .unwrap() + .as_ref() + .unwrap() + .build + .dev_url + .as_ref() + .is_some_and(|url| { + matches!( + url.host(), + Some(Host::Ipv4(i)) if i == Ipv4Addr::UNSPECIFIED + ) + }) { use_network_address_for_dev_url(&tauri_config, &mut dev_options, options.force_ip_prompt)?; } diff --git a/crates/tauri-cli/src/mobile/ios/dev.rs b/crates/tauri-cli/src/mobile/ios/dev.rs index 406a72a0b..36d88b511 100644 --- a/crates/tauri-cli/src/mobile/ios/dev.rs +++ b/crates/tauri-cli/src/mobile/ios/dev.rs @@ -32,8 +32,9 @@ use cargo_mobile2::{ env::Env, opts::{NoiseLevel, Profile}, }; +use url::Host; -use std::{env::set_current_dir, path::PathBuf}; +use std::{env::set_current_dir, net::Ipv4Addr, path::PathBuf}; const PHYSICAL_IPHONE_DEV_WARNING: &str = "To develop on physical phones you need the `--host` option (not required for Simulators). See the documentation for more information: https://v2.tauri.app/develop/#development-server"; @@ -271,12 +272,26 @@ fn run_dev( config: &AppleConfig, noise_level: NoiseLevel, ) -> Result<()> { - // when running on an actual device we must use the network IP + // when --host is provided or running on a physical device or resolving 0.0.0.0 we must use the network IP if options.host.0.is_some() || device .as_ref() .map(|device| !matches!(device.kind(), DeviceKind::Simulator)) .unwrap_or(false) + || tauri_config + .lock() + .unwrap() + .as_ref() + .unwrap() + .build + .dev_url + .as_ref() + .is_some_and(|url| { + matches!( + url.host(), + Some(Host::Ipv4(i)) if i == Ipv4Addr::UNSPECIFIED + ) + }) { use_network_address_for_dev_url(&tauri_config, &mut dev_options, options.force_ip_prompt)?; } diff --git a/crates/tauri-cli/src/mobile/mod.rs b/crates/tauri-cli/src/mobile/mod.rs index a764ae360..301900b04 100644 --- a/crates/tauri-cli/src/mobile/mod.rs +++ b/crates/tauri-cli/src/mobile/mod.rs @@ -268,9 +268,7 @@ fn use_network_address_for_dev_url( let ip = if let Some(url) = &mut dev_url { let localhost = match url.host() { Some(url::Host::Domain(d)) => d == "localhost", - Some(url::Host::Ipv4(i)) => { - i == std::net::Ipv4Addr::LOCALHOST || i == std::net::Ipv4Addr::UNSPECIFIED - } + Some(url::Host::Ipv4(i)) => i == Ipv4Addr::LOCALHOST || i == Ipv4Addr::UNSPECIFIED, _ => false, };