Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import java.util.zip.ZipException
import java.util.zip.ZipInputStream
import kotlin.io.path.ExperimentalPathApi
import kotlin.io.path.deleteRecursively
import kotlin.io.path.pathString
import kotlin.math.pow

typealias AssetsInstallerProgressConsumer = (AssetsInstallationHelper.Progress) -> Unit
Expand Down Expand Up @@ -176,14 +175,18 @@ object AssetsInstallationHelper {
val freeStorage = getAvailableStorage(File(DEFAULT_ROOT))

val snapshot =
buildString {
entryStatusMap.forEach { (entry, status) ->
appendLine("$entry ${if (status == STATUS_FINISHED) "✓" else ""}")
if (percent >= 99.0) {
"Post install processing in progress...."
} else {
buildString {
entryStatusMap.forEach { (entry, status) ->
appendLine("$entry ${if (status == STATUS_FINISHED) "✓" else ""}")
}
appendLine("--------------------")
appendLine("Progress: ${formatPercent(percent)}")
appendLine("Installed: ${formatBytes(installedSize)} / ${formatBytes(totalSize)}")
appendLine("Remaining storage: ${formatBytes(freeStorage)}")
}
appendLine("--------------------")
appendLine("Progress: ${formatPercent(percent)}")
appendLine("Installed: ${formatBytes(installedSize)} / ${formatBytes(totalSize)}")
appendLine("Remaining storage: ${formatBytes(freeStorage)}")
}

if (snapshot != previousSnapshot) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,86 @@
package com.itsaky.androidide.assets

import android.content.Context
import com.itsaky.androidide.utils.Environment
import org.slf4j.LoggerFactory
import java.io.File
import java.nio.file.Path
import java.util.concurrent.TimeUnit
import com.termux.shared.termux.TermuxConstants
import com.itsaky.androidide.utils.Environment
import kotlin.concurrent.thread
import kotlin.system.measureTimeMillis


abstract class BaseAssetsInstaller : AssetsInstaller {
private val logger = LoggerFactory.getLogger(BaseAssetsInstaller::class.java)

override suspend fun postInstall(
context: Context,
stagingDir: Path
) {
Environment.AAPT2.setExecutable(true)

installNdk(
File(Environment.ANDROID_HOME, Environment.NDK_TAR_XZ),
Environment.ANDROID_HOME
)
}

private fun installNdk(archiveFile: File, outputDir: File): Boolean {
if (!archiveFile.exists()) {
logger.debug("NDK installable package not found: ${archiveFile.absolutePath}")
return false
}

logger.debug("Starting installation of ${archiveFile.absolutePath}")

var exitCode: Int
var result: String
val elapsed = measureTimeMillis {
val processBuilder = ProcessBuilder(
"${TermuxConstants.TERMUX_BIN_PREFIX_DIR_PATH}/bash",
"-c",
"tar -xJf ${archiveFile.absolutePath} -C ${outputDir.absolutePath} --no-same-owner"
)
.redirectErrorStream(true)

val env = processBuilder.environment()
env["PATH"] = "${TermuxConstants.TERMUX_BIN_PREFIX_DIR_PATH}:${env["PATH"]}"

val process = processBuilder.start()

val output = StringBuilder()
val reader = thread(start = true, name = "ndk-extract-output") {
process.inputStream.bufferedReader().useLines { lines ->
lines.forEach { output.appendLine(it) }
}
}

val completed = process.waitFor(2, TimeUnit.MINUTES)
if (!completed) process.destroyForcibly()
reader.join()
result = output.toString()
exitCode = if (completed) process.exitValue() else -1
}

return if (exitCode == 0) {
logger.debug("Extraction of ${archiveFile.absolutePath} successful took ${elapsed}ms : $result")

if (archiveFile.exists()) {
val deleted = archiveFile.delete()
if (deleted) {
logger.debug("${archiveFile.absolutePath} deleted successfully.")
} else {
logger.debug("Failed to delete ${archiveFile.absolutePath}.")
}
deleted
} else {
logger.debug("Archive file not found for deletion.")
false
}
} else {
logger.error("Extraction failed with code $exitCode: $result")
false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ data object BundledAssetsInstaller : BaseAssetsInstaller() {

override fun expectedSize(entryName: String): Long = when (entryName) {
GRADLE_DISTRIBUTION_ARCHIVE_NAME -> 63399283L
ANDROID_SDK_ZIP -> 53226785L
ANDROID_SDK_ZIP -> 254814511L
DOCUMENTATION_DB -> 297763377L
LOCAL_MAVEN_REPO_ARCHIVE_ZIP_NAME -> 97485855L
AssetsInstallationHelper.BOOTSTRAP_ENTRY_NAME -> 124120151L
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ data object SplitAssetsInstaller : BaseAssetsInstaller() {
logger.debug("Completed extracting '{}' to dir: {}", entry.name, destDir)
}

AssetsInstallationHelper.BOOTSTRAP_ENTRY_NAME -> {
AssetsInstallationHelper.BOOTSTRAP_ENTRY_NAME -> {
logger.debug("Extracting 'bootstrap.zip' to dir: {}", stagingDir)

val result = retryOnceOnNoSuchFile(
Expand Down Expand Up @@ -173,7 +173,7 @@ data object SplitAssetsInstaller : BaseAssetsInstaller() {

override fun expectedSize(entryName: String): Long = when (entryName) {
GRADLE_DISTRIBUTION_ARCHIVE_NAME -> 137260932L
ANDROID_SDK_ZIP -> 85024182L
ANDROID_SDK_ZIP -> 286625871L
DOCUMENTATION_DB -> 224296960L
LOCAL_MAVEN_REPO_ARCHIVE_ZIP_NAME -> 215389106L
AssetsInstallationHelper.BOOTSTRAP_ENTRY_NAME -> 456462823L
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ public final class Environment {
"PL", "PT", "RO", "SK", "SI", "ES", "SE"
};

public static final String NDK_TAR_XZ = "ndk-cmake.tar.xz";
public static File NDK_DIR;

public static String getArchitecture() {
return IDEBuildConfigProvider.getInstance().getCpuAbiName();
}
Expand Down Expand Up @@ -176,6 +179,8 @@ public static void init(Context context) {
KEYSTORE_RELEASE = new File(KEYSTORE_DIR, KEYSTORE_RELEASE_NAME);
KEYSTORE_PROPERTIES = new File(KEYSTORE_DIR, KEYSTORE_PROPERTIES_NAME);

NDK_DIR = new File(ANDROID_HOME,"ndk");

isInitialized.set(true);
}

Expand Down