Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 54
NDK support#871
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
NDK support #871
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,15 +1,79 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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.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() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| result = process.inputStream.bufferedReader().use { it.readText() } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val completed = process.waitFor(2, TimeUnit.MINUTES) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| exitCode = if (completed) process.exitValue() else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| process.destroyForcibly() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+49
to
+56
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Timeout is ineffective because output is read before
🔧 Suggested fix (drain output concurrently) import java.util.concurrent.TimeUnit
+import kotlin.concurrent.thread
...
val process = processBuilder.start()
- result = process.inputStream.bufferedReader().use { it.readText() }- val completed = process.waitFor(2, TimeUnit.MINUTES)- exitCode = if (completed) process.exitValue() else {- process.destroyForcibly()- -1- }+ 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📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gate the “post install” message on completion, not percent.
If any
expectedSizeis approximate/zero,percentcan reach 99.99 before all entries are finished, which hides the per‑entry status prematurely. Consider switching the condition to “all entries finished” for a more accurate status.🔧 Suggested adjustment
🤖 Prompt for AI Agents