33// SPDX-License-Identifier: MIT
44
55use super :: { get_app, Target } ;
6- use crate :: helpers:: { config:: get as get_tauri_config, template:: JsonMap } ;
6+ use crate :: helpers:: { app_paths :: tauri_dir , config:: get as get_tauri_config, template:: JsonMap } ;
77use crate :: Result ;
88use cargo_mobile2:: {
99 android:: {
@@ -15,6 +15,7 @@ use cargo_mobile2::{
1515 util:: {
1616 self ,
1717 cli:: { Report , TextWrapper } ,
18+ relativize_path,
1819 } ,
1920} ;
2021use handlebars:: { Context , Handlebars , Helper , HelperResult , Output , RenderContext , RenderError } ;
@@ -97,14 +98,21 @@ pub fn exec(
9798
9899 let ( handlebars, mut map) = handlebars ( & app) ;
99100
101+ // the CWD used when the the IDE runs the android-studio-script or the xcode-script
102+ let ide_run_cwd = if target == Target :: Android {
103+ tauri_dir ( )
104+ } else {
105+ tauri_dir ( ) . join ( "gen/apple" )
106+ } ;
107+
100108 let mut args = std:: env:: args_os ( ) ;
101109 let mut binary = args
102110 . next ( )
103111 . map ( |bin| {
104112 let path = PathBuf :: from ( & bin) ;
105113 if path. exists ( ) {
106114 let absolute_path = util:: prefix_path ( & current_dir, path) ;
107- return absolute_path. into ( ) ;
115+ return relativize_path ( absolute_path, & ide_run_cwd ) . into_os_string ( ) ;
108116 }
109117 bin
110118 } )
@@ -114,11 +122,16 @@ pub fn exec(
114122 let path = PathBuf :: from ( & arg) ;
115123 if path. exists ( ) {
116124 let absolute_path = util:: prefix_path ( & current_dir, path) ;
117- build_args. push ( absolute_path. to_string_lossy ( ) . into_owned ( ) ) ;
125+ build_args. push (
126+ relativize_path ( absolute_path, & ide_run_cwd)
127+ . to_string_lossy ( )
128+ . into_owned ( ) ,
129+ ) ;
118130 continue ;
119131 }
132+ let is_mobile_cmd_arg = arg == "android" || arg == "ios" ;
120133 build_args. push ( arg. to_string_lossy ( ) . into_owned ( ) ) ;
121- if arg == "android" || arg == "ios" {
134+ if is_mobile_cmd_arg {
122135 break ;
123136 }
124137 }
@@ -163,7 +176,6 @@ pub fn exec(
163176 // Generate Android Studio project
164177 Target :: Android => match AndroidEnv :: new ( ) {
165178 Ok ( _env) => {
166- let app = get_app ( tauri_config_) ;
167179 let ( config, metadata) =
168180 super :: android:: get_config ( & app, tauri_config_, & Default :: default ( ) ) ;
169181 map. insert ( "android" , & config) ;
0 commit comments