fix(cli): android dev --open failing due to adb not finding device (#10467)

This commit is contained in:
Lucas Fernandes Nogueira 2024-08-03 10:04:26 -03:00 committed by GitHub
parent 699319d8a7
commit fb1933f174
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 34 additions and 20 deletions

View File

@ -0,0 +1,6 @@
---
"tauri-cli": patch:bug
"@tauri-apps/cli": patch:bug
---
Fixes running `android dev --open`.

View File

@ -11,7 +11,7 @@ use crate::{
use clap::{ArgAction, Parser};
use cargo_mobile2::{
android::target::Target,
android::{adb, target::Target},
opts::Profile,
target::{call_for_targets_with_fallback, TargetTrait},
};
@ -58,6 +58,26 @@ pub fn command(options: Options) -> Result<()> {
let env = env()?;
if cli_options.dev {
let dev_url = tauri_config
.lock()
.unwrap()
.as_ref()
.unwrap()
.build
.dev_url
.clone();
if let Some(port) = dev_url.and_then(|url| url.port_or_known_default()) {
let forward = format!("tcp:{port}");
// ignore errors in case we do not have a device available
let _ = adb::adb(&env, ["reverse", &forward, &forward])
.stdin_file(os_pipe::dup_stdin().unwrap())
.stdout_file(os_pipe::dup_stdout().unwrap())
.stderr_capture()
.run();
}
}
call_for_targets_with_fallback(
options.targets.unwrap_or_default().iter(),
&detect_target_ok,

View File

@ -189,6 +189,7 @@ fn run_build(
let _lock = flock::open_rw(out_dir.join("lock").with_extension("android"), "Android")?;
let cli_options = CliOptions {
dev: false,
features: build_options.features.clone(),
args: build_options.args.clone(),
noise_level,

View File

@ -22,7 +22,6 @@ use clap::{ArgAction, Parser};
use anyhow::Context;
use cargo_mobile2::{
android::{
adb,
config::{Config as AndroidConfig, Metadata as AndroidMetadata},
device::Device,
env::Env,
@ -208,23 +207,6 @@ fn run_dev(
},
)?;
let dev_url = tauri_config
.lock()
.unwrap()
.as_ref()
.unwrap()
.build
.dev_url
.clone();
if let Some(port) = dev_url.and_then(|url| url.port_or_known_default()) {
let forward = format!("tcp:{port}");
adb::adb(&env, ["reverse", &forward, &forward])
.stdin_file(os_pipe::dup_stdin().unwrap())
.stdout_file(os_pipe::dup_stdout().unwrap())
.stderr_capture()
.run()?;
}
let open = options.open;
let exit_on_panic = options.exit_on_panic;
let no_watch = options.no_watch;
@ -238,6 +220,7 @@ fn run_dev(
},
|options| {
let cli_options = CliOptions {
dev: true,
features: options.features.clone(),
args: options.args.clone(),
noise_level,

View File

@ -270,6 +270,7 @@ fn run_build(
let _lock = flock::open_rw(out_dir.join("lock").with_extension("ios"), "iOS")?;
let cli_options = CliOptions {
dev: false,
features: build_options.features.clone(),
args: build_options.args.clone(),
noise_level,

View File

@ -310,7 +310,7 @@ fn use_network_address_for_dev_url(
.host
.unwrap_or_default()
.unwrap_or_else(|| *local_ip_address(options.force_ip_prompt));
dev_options.host.replace(ip.clone());
dev_options.host.replace(ip);
Some(ip)
} else {
None
@ -375,6 +375,7 @@ fn run_dev(
},
|options| {
let cli_options = CliOptions {
dev: true,
features: options.features.clone(),
args: options.args.clone(),
noise_level,

View File

@ -131,6 +131,7 @@ impl Target {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CliOptions {
pub dev: bool,
pub features: Option<Vec<String>>,
pub args: Vec<String>,
pub noise_level: NoiseLevel,
@ -140,6 +141,7 @@ pub struct CliOptions {
impl Default for CliOptions {
fn default() -> Self {
Self {
dev: false,
features: None,
args: vec!["--lib".into()],
noise_level: Default::default(),