Still getting the same issue
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use std::path::Path;
|
||||
use std::path::{Path, PathBuf};
|
||||
use anyhow::{Result, Context};
|
||||
use indicatif::{ProgressBar, ProgressStyle};
|
||||
use reqwest::blocking::Client;
|
||||
@@ -77,6 +77,32 @@ pub fn install(sdk_path: &Path) -> Result<()> {
|
||||
// Cleanup
|
||||
std::fs::remove_file(&temp_zip)?;
|
||||
|
||||
// The zip extracts to cmdline-tools/ but we need it in cmdline-tools/latest/
|
||||
// This is required by the Android SDK structure
|
||||
let extracted_tools = sdk_path.join("cmdline-tools");
|
||||
let target_location = sdk_path.join("cmdline-tools").join("latest");
|
||||
|
||||
if extracted_tools.exists() && !target_location.exists() {
|
||||
println!("Reorganizing cmdline-tools directory structure...");
|
||||
|
||||
// Create a temporary directory to hold the contents
|
||||
let temp_dir = sdk_path.join("cmdline-tools-temp");
|
||||
std::fs::rename(&extracted_tools, &temp_dir)?;
|
||||
|
||||
// Create the proper structure
|
||||
std::fs::create_dir_all(&target_location)?;
|
||||
|
||||
// Move everything from temp into latest/
|
||||
for entry in std::fs::read_dir(&temp_dir)? {
|
||||
let entry = entry?;
|
||||
let dest = target_location.join(entry.file_name());
|
||||
std::fs::rename(entry.path(), dest)?;
|
||||
}
|
||||
|
||||
// Remove temp directory
|
||||
std::fs::remove_dir_all(&temp_dir)?;
|
||||
}
|
||||
|
||||
// Install required packages
|
||||
install_packages(sdk_path)?;
|
||||
|
||||
@@ -88,56 +114,76 @@ pub fn install(sdk_path: &Path) -> Result<()> {
|
||||
fn install_packages(sdk_path: &Path) -> Result<()> {
|
||||
println!("Installing Android SDK packages...");
|
||||
|
||||
let sdkmanager = sdk_path
|
||||
.join("cmdline-tools/bin/sdkmanager");
|
||||
// Find sdkmanager in the expected location
|
||||
let sdkmanager_path = sdk_path.join("cmdline-tools").join("latest").join("bin");
|
||||
|
||||
let sdkmanager = if cfg!(target_os = "windows") {
|
||||
sdkmanager_path.join("sdkmanager.bat")
|
||||
} else {
|
||||
sdkmanager_path.join("sdkmanager")
|
||||
};
|
||||
|
||||
if !sdkmanager.exists() {
|
||||
// Try alternate location
|
||||
let alt = sdk_path.join("cmdline-tools/latest/bin/sdkmanager");
|
||||
if alt.exists() {
|
||||
return run_sdkmanager(&alt, sdk_path);
|
||||
anyhow::bail!(
|
||||
"sdkmanager not found at expected location: {}\n\
|
||||
Directory structure may be incorrect.",
|
||||
sdkmanager.display()
|
||||
);
|
||||
}
|
||||
|
||||
// Need to move cmdline-tools to correct location
|
||||
let from = sdk_path.join("cmdline-tools");
|
||||
let to = sdk_path.join("cmdline-tools/latest");
|
||||
if from.exists() {
|
||||
std::fs::create_dir_all(sdk_path.join("cmdline-tools"))?;
|
||||
std::fs::rename(&from, &to)?;
|
||||
return run_sdkmanager(&to.join("bin/sdkmanager"), sdk_path);
|
||||
}
|
||||
}
|
||||
println!("Found sdkmanager at: {}", sdkmanager.display());
|
||||
|
||||
run_sdkmanager(&sdkmanager, sdk_path)
|
||||
}
|
||||
|
||||
fn run_sdkmanager(sdkmanager: &Path, sdk_root: &Path) -> Result<()> {
|
||||
use std::process::Command;
|
||||
use std::process::{Command, Stdio};
|
||||
use std::io::Write;
|
||||
|
||||
// Accept licenses
|
||||
let mut yes_cmd = Command::new("yes");
|
||||
let yes_output = yes_cmd.output()?;
|
||||
println!("Accepting licenses...");
|
||||
|
||||
let mut cmd = Command::new(sdkmanager);
|
||||
cmd.arg("--sdk_root")
|
||||
.arg(sdk_root)
|
||||
// Accept licenses
|
||||
let mut license_cmd = Command::new(sdkmanager)
|
||||
.arg(format!("--sdk_root={}", sdk_root.display()))
|
||||
.arg("--licenses")
|
||||
.stdin(std::process::Stdio::piped())
|
||||
.spawn()?
|
||||
.stdin
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.write_all(&yes_output.stdout)?;
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::null())
|
||||
.stderr(Stdio::null())
|
||||
.spawn()
|
||||
.context("Failed to spawn sdkmanager for licenses")?;
|
||||
|
||||
// Write 'y' responses to accept all licenses
|
||||
if let Some(mut stdin) = license_cmd.stdin.take() {
|
||||
// Write enough 'y\n' to accept all licenses (usually 5-6 licenses)
|
||||
for _ in 0..10 {
|
||||
let _ = stdin.write_all(b"y\n");
|
||||
}
|
||||
drop(stdin); // Close stdin so sdkmanager knows we're done
|
||||
}
|
||||
|
||||
let status = license_cmd.wait()
|
||||
.context("Failed to wait for license acceptance")?;
|
||||
|
||||
if !status.success() {
|
||||
println!("{} License acceptance may have failed, continuing anyway...", "⚠".yellow());
|
||||
}
|
||||
|
||||
println!("Installing SDK packages (this may take a few minutes)...");
|
||||
|
||||
// Install packages
|
||||
Command::new(sdkmanager)
|
||||
.arg("--sdk_root")
|
||||
.arg(sdk_root)
|
||||
let status = Command::new(sdkmanager)
|
||||
.arg(format!("--sdk_root={}", sdk_root.display()))
|
||||
.arg("platform-tools")
|
||||
.arg("platforms;android-34")
|
||||
.arg("build-tools;34.0.0")
|
||||
.status()?;
|
||||
.stdout(Stdio::inherit())
|
||||
.stderr(Stdio::inherit())
|
||||
.status()
|
||||
.context("Failed to run sdkmanager for package installation")?;
|
||||
|
||||
if !status.success() {
|
||||
anyhow::bail!("Failed to install Android SDK packages");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user