Skip to content
2 changes: 1 addition & 1 deletion ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ These structural facts shape every module. Day-to-day build *commands* live in `
- **ABI product flavors.** Every Android module *except* `:plugin-api` and `:subprojects:sqlite-js` gets two flavors on the `abi` dimension — `v7` (`armeabi-v7a`) and `v8` (`arm64-v8a`) — defined centrally. There is no flavorless variant; tasks are `assembleV8Debug`, `assembleV7Release`, etc.
- **SDK levels** (`build-logic/.../build/config/BuildConfig.kt`): `COMPILE_SDK=36`, `MIN_SDK=28`, `TARGET_SDK=28`. **`TARGET_SDK` is deliberately pinned at 28:** higher targets enforce W^X (write-xor-execute), which blocks executing code from app-writable files. That is fatal for an on-device IDE that compiles and runs code (Gradle, `javac`, Termux binaries), so it is a hard requirement, not tech debt. `MIN_SDK_FOR_APPS_BUILT_WITH_COGO=16` is the floor for the apps a *user* builds with CoGo — distinct from CoGo's own `MIN_SDK`.
- **Native asset bundling.** The on-device LLM (`llama-impl`) ships as a per-flavor native AAR, wired through the root `build.gradle.kts` (`bundleLlamaV8Assets` / `assembleV8Assets`, …); prebuilt per-flavor assets live under `assets/release/v7/` and `assets/release/v8/`.
- **Bundled add-ons** (ADFA-7238). A build is *fat* when `assets/plugins/*.cgp` and `assets/templates/*.cgt` exist in the repo root: release builds put them in the APK assets as `plugins/<name>` and `templates/<name>` (`StageBundledAddons` in `app/build.gradle.kts`), and `createAssetsZip()` adds the same entries to the debug `assets-<arch>.zip`. Both also write the bundle index `bundled-addons.tsv` (one line per add-on: entry name, size, SHA-256; empty in a thin build), so the app lists and fingerprints the bundle without opening an add-on, which a release APK stores compressed, and a rebuilt add-on of the same size changes the fingerprint. A bundle without a valid index, such as an older debug zip, is listed from its folders by name and size. A missing or empty folder is the thin build. First-run setup (`AssetsInstallationHelper`) lists the bundle (`assets/addons/BundledAddons`), installs each file in the same parallel phase through `BundledAddonInstaller` (scratch file, then rename; a plugin lands in `filesDir/plugins` as `<pluginId>-<hash>.cgp`, a template in `Environment.TEMPLATES_DIR`; a copy whose SHA-256 differs from the index is rejected and reported like a plugin with no readable manifest), and writes `filesDir/bundled_addons.properties` last (`BundledAddonsRecord`: bundle fingerprint, bundled plugin IDs and template files, plugin load failures not yet reported to the user). `InstallationViewModel` then reloads the plugins once, and `MainActivity` shows one error bar for the recorded failures.
- **Bundled add-ons** (ADFA-7238). A build is *fat* when `assets/plugins/*.cgp` and `assets/templates/*.cgt` exist in the repo root: release builds put them in the APK assets as `plugins/<name>` and `templates/<name>` (`StageBundledAddons` in `app/build.gradle.kts`), and `createAssetsZip()` adds the same entries to the debug `assets-<arch>.zip`. Both also write the bundle index `bundled-addons.tsv` (one line per add-on: entry name, size, SHA-256; empty in a thin build), so the app lists and fingerprints the bundle without opening an add-on, which a release APK stores compressed, and a rebuilt add-on of the same size changes the fingerprint. A bundle without a valid index, such as an older debug zip, is listed from its folders by name and size. A missing or empty folder is the thin build. First-run setup (`AssetsInstallationHelper`) lists the bundle (`assets/addons/BundledAddons`), installs each file in the same parallel phase through `BundledAddonInstaller` (scratch file, then rename; a plugin lands in `filesDir/plugins` as `<pluginId>-<hash>.cgp`, a template in `Environment.TEMPLATES_DIR`; a copy whose SHA-256 differs from the index is rejected and reported like a plugin with no readable manifest), and writes `filesDir/bundled_addons.properties` last (`BundledAddonsRecord`: bundle fingerprint, bundled plugin IDs and template files, plugin load failures not yet reported to the user). `InstallationViewModel` then reloads the plugins once, and `MainActivity` shows one error bar for the recorded failures. The Add-ons Manager reads the same record to warn (ADFA-7240) before it uninstalls or disables a bundled plugin, or uninstalls a bundled template; the record is not changed by either.
- **sqlite-js for apps built with CoGo** (ADFA-7082). `subprojects:sqlite-js` builds the AAR that the JavaScript-in-SQLite project template depends on: the sqlite-js release vendored (see its README), for arm64-v8a and armeabi-v7a, minSdk 26, without core-library desugaring. Nothing in CoGo depends on it. Its default entry point runs no code stored in a database; loading stored functions is a separate entry point, only for databases the app made, since loading runs their code. `test-sqlite-js.yml` runs its host tests on pull requests. The manual `release-sqlite-js.yml` publishes it to the moving `sqlite-js-latest` release, from which dev-assets fetches it into the template, as it fetches `plugin-api-latest` for the plugin template.
- **Native lib compression** (ADFA-2306, ADFA-4729). The app manifest hard-codes `android:extractNativeLibs="true"` (required: the installer must materialize libs in `nativeLibraryDir`, e.g. `libshizuku.so` is an executable the adb shell runs from there). That attribute overrides the `jniLibs.useLegacyPackaging` DSL, so AGP packages `lib/<abi>/*.so` deflate-compressed in **every** APK — ~5.9 MB smaller (`libtree-sitter-kotlin.so` alone is 4.18 MB → 339 kB). The trap is the `recompressApk` post-step (release always, debug in CI only): its no-compress lists in `app/build.gradle.kts` must NOT contain `"so"`, or it silently re-stores the libs and undoes the saving — which is what ADFA-2306 fixed for release and ADFA-4729 for CI debug. Locally built debug APKs (including the e2e farm's) never run that step and were always fine.
- **Quick Build shares the Gradle distribution's toolchain** (ADFA-4931). `:app`'s `quickBuildDaemonZip` leaves the Kotlin compiler and eight other jars out of the daemon zip, because the on-device Gradle distribution already carries them; `QuickBuildArtifactStager` links them in at provision time. That makes the daemon's Kotlin version the distribution's, so `:quickbuild:daemon` takes its Kotlin artifacts at `org.adfa.constants.GRADLE_DISTRIBUTION_KOTLIN_VERSION`, and `:app:quickBuildDistJarCheck` fails the build when the distribution it packages lacks a linked jar. See [ADR 0016](docs/adr/0016-quick-build-compiles-outside-gradle.md).
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/com/itsaky/androidide/di/PluginModule.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.itsaky.androidide.di

import com.itsaky.androidide.app.IDEApplication
import com.itsaky.androidide.assets.addons.BundledAddonsRecord
import com.itsaky.androidide.preferences.internal.BuildPreferences
import com.itsaky.androidide.repositories.DownloadFilesRepository
import com.itsaky.androidide.repositories.DownloadFilesRepositoryImpl
Expand Down Expand Up @@ -53,6 +54,13 @@ val pluginModule =
filesDir = IDEApplication.cachedFilesDir,
connectivityObserver = get(),
isOfflineModeEnabled = { BuildPreferences.isOfflineEnabled },
isBundledPlugin = { id ->
BundledAddonsRecord
.inFilesDir(IDEApplication.cachedFilesDir)
.read()
?.pluginIds
?.contains(id) == true
},
)
}

Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/com/itsaky/androidide/di/TemplateModule.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.itsaky.androidide.di

import com.itsaky.androidide.app.IDEApplication
import com.itsaky.androidide.assets.addons.BundledAddonsRecord
import com.itsaky.androidide.repositories.TemplateCollectionRepository
import com.itsaky.androidide.repositories.TemplateRepository
import com.itsaky.androidide.repositories.TemplateRepositoryImpl
Expand Down Expand Up @@ -27,6 +29,13 @@ val templateModule =
TemplateManagerViewModel(
templateRepository = get(),
collectionInstalls = get<TemplateCollectionRepository>().installs,
isBundledTemplate = { fileName ->
BundledAddonsRecord
.inFilesDir(IDEApplication.cachedFilesDir)
.read()
?.templateFiles
?.contains(fileName) == true
},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ private sealed interface PluginManagerDialogState : Parcelable {
@Parcelize
data class UninstallConfirm(
val pluginId: String,
val bundled: Boolean,
) : PluginManagerDialogState

@Parcelize
data class DisableConfirm(
val pluginId: String,
val pluginName: String,
) : PluginManagerDialogState

@Parcelize
Expand Down Expand Up @@ -167,7 +174,11 @@ fun PluginManagerContent(
}

is PluginManagerUiEffect.ShowUninstallConfirmation -> {
dialogState = PluginManagerDialogState.UninstallConfirm(effect.plugin.metadata.id)
dialogState = PluginManagerDialogState.UninstallConfirm(effect.plugin.metadata.id, effect.bundled)
}

is PluginManagerUiEffect.ShowDisableConfirmation -> {
dialogState = PluginManagerDialogState.DisableConfirm(effect.pluginId, effect.pluginName)
}

is PluginManagerUiEffect.ShowRestartPrompt -> {
Expand Down Expand Up @@ -254,6 +265,7 @@ fun PluginManagerContent(
if (plugin != null) {
UninstallConfirmationDialog(
plugin = plugin,
bundled = dialog.bundled,
onConfirm = {
viewModel.confirmUninstallPlugin(plugin.metadata.id)
dialogState = PluginManagerDialogState.None
Expand All @@ -263,6 +275,18 @@ fun PluginManagerContent(
}
}

is PluginManagerDialogState.DisableConfirm -> {
// Carries its own name, so it shows even while the plugin list reloads.
DisableBundledPluginDialog(
pluginName = dialog.pluginName,
onConfirm = {
viewModel.confirmDisablePlugin(dialog.pluginId)
dialogState = PluginManagerDialogState.None
},
onDismiss = { dialogState = PluginManagerDialogState.None },
)
}

is PluginManagerDialogState.Details -> {
val plugin = uiState.plugins.firstOrNull { it.metadata.id == dialog.pluginId }
if (plugin != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,53 @@ fun UninstallConfirmationDialog(
plugin: PluginInfo,
onConfirm: () -> Unit,
onDismiss: () -> Unit,
bundled: Boolean = false,
) {
AlertDialog(
onDismissRequest = onDismiss,
title = { Text(stringResource(R.string.title_uninstall_plugin)) },
text = { Text(stringResource(R.string.msg_uninstall_plugin_confirm, plugin.metadata.name)) },
title = {
Text(stringResource(if (bundled) R.string.title_uninstall_bundled_plugin else R.string.title_uninstall_plugin))
},
// AlertDialog's text slot does not scroll; at 2x font scale the text would clip.
text = {
Text(
if (bundled) {
stringResource(R.string.msg_uninstall_bundled_plugin_confirm, plugin.metadata.name)
} else {
stringResource(R.string.msg_uninstall_plugin_confirm, plugin.metadata.name)
},
modifier = Modifier.verticalScroll(rememberScrollState()),
)
},
confirmButton = {
TextButton(onClick = onConfirm) {
Text(stringResource(if (bundled) R.string.action_continue else R.string.uninstall_plugin))
}
},
dismissButton = {
TextButton(onClick = onDismiss) { Text(stringResource(android.R.string.cancel)) }
},
)
}

/** Disabling a plugin that came with the app can break the installation (ADFA-7240). */
@Composable
fun DisableBundledPluginDialog(
pluginName: String,
onConfirm: () -> Unit,
onDismiss: () -> Unit,
) {
AlertDialog(
onDismissRequest = onDismiss,
title = { Text(stringResource(R.string.title_disable_bundled_plugin)) },
text = {
Text(
stringResource(R.string.msg_disable_bundled_plugin_confirm, pluginName),
modifier = Modifier.verticalScroll(rememberScrollState()),
)
},
confirmButton = {
TextButton(onClick = onConfirm) { Text(stringResource(R.string.uninstall_plugin)) }
TextButton(onClick = onConfirm) { Text(stringResource(R.string.action_continue)) }
},
dismissButton = {
TextButton(onClick = onDismiss) { Text(stringResource(android.R.string.cancel)) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,28 @@ fun UninstallTemplateConfirmationDialog(
item: CgtFileItem,
onConfirm: () -> Unit,
onDismiss: () -> Unit,
bundled: Boolean = false,
) {
AlertDialog(
onDismissRequest = onDismiss,
title = { Text(stringResource(R.string.title_uninstall_template)) },
title = {
Text(stringResource(if (bundled) R.string.title_uninstall_bundled_template else R.string.title_uninstall_template))
},
// AlertDialog's text slot does not scroll; a long file name at 2x font scale would clip.
text = {
Text(
stringResource(R.string.msg_uninstall_template_confirm, item.displayName),
if (bundled) {
stringResource(R.string.msg_uninstall_bundled_template_confirm, item.displayName)
} else {
stringResource(R.string.msg_uninstall_template_confirm, item.displayName)
},
modifier = Modifier.verticalScroll(rememberScrollState()),
)
},
confirmButton = {
TextButton(onClick = onConfirm) { Text(stringResource(R.string.action_uninstall_template)) }
TextButton(onClick = onConfirm) {
Text(stringResource(if (bundled) R.string.action_continue else R.string.action_uninstall_template))
}
},
dismissButton = {
TextButton(onClick = onDismiss) { Text(stringResource(android.R.string.cancel)) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ private sealed interface TemplateManagerDialogState : Parcelable {
@Parcelize
data class UninstallConfirm(
val path: String,
val bundled: Boolean,
) : TemplateManagerDialogState

@Parcelize
Expand Down Expand Up @@ -165,7 +166,7 @@ fun TemplateManagerScreen(
}

is TemplateManagerUiEffect.ShowUninstallConfirmation -> {
dialogState = TemplateManagerDialogState.UninstallConfirm(effect.item.file.absolutePath)
dialogState = TemplateManagerDialogState.UninstallConfirm(effect.item.file.absolutePath, effect.bundled)
}

is TemplateManagerUiEffect.ShowDeleteConfirmation -> {
Expand Down Expand Up @@ -239,6 +240,7 @@ fun TemplateManagerScreen(
if (item != null) {
UninstallTemplateConfirmationDialog(
item = item,
bundled = dialog.bundled,
onConfirm = {
viewModel.confirmUninstallTemplate(item)
dialogState = TemplateManagerDialogState.None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,19 @@ sealed class PluginManagerUiEffect {
val source: PluginInstallSource,
) : PluginManagerUiEffect()

/** [bundled]: the plugin came with the app (ADFA-7240), so the dialog warns about removing it. */
data class ShowUninstallConfirmation(
val plugin: PluginInfo,
val bundled: Boolean,
) : PluginManagerUiEffect()

/**
* Sent instead of disabling at once, for a plugin that came with the app (ADFA-7240).
* [pluginName] is the plugin's name, or its ID when the loaded list does not have it.
*/
data class ShowDisableConfirmation(
val pluginId: String,
val pluginName: String,
) : PluginManagerUiEffect()

object ShowRestartPrompt : PluginManagerUiEffect()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ sealed class TemplateManagerUiEffect {
val item: CgtFileItem,
) : TemplateManagerUiEffect()

/** [bundled]: the template came with the app (ADFA-7240), so the dialog warns about removing it. */
data class ShowUninstallConfirmation(
val item: CgtFileItem,
val bundled: Boolean,
) : TemplateManagerUiEffect()

data class ShowDeleteConfirmation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class PluginManagerViewModel(
private val connectivityObserver: ConnectivityObserver,
// Gradle's offline mode (Build & Run preferences). A function so tests need no preferences.
private val isOfflineModeEnabled: () -> Boolean,
// Whether the plugin came with the app (ADFA-7240). Reads a file, so it is called from IO only.
private val isBundledPlugin: (String) -> Boolean,
) : ViewModel() {
private companion object {
private const val TAG = "PluginManagerViewModel"
Expand Down Expand Up @@ -145,7 +147,7 @@ class PluginManagerViewModel(
}

is PluginManagerUiEvent.DisablePlugin -> {
disablePlugin(event.pluginId)
showDisableConfirmationIfBundled(event.pluginId)
}

is PluginManagerUiEvent.UninstallPlugin -> {
Expand Down Expand Up @@ -267,9 +269,29 @@ class PluginManagerViewModel(
}

/**
* Disable a plugin
* A plugin that came with the app asks for confirmation first; any other disables at once.
* Decided by ID, not by the loaded list, so a list being reloaded cannot skip the warning; the
* list only supplies the name, and the ID stands in when it lacks the plugin.
*/
private fun disablePlugin(pluginId: String) {
private fun showDisableConfirmationIfBundled(pluginId: String) {
viewModelScope.launch {
if (withContext(Dispatchers.IO) { isBundledPlugin(pluginId) }) {
val name =
_uiState.value.plugins
.find { it.metadata.id == pluginId }
?.metadata
?.name ?: pluginId
_uiEffect.send(PluginManagerUiEffect.ShowDisableConfirmation(pluginId, name))
} else {
confirmDisablePlugin(pluginId)
}
}
}

/**
* Disable a plugin (called after confirmation, or directly for a plugin the user added)
*/
fun confirmDisablePlugin(pluginId: String) {
viewModelScope.launch {
_currentOperation.value = PluginOperation.Disabling(pluginId)

Expand Down Expand Up @@ -305,7 +327,8 @@ class PluginManagerViewModel(
val plugin = _uiState.value.plugins.find { it.metadata.id == pluginId }
if (plugin != null) {
viewModelScope.launch {
_uiEffect.send(PluginManagerUiEffect.ShowUninstallConfirmation(plugin))
val bundled = withContext(Dispatchers.IO) { isBundledPlugin(pluginId) }
_uiEffect.send(PluginManagerUiEffect.ShowUninstallConfirmation(plugin, bundled))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.itsaky.androidide.templates.manager.models.displayName
import com.itsaky.androidide.ui.models.TemplateManagerUiEffect
import com.itsaky.androidide.ui.models.TemplateManagerUiEvent
import com.itsaky.androidide.ui.models.TemplateManagerUiState
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.Flow
Expand All @@ -19,13 +20,16 @@ import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

/**
* ViewModel for the Templates tab. Same UDF shape as [PluginManagerViewModel].
*/
class TemplateManagerViewModel(
private val templateRepository: TemplateRepository,
collectionInstalls: Flow<Unit>,
// Whether an installed template file (by file name) came with the app (ADFA-7240). Reads a file, so IO only.
private val isBundledTemplate: (String) -> Boolean,
) : ViewModel() {
private companion object {
private const val TAG = "TemplateManagerViewModel"
Expand Down Expand Up @@ -138,7 +142,8 @@ class TemplateManagerViewModel(

private fun showUninstallConfirmation(item: CgtFileItem) {
viewModelScope.launch {
_uiEffect.send(TemplateManagerUiEffect.ShowUninstallConfirmation(item))
val bundled = item.installed && withContext(Dispatchers.IO) { isBundledTemplate(item.file.name) }
_uiEffect.send(TemplateManagerUiEffect.ShowUninstallConfirmation(item, bundled))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class PluginManagerViewModelSourceDeleteTest {
override fun observe() = flowOf(true)
},
isOfflineModeEnabled = { false },
isBundledPlugin = { false },
)

private fun downloadedPlugin(): File = File(tempFolder.newFolder("Download"), "my-plugin.cgp").apply { writeText("cgp") }
Expand Down
Loading
Loading