Skip to content

Commit 90feaa3

Browse files
committed
Alter sdk default path return and bump version
1 parent 0e6a210 commit 90feaa3

File tree

7 files changed

+27
-25
lines changed

7 files changed

+27
-25
lines changed

Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "android-tools"
3-
version = "0.2.10"
3+
version = "0.2.11"
44
edition = "2021"
55
authors = ["DodoRare Team <[email protected]>"]
66
description = "Android-related tools for building and developing applications 🛠"
@@ -14,14 +14,14 @@ thiserror = "1.0"
1414
displaydoc = "0.2"
1515
walkdir = "2.3"
1616
dirs = { version = "4.0.0", optional = true }
17-
which = { version = "4.2.2", optional = true }
17+
which = { version = "4.2.5", optional = true }
1818

1919
[dev-dependencies]
20-
tempfile = "3.2"
20+
tempfile = "3.3"
2121
dunce = "1.0"
2222
zip = "0.5.13"
2323
fs_extra = "1.2"
24-
zip-extensions = "0.6"
24+
zip-extensions = "0.6.1"
2525

2626
[features]
2727
default = ["aapt2", "bundletool", "java-tools", "emulator"]

src/aapt2/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ impl Aapt2Link {
609609
});
610610
} else if let Some(compiled_res) = &self.compiled_res {
611611
let paths = std::fs::read_dir(compiled_res)
612-
.map_err(|_| Error::CompiledResourcesIsNotFound)?
612+
.map_err(|_| Error::CompiledResourcesNotFound)?
613613
.flat_map(|e| e.map(|x| x.path()))
614614
.collect::<Vec<_>>();
615615
paths.iter().for_each(|input| {

src/bundletool/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ pub fn bundletool() -> Result<Command> {
9393
std::env::var("BUNDLETOOL_VERSION").unwrap_or_else(|_| BUNDLETOOL_VERSION.to_string());
9494
let bundletool_file = format!("bundletool-all-{}.jar", env_version);
9595
let bundletool_file_path = dirs::home_dir()
96-
.ok_or_else(|| Error::PathIsNotFound(PathBuf::from("$HOME")))?
96+
.ok_or(Error::UnableToAccessHomeDirectory)?
9797
.join(bundletool_file);
9898
if bundletool_file_path.exists() {
9999
bundletool_init.arg(bundletool_file_path);
100100
} else {
101-
return Err(Error::BundletoolIsNotFound);
101+
return Err(Error::BundletoolNotFound);
102102
}
103103
}
104104
Ok(bundletool_init)

src/error.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ pub type Result<T> = std::result::Result<T, Error>;
99
#[derive(Display, Debug, Error)]
1010
pub enum Error {
1111
/// Android SDK or Android NDK is not found. Check the installation path or use crossbundle install command to install it
12-
AndroidToolIsNotFound,
12+
AndroidToolNotFound,
1313
/// Android SDK is not found. Check the installation path or use crossbundle install command to install it
14-
AndroidSdkIsNotFound,
14+
AndroidSdkNotFound,
1515
/// Bundletool is not found. Check the installation path or use crossbundle install command to install it
16-
BundletoolIsNotFound,
16+
BundletoolNotFound,
1717
/// Unable to access to home directory or home directory doesn't exists
18-
HomeDirectoryUnableToAccess,
18+
UnableToAccessHomeDirectory,
1919
/// Path {0:?} doesn't exists
20-
PathIsNotFound(PathBuf),
20+
PathNotFound(PathBuf),
2121
/// Command {0} is not found
22-
CmdIsNotFound(String),
22+
CmdNotFound(String),
2323
/// Command had a non-zero exit code. Stdout: {0} Stderr: {1}
2424
CmdFailed(String, String),
2525
/// Compiled resources is not found
26-
CompiledResourcesIsNotFound,
26+
CompiledResourcesNotFound,
2727
/// IO error
2828
Io(#[from] std::io::Error),
2929
}

src/java_tools/jarsigner.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -484,5 +484,5 @@ fn jarsigner_tool() -> Result<Command> {
484484
return Ok(Command::new(keytool));
485485
}
486486
}
487-
Err(Error::CmdIsNotFound("jarsigner".to_string()))
487+
Err(Error::CmdNotFound("jarsigner".to_string()))
488488
}

src/java_tools/keytool.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ pub fn keytool() -> Result<Command> {
948948
return Ok(Command::new(keytool));
949949
}
950950
}
951-
Err(Error::CmdIsNotFound("keytool".to_string()))
951+
Err(Error::CmdNotFound("keytool".to_string()))
952952
}
953953

954954
#[derive(Clone)]
@@ -1046,7 +1046,7 @@ impl Key {
10461046
/// Returns or crates it if needed the path to `.android` in the user's home directory.
10471047
pub fn android_dir() -> Result<PathBuf> {
10481048
let android_dir = dirs::home_dir()
1049-
.ok_or_else(|| Error::PathIsNotFound(PathBuf::from("$HOME")))?
1049+
.ok_or(Error::UnableToAccessHomeDirectory)?
10501050
.join(".android");
10511051
std::fs::create_dir_all(&android_dir)?;
10521052
Ok(android_dir)

src/lib.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,21 @@ pub fn sdk_path_from_env() -> crate::error::Result<PathBuf> {
3232
.ok()
3333
.or_else(|| std::env::var("ANDROID_SDK_PATH").ok())
3434
.or_else(|| std::env::var("ANDROID_HOME").ok());
35-
std::path::PathBuf::from(
36-
sdk_path.unwrap_or(sdk_install_path()?.to_str().unwrap().to_string()),
37-
)
35+
if let Some(path) = sdk_path {
36+
std::path::PathBuf::from(path)
37+
} else {
38+
sdk_install_path()?
39+
}
3840
};
41+
if !sdk_path.exists() {
42+
return Err(Error::AndroidSdkNotFound)?;
43+
}
3944
Ok(sdk_path)
4045
}
4146

4247
/// Default installation path
4348
pub fn sdk_install_path() -> crate::error::Result<PathBuf> {
44-
let home_dir_path = dirs::home_dir().ok_or(Error::HomeDirectoryUnableToAccess)?;
49+
let home_dir_path = dirs::home_dir().ok_or(Error::UnableToAccessHomeDirectory)?;
4550
#[cfg(target_os = "windows")]
4651
let path = std::path::Path::new("Local").join("Android").join("Sdk");
4752
#[cfg(target_os = "macos")]
@@ -57,9 +62,6 @@ pub fn sdk_install_path() -> crate::error::Result<PathBuf> {
5762
#[cfg(not(target_os = "windows"))]
5863
let sdk_path = home_dir_path.join(path);
5964

60-
if !sdk_path.exists() {
61-
return Err(Error::AndroidSdkIsNotFound)?;
62-
}
6365
Ok(sdk_path)
6466
}
6567

@@ -70,6 +72,6 @@ pub fn find_max_version(target_dir: &std::path::Path) -> crate::error::Result<St
7072
.filter_map(|path| path.file_name().into_string().ok())
7173
.filter(|name| name.chars().next().unwrap().is_ascii_digit())
7274
.max()
73-
.ok_or(Error::AndroidToolIsNotFound)?;
75+
.ok_or(Error::AndroidToolNotFound)?;
7476
Ok(max_version)
7577
}

0 commit comments

Comments
 (0)