rust-mobile / cargo-apk

Helps cargo build APKs
Apache License 2.0
109 stars 30 forks source link

Error "NoPlatformFound" has poor description #62

Open hut opened 3 months ago

hut commented 3 months ago

Hi, I just spent >1 hours debugging why cargo apk run tells me "Error: Android SDK has no platforms installed.", even though I had a platform installed.

Finally I found out that this is because of the final filter in the code of ndk.rs:

        let platforms: Vec<u32> = std::fs::read_dir(&platforms_dir)
            .or(Err(NdkError::PathNotFound(platforms_dir)))?
            .filter_map(|path| path.ok())
            .filter(|path| path.path().is_dir())
            .filter_map(|path| path.file_name().into_string().ok())
            .filter_map(|name| {
                name.strip_prefix("android-")
                    .and_then(|api| api.parse::<u32>().ok())
            })
            .filter(|level| (min_platform_level..=max_platform_level).contains(level))
            .collect();

My platform version was simply outside of the range min_platform_level..=max_platform_level. So the problem was not that it has "no platforms installed", but that the installed platform version is incompatible.

Would it be possible to adjust the error message? If you wish, I can make a PR.

P.S. i see that this tool is deprecated. feel free to close the PR without any action then