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 anyhow::{Result, Context};
|
||||||
use indicatif::{ProgressBar, ProgressStyle};
|
use indicatif::{ProgressBar, ProgressStyle};
|
||||||
use reqwest::blocking::Client;
|
use reqwest::blocking::Client;
|
||||||
@@ -77,6 +77,32 @@ pub fn install(sdk_path: &Path) -> Result<()> {
|
|||||||
// Cleanup
|
// Cleanup
|
||||||
std::fs::remove_file(&temp_zip)?;
|
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 required packages
|
||||||
install_packages(sdk_path)?;
|
install_packages(sdk_path)?;
|
||||||
|
|
||||||
@@ -88,56 +114,76 @@ pub fn install(sdk_path: &Path) -> Result<()> {
|
|||||||
fn install_packages(sdk_path: &Path) -> Result<()> {
|
fn install_packages(sdk_path: &Path) -> Result<()> {
|
||||||
println!("Installing Android SDK packages...");
|
println!("Installing Android SDK packages...");
|
||||||
|
|
||||||
let sdkmanager = sdk_path
|
// Find sdkmanager in the expected location
|
||||||
.join("cmdline-tools/bin/sdkmanager");
|
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() {
|
if !sdkmanager.exists() {
|
||||||
// Try alternate location
|
anyhow::bail!(
|
||||||
let alt = sdk_path.join("cmdline-tools/latest/bin/sdkmanager");
|
"sdkmanager not found at expected location: {}\n\
|
||||||
if alt.exists() {
|
Directory structure may be incorrect.",
|
||||||
return run_sdkmanager(&alt, sdk_path);
|
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)
|
run_sdkmanager(&sdkmanager, sdk_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_sdkmanager(sdkmanager: &Path, sdk_root: &Path) -> Result<()> {
|
fn run_sdkmanager(sdkmanager: &Path, sdk_root: &Path) -> Result<()> {
|
||||||
use std::process::Command;
|
use std::process::{Command, Stdio};
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
// Accept licenses
|
println!("Accepting licenses...");
|
||||||
let mut yes_cmd = Command::new("yes");
|
|
||||||
let yes_output = yes_cmd.output()?;
|
|
||||||
|
|
||||||
let mut cmd = Command::new(sdkmanager);
|
// Accept licenses
|
||||||
cmd.arg("--sdk_root")
|
let mut license_cmd = Command::new(sdkmanager)
|
||||||
.arg(sdk_root)
|
.arg(format!("--sdk_root={}", sdk_root.display()))
|
||||||
.arg("--licenses")
|
.arg("--licenses")
|
||||||
.stdin(std::process::Stdio::piped())
|
.stdin(Stdio::piped())
|
||||||
.spawn()?
|
.stdout(Stdio::null())
|
||||||
.stdin
|
.stderr(Stdio::null())
|
||||||
.as_mut()
|
.spawn()
|
||||||
.unwrap()
|
.context("Failed to spawn sdkmanager for licenses")?;
|
||||||
.write_all(&yes_output.stdout)?;
|
|
||||||
|
// 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
|
// Install packages
|
||||||
Command::new(sdkmanager)
|
let status = Command::new(sdkmanager)
|
||||||
.arg("--sdk_root")
|
.arg(format!("--sdk_root={}", sdk_root.display()))
|
||||||
.arg(sdk_root)
|
|
||||||
.arg("platform-tools")
|
.arg("platform-tools")
|
||||||
.arg("platforms;android-34")
|
.arg("platforms;android-34")
|
||||||
.arg("build-tools;34.0.0")
|
.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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user