1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
use clap::Parser;
use crossbundle_tools::{error::CommandExt, tools::AndroidSdk, utils::Config};
#[derive(Parser, Clone, Debug, Default)]
pub struct SdkManagerInstallCommand {
#[clap(long, short)]
preferred_tools: bool,
#[clap(long, short)]
list: bool,
#[clap(long, short)]
install: Option<String>,
#[clap(long)]
uninstall: Option<String>,
#[clap(long)]
update: bool,
#[clap(long, short)]
sdk_root: Option<std::path::PathBuf>,
#[clap(long, short)]
channel: Option<u32>,
#[clap(long)]
include_obsolete: bool,
#[clap(long, short)]
no_https: bool,
#[clap(long, short)]
verbose: bool,
#[clap(long)]
proxy: Option<String>,
#[clap(long)]
proxy_host: Option<String>,
#[clap(long)]
proxy_port: Option<String>,
}
impl SdkManagerInstallCommand {
pub fn new(&self) -> Self {
Self {
..Default::default()
}
}
pub fn list(&mut self, list: bool) -> &mut Self {
self.list = list;
self
}
pub fn install(&mut self, install: String) -> &mut Self {
self.install = Some(install);
self
}
pub fn uninstall(&mut self, uninstall: String) -> &mut Self {
self.uninstall = Some(uninstall);
self
}
pub fn update(&mut self, update: bool) -> &mut Self {
self.update = update;
self
}
pub fn preferred_tools(&mut self, preferred_tools: bool) -> &mut Self {
self.preferred_tools = preferred_tools;
self
}
pub fn sdk_root(&mut self, sdk_root: std::path::PathBuf) -> &mut Self {
self.sdk_root = Some(sdk_root);
self
}
pub fn channel(&mut self, channel: u32) -> &mut Self {
self.channel = Some(channel);
self
}
pub fn include_obsolete(&mut self, include_obsolete: bool) -> &mut Self {
self.include_obsolete = include_obsolete;
self
}
pub fn no_https(&mut self, no_https: bool) -> &mut Self {
self.no_https = no_https;
self
}
pub fn verbose(&mut self, verbose: bool) -> &mut Self {
self.verbose = verbose;
self
}
pub fn proxy(&mut self, proxy: String) -> &mut Self {
self.proxy = Some(proxy);
self
}
pub fn proxy_host(&mut self, proxy_host: String) -> &mut Self {
self.proxy_host = Some(proxy_host);
self
}
pub fn proxy_port(&mut self, proxy_port: String) -> &mut Self {
self.proxy_port = Some(proxy_port);
self
}
pub fn run(&self, _config: &Config) -> crate::error::Result<()> {
let sdk_root = AndroidSdk::sdk_install_path()?;
let sdkmanager_path = sdk_root.join("cmdline-tools").join("bin");
let sdkmanager_bat =
sdkmanager_path.join(format!("sdkmanager{}", super::EXECUTABLE_SUFFIX_BAT));
let mut sdkmanager = std::process::Command::new(sdkmanager_bat);
if let Some(sdk_root) = &self.sdk_root {
sdkmanager.arg(sdk_root);
} else {
sdkmanager.arg(format!("--sdk_root={}", sdk_root.to_str().unwrap()));
}
if let Some(install) = &self.install {
sdkmanager.arg(install);
}
if let Some(uninstall) = &self.uninstall {
sdkmanager.arg("--uninstall").arg(uninstall);
}
if self.update {
sdkmanager.arg("--update");
}
if self.list {
sdkmanager.arg("--list");
}
if self.preferred_tools {
sdkmanager
.arg("build-tools;29.0.0")
.arg("ndk;23.1.7779620")
.arg("platforms;android-30");
}
if let Some(channel) = &self.channel {
sdkmanager.arg(format!("--channel={}", channel));
}
if self.include_obsolete {
sdkmanager.arg("--include_obsolete");
}
if self.no_https {
sdkmanager.arg("--no_https");
}
if self.verbose {
sdkmanager.arg("--verbose");
}
if let Some(http_or_socks) = &self.proxy {
sdkmanager.arg(format!("--proxy={}", http_or_socks));
}
if let Some(ip_or_dns) = &self.proxy_host {
sdkmanager.arg(format!("--proxy_host={}", ip_or_dns));
}
if let Some(port_number) = &self.proxy_port {
sdkmanager.arg(format!("--proxy_port={}", port_number));
}
sdkmanager.output_err(true)?;
Ok(())
}
}