11use super :: {
2- delete_codegen_vars, device_prompt, ensure_init, env, init_dot_cargo, open_and_wait, with_config ,
3- MobileTarget ,
2+ delete_codegen_vars, device_prompt, ensure_init, env, init_dot_cargo, open_and_wait,
3+ setup_dev_config , with_config , MobileTarget ,
44} ;
55use crate :: {
6+ dev:: Options as DevOptions ,
67 helpers:: flock,
78 interface:: { AppSettings , Interface , MobileOptions , Options as InterfaceOptions } ,
89 mobile:: { write_options, CliOptions , DevChild , DevProcess } ,
@@ -13,6 +14,7 @@ use clap::{ArgAction, Parser};
1314use tauri_mobile:: {
1415 android:: {
1516 config:: { Config as AndroidConfig , Metadata as AndroidMetadata } ,
17+ device:: Device ,
1618 env:: Env ,
1719 } ,
1820 config:: app:: App ,
@@ -55,7 +57,7 @@ pub struct Options {
5557 pub device : Option < String > ,
5658}
5759
58- impl From < Options > for crate :: dev :: Options {
60+ impl From < Options > for DevOptions {
5961 fn from ( options : Options ) -> Self {
6062 Self {
6163 runner : None ,
@@ -89,13 +91,29 @@ pub fn command(options: Options, noise_level: NoiseLevel) -> Result<()> {
8991}
9092
9193fn run_dev (
92- options : Options ,
94+ mut options : Options ,
9395 app : & App ,
9496 config : & AndroidConfig ,
9597 metadata : & AndroidMetadata ,
9698 noise_level : NoiseLevel ,
9799) -> Result < ( ) > {
98- let mut dev_options = options. clone ( ) . into ( ) ;
100+ setup_dev_config ( & mut options. config ) ?;
101+ let env = env ( ) ?;
102+ let device = match device_prompt ( & env, options. device . as_deref ( ) ) {
103+ Ok ( d) => Some ( d) ,
104+ Err ( e) => {
105+ log:: error!( "{e}" ) ;
106+ None
107+ }
108+ } ;
109+
110+ let mut dev_options: DevOptions = options. clone ( ) . into ( ) ;
111+ dev_options. target = Some (
112+ device
113+ . as_ref ( )
114+ . map ( |d| d. target ( ) . triple . to_string ( ) )
115+ . unwrap_or_else ( || "aarch64-linux-android" . into ( ) ) ,
116+ ) ;
99117 let mut interface = crate :: dev:: setup ( & mut dev_options, true ) ?;
100118
101119 let app_settings = interface. app_settings ( ) ;
@@ -106,13 +124,11 @@ fn run_dev(
106124 let out_dir = bin_path. parent ( ) . unwrap ( ) ;
107125 let _lock = flock:: open_rw ( out_dir. join ( "lock" ) . with_extension ( "android" ) , "Android" ) ?;
108126
109- let env = env ( ) ?;
110127 init_dot_cargo ( app, Some ( ( & env, config) ) ) ?;
111128
112129 let open = options. open ;
113130 let exit_on_panic = options. exit_on_panic ;
114131 let no_watch = options. no_watch ;
115- let device = options. device ;
116132 interface. mobile_dev (
117133 MobileOptions {
118134 debug : true ,
@@ -133,45 +149,34 @@ fn run_dev(
133149
134150 if open {
135151 open_and_wait ( config, & env)
136- } else {
137- match run (
138- device. as_deref ( ) ,
139- options,
140- config,
141- & env,
142- metadata,
143- noise_level,
144- ) {
152+ } else if let Some ( device) = & device {
153+ match run ( device, options, config, & env, metadata, noise_level) {
145154 Ok ( c) => {
146155 crate :: dev:: wait_dev_process ( c. clone ( ) , move |status, reason| {
147156 crate :: dev:: on_app_exit ( status, reason, exit_on_panic, no_watch)
148157 } ) ;
149158 Ok ( Box :: new ( c) as Box < dyn DevProcess > )
150159 }
151- Err ( RunError :: FailedToPromptForDevice ( e) ) => {
152- log:: error!( "{}" , e) ;
153- open_and_wait ( config, & env)
154- }
155160 Err ( e) => {
156161 crate :: dev:: kill_before_dev_process ( ) ;
157162 Err ( e. into ( ) )
158163 }
159164 }
165+ } else {
166+ open_and_wait ( config, & env)
160167 }
161168 } ,
162169 )
163170}
164171
165172#[ derive( Debug , thiserror:: Error ) ]
166173enum RunError {
167- #[ error( "{0}" ) ]
168- FailedToPromptForDevice ( String ) ,
169174 #[ error( "{0}" ) ]
170175 RunFailed ( String ) ,
171176}
172177
173178fn run (
174- device : Option < & str > ,
179+ device : & Device < ' _ > ,
175180 options : MobileOptions ,
176181 config : & AndroidConfig ,
177182 env : & Env ,
@@ -186,8 +191,7 @@ fn run(
186191
187192 let build_app_bundle = metadata. asset_packs ( ) . is_some ( ) ;
188193
189- device_prompt ( env, device)
190- . map_err ( |e| RunError :: FailedToPromptForDevice ( e. to_string ( ) ) ) ?
194+ device
191195 . run (
192196 config,
193197 env,
0 commit comments