mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-11-24 04:03:52 +03:00
fix(cli): android dev --open failing due to adb not finding device (#10467)
This commit is contained in:
parent
699319d8a7
commit
fb1933f174
6
.changes/android-dev-open-adb-fix.md
Normal file
6
.changes/android-dev-open-adb-fix.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
"tauri-cli": patch:bug
|
||||
"@tauri-apps/cli": patch:bug
|
||||
---
|
||||
|
||||
Fixes running `android dev --open`.
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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(),
|
||||
|
Loading…
Reference in New Issue
Block a user