Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): Log errors when adb command fails #3493

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions packages/cli/src/serve/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl AppHandle {

// https://developer.android.com/studio/run/emulator-commandline
Platform::Android => {
self.open_android_sim(envs).await?;
self.open_android_sim(envs).await;
None
}

Expand Down Expand Up @@ -486,28 +486,31 @@ impl AppHandle {
unimplemented!("dioxus-cli doesn't support ios devices yet.")
}

async fn open_android_sim(&self, envs: Vec<(&'static str, String)>) -> Result<()> {
async fn open_android_sim(&self, envs: Vec<(&'static str, String)>) {
let apk_path = self.app.apk_path();
let full_mobile_app_name = self.app.build.krate.full_mobile_app_name();

// Start backgrounded since .open() is called while in the arm of the top-level match
tokio::task::spawn(async move {
// Install
// adb install -r app-debug.apk
let _output = Command::new("adb")
if let Err(e) = Command::new("adb")
.arg("install")
.arg("-r")
.arg(apk_path)
.stderr(Stdio::piped())
.stdout(Stdio::piped())
.output()
.await?;
.await
{
tracing::error!("Failed to install apk with `adb`: {e}");
};

// eventually, use the user's MainAcitivty, not our MainAcitivty
// adb shell am start -n dev.dioxus.main/dev.dioxus.main.MainActivity
let activity_name = format!("{}/dev.dioxus.main.MainActivity", full_mobile_app_name,);

let _output = Command::new("adb")
if let Err(e) = Command::new("adb")
.arg("shell")
.arg("am")
.arg("start")
Expand All @@ -517,11 +520,10 @@ impl AppHandle {
.stderr(Stdio::piped())
.stdout(Stdio::piped())
.output()
.await?;

Result::<()>::Ok(())
.await
{
tracing::error!("Failed to start app with `adb`: {e}");
};
});

Ok(())
}
}
Loading