Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
e6b2e26
ADFA-7138 Add sqlite-rewrite-runtime, the helpers the requery rewrite…
davidschachterADFA Nov 16, 2026
e392fe9
ADFA-7138 Rewrite android.database.sqlite to requery in the Gradle pl…
davidschachterADFA Nov 16, 2026
0c28568
ADFA-7138 Code on the Go injects the rewrite runtime AAR and checks t…
davidschachterADFA Nov 16, 2026
b65e593
ADFA-7138 Add the SQLite debugger AAR to debuggable variants when opt…
davidschachterADFA Nov 16, 2026
2a5cb6d
ADFA-7138 Apply the rewrite and the debugger from one opt-in property
davidschachterADFA Nov 16, 2026
9dc56f0
ADFA-7138 Do not apply or provision Quick Build for a project that op…
davidschachterADFA Nov 16, 2026
dd570d4
ADFA-7138 Add a script that checks an APK carries no SQLite debugger
davidschachterADFA Nov 16, 2026
4a9bc95
ADFA-7138 Docs: describe the SQLite rewrite and the Gradle wiring
davidschachterADFA Nov 16, 2026
2c78e0a
ADFA-7138 Quick Build opt-in check reads the sources Gradle's findPro…
davidschachterADFA Nov 16, 2026
4e4718f
ADFA-7138 Fail the build when a variant's runtime classpath cannot be…
davidschachterADFA Nov 16, 2026
3605133
ADFA-7138: Merge ADFA-7135 (with #2244's sqlite-js 1.4.3) up the stack
davidschachterADFA Nov 16, 2026
627aa94
ADFA-7138: Say how to turn the SQLite debugger on in an app
davidschachterADFA Nov 16, 2026
2394a80
ADFA-7138: Say how to build when the rewrite fails on a library class
davidschachterADFA Nov 16, 2026
810fe1c
ADFA-7138: Merge ADFA-7135 (README corrections) up the stack
davidschachterADFA Nov 16, 2026
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
5 changes: 3 additions & 2 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Strategy: **layer-and-subsystem based**, not feature-by-feature. The Gradle buil

- **`app` depends inward; libraries never depend on `app`.** Subsystems are consumed by `app`, not vice versa.
- **Vendored forks are substituted, not imported ad hoc.** `composite-builds/build-deps` and `build-deps-common` provide forked `javac`/`jdt`/`layoutlib`/etc.; `settings.gradle.kts` substitutes them in for `com.itsaky.androidide.build:*`. Don't add a Maven coordinate for something already substituted. Pebble is likewise built from source, as `subprojects:pebble`, for a lexer fix Android needs (its `NOTICE` says what changed); depend on `projects.subprojects.pebble`, not `io.pebbletemplates:pebble`.
- **All module config flows through `composite-builds/build-logic`.** Every Android module gets the `v7`/`v8` ABI flavors centrally (`AndroidModuleConf.kt`) — there is no flavorless `assembleDebug`. `:plugin-api`, `:subprojects:sqlite-js` and `:subprojects:sqlite-debugger`, libraries for other projects that need one artifact, are intentionally excluded from flavors.
- **All module config flows through `composite-builds/build-logic`.** Every Android module gets the `v7`/`v8` ABI flavors centrally (`AndroidModuleConf.kt`) — there is no flavorless `assembleDebug`. `:plugin-api`, `:subprojects:sqlite-js`, `:subprojects:sqlite-debugger` and `:subprojects:sqlite-rewrite-runtime`, libraries for other projects that need one artifact, are intentionally excluded from flavors.
- **`RepositoriesMode.FAIL_ON_PROJECT_REPOS`** — repositories are declared once in `settings.gradle.kts`; modules must not declare their own.
- **Avoid new dependencies.** Check `gradle/libs.versions.toml` first; the build almost certainly already has it.

Expand All @@ -104,11 +104,12 @@ Strategy: **layer-and-subsystem based**, not feature-by-feature. The Gradle buil
These structural facts shape every module. Day-to-day build *commands* live in `CLAUDE.md`; the rules that produce them live here.

- **Centralized convention logic.** All Android module setup flows through `composite-builds/build-logic` (`conf/AndroidModuleConf.kt`). Modules stay thin and share configuration, so understanding any module's setup starts here.
- **ABI product flavors.** Every Android module *except* `:plugin-api`, `:subprojects:sqlite-js` and `:subprojects:sqlite-debugger` 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.
- **ABI product flavors.** Every Android module *except* `:plugin-api`, `:subprojects:sqlite-js`, `:subprojects:sqlite-debugger` and `:subprojects:sqlite-rewrite-runtime` 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/`.
- **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.
- **SQLite debugger for apps built with CoGo** (ADFA-7131). `subprojects:sqlite-debugger` builds an AAR with a debug-only SQLite debugger and MCP server for apps built with CoGo: a native extension on requery's SQLite plus a loopback HTTP server. Like sqlite-js it has no ABI flavors, and nothing in CoGo depends on it; see its README.
- **AARs bundled for apps built with CoGo.** `:logsender`, `:subprojects:sqlite-debugger` and `:subprojects:sqlite-rewrite-runtime` are built as AARs and bundled into the IDE's assets (`AndroidIDEAssetsPlugin`). Code on the Go extracts them and passes their paths to Gradle as properties, and its Gradle plugin injects each into the app: logsender and the debugger into debuggable variants, the rewrite runtime into every variant of a project with `cogo.sqliteDebugger=true`. `:subprojects:sqlite-rewrite-runtime` is Java-only, has no ABI flavors and holds the helpers the build-time rewrite to requery redirects to (ADFA-7138); see `gradle-plugin/docs/sqlite-rewrite.md`.
- **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).
- **`app` package layout is by concern, not feature:** `activities`, `fragments`, `services`, `di`, `agent`, `viewmodel(s)`, `repositories`, `roomData`, `localWebServer`, `preferences`, `ui` (Compose screens live under `ui/compose`), `templates/manager` (the Manager screen's `.cgt`-parsing data layer, with direct filesystem access to `Environment.TEMPLATES_DIR` — distinct from the plugin-facing `IdeTemplateService` in `plugin-api`/`plugin-manager`), `utils`, ….
Expand Down
4 changes: 2 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ flox activate -d flox/local -- ./gradlew <task>
```

- **Debug APK (arm64, the usual target):** `flox activate -d flox/local -- ./gradlew :app:assembleV8Debug --parallel --max-workers=6`
- **Module unit tests:** `flox activate -d flox/local -- ./gradlew :editor:testV7DebugUnitTest` - unit tests are per-flavor, there is no plain `test` task. `:plugin-api`, `:subprojects:sqlite-js` and `:subprojects:sqlite-debugger` are the modules without flavors: `:plugin-api:testDebugUnitTest`.
- **Module unit tests:** `flox activate -d flox/local -- ./gradlew :editor:testV7DebugUnitTest` - unit tests are per-flavor, there is no plain `test` task. `:plugin-api`, `:subprojects:sqlite-js`, `:subprojects:sqlite-debugger` and `:subprojects:sqlite-rewrite-runtime` are the modules without flavors: `:plugin-api:testDebugUnitTest`.
- **Single unit test:** append `--tests "com.itsaky.androidide.SomeTest"` to the flavored task above.
- **Fast iteration:** during multi-file/multi-module changes, verify with targeted `:module:compileV8DebugKotlin`/`compileV8DebugJavaWithJavac` invocations (batch several modules into one Gradle call) rather than a full assemble. Reserve `:app:assembleV8Debug` for final end-to-end verification — it's slow (multi-minute) in this multi-module project, and running it after every small change adds up.
- **Long-running commands: narrate them, and background only the read-only ones.** Anything that can exceed ~60s — `assembleV8Debug`, a full test sweep, a cold Gradle invocation of any kind (daemon start plus configuring this many modules is ~20s before any task runs, and far worse under memory pressure), and `git push`, which runs Spotless through the hook — gets a line before it starts saying what is running and roughly how long it takes, and a status line every couple of minutes while it runs: elapsed time, the last output line, whether it is still progressing. A silent terminal is indistinguishable from a hang, and saying which it is is your job, not the user's to ask.
Expand All @@ -26,7 +26,7 @@ When the user names a CI/CD job ("the sonar job", "the analyze workflow"), read

### ABI product flavors (v7 / v8)

Every module except `:plugin-api`, `:subprojects:sqlite-js` and `:subprojects:sqlite-debugger` carries `v7` (`armeabi-v7a`) and `v8` (`arm64-v8a`) flavors, so build tasks are `assembleV8Debug`, `assembleV7Release`, etc. — there is **no** flavorless `assembleDebug`. Those three build one artifact for other projects. See [ARCHITECTURE.md](ARCHITECTURE.md) (Build & Module Configuration) for flavors, native asset bundling, and SDK levels.
Every module except `:plugin-api`, `:subprojects:sqlite-js`, `:subprojects:sqlite-debugger` and `:subprojects:sqlite-rewrite-runtime` carries `v7` (`armeabi-v7a`) and `v8` (`arm64-v8a`) flavors, so build tasks are `assembleV8Debug`, `assembleV7Release`, etc. — there is **no** flavorless `assembleDebug`. Those four build one artifact for other projects. See [ARCHITECTURE.md](ARCHITECTURE.md) (Build & Module Configuration) for flavors, native asset bundling, and SDK levels.

### Emulator / device

Expand Down
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,9 @@ dependencies {
// (QuickBuildArtifactStager).
evaluationDependsOn(":quickbuild:runtime")
evaluationDependsOn(":quickbuild:daemon")
// The assets plugin bundles its release AAR (ADFA-7131).
evaluationDependsOn(":subprojects:sqlite-debugger")
evaluationDependsOn(":subprojects:sqlite-rewrite-runtime")

// ADFA-4931: jars the daemon loads from the on-device Gradle distribution instead of shipping its
// own copy, since `gradle-dists/` and `quickbuild/` both sit under <ANDROIDIDE_HOME>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.itsaky.androidide.tooling.api.messages.BuildRunType
import com.itsaky.androidide.tooling.api.messages.GradleBuildParams
import com.itsaky.androidide.tooling.api.messages.TaskExecutionMessage
import com.itsaky.androidide.tooling.api.messages.result.TaskExecutionResult
import com.itsaky.androidide.utils.Environment
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
Expand Down Expand Up @@ -340,11 +341,27 @@ class GradleQuickBuildProvisioner(
log.info("A Gradle build is already in progress; not staging for the Quick Build proxy app build")
return ProxyAppBuildResult.SlotBusy
}
stage(context, paths)

val projectManager = lookupProjectManager()
val projectRoot = File(projectManager.projectDirPath)

// Before staging, which writes into the project: the Gradle plugin never applies Quick Build
// to an opted-in project, so building would only end in "variant setup missing".
QuickBuildProjectSupport
.sqliteDebuggerMessage(
QuickBuildProjectSupport.isSqliteDebuggerEnabled(
projectRoot,
Environment.GRADLE_USER_HOME,
projectManager.getAndroidAppModules().map { File(it.projectDirPath) },
),
)?.let { refusal ->
log.info(
"Quick Build is not provisioned: {} is true in the project's or the Gradle user home's gradle.properties",
GradlePluginConfig.PROPERTY_SQLITE_DEBUGGER_ENABLED,
)
return ProxyAppBuildResult.Failed(context.getString(refusal))
}
stage(context, paths)

// The project model only exists once CoGo's Gradle sync has populated it, and a tap
// during sync is common (the user opens a project and reaches straight for Quick
// Build). Queue behind the sync rather than failing: the session is already in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ package com.itsaky.androidide.quickbuild

import androidx.annotation.StringRes
import com.itsaky.androidide.resources.R
import com.itsaky.androidide.tooling.api.GradlePluginConfig
import org.slf4j.LoggerFactory
import java.io.File
import java.io.IOException
import java.io.StringReader
import java.util.Properties

/**
* The reasons Quick Build refuses a project up front, as string resources.
Expand Down Expand Up @@ -61,4 +67,78 @@ object QuickBuildProjectSupport {
} else {
null
}

/**
* A project with `cogo.sqliteDebugger=true` is moved to requery by the Gradle plugin, which
* never applies Quick Build to it (its payload would compile the source without the move). The
* IDE must not provision it either: the build would succeed and then end in a "variant setup
* missing" message that blames the variant.
*
* @param sqliteDebuggerEnabled see [isSqliteDebuggerEnabled].
* @return the refusal message, or null when Quick Build may run.
*/
@StringRes
fun sqliteDebuggerMessage(sqliteDebuggerEnabled: Boolean): Int? =
if (sqliteDebuggerEnabled) {
R.string.quick_build_disabled_sqlite_debugger
} else {
null
}

/**
* Whether one `gradle.properties` text opts in, decided as the Gradle plugin does: the value is
* exactly `true`.
*
* @param gradleProperties the file's text, or null when there is none.
*/
fun isSqliteDebuggerEnabled(gradleProperties: String?): Boolean = gradleProperties != null && propertyValue(gradleProperties) == "true"

/**
* Whether the project opts in, from the same files the Gradle plugin's `findProperty` sees in
* Code on the Go's builds: the Gradle user home `gradle.properties` (`GRADLE_USER_HOME`, which
* overrides the project files), the app module's, and the root's. Gradle loads a
* `gradle.properties` from every project directory into that project, and a subproject also
* inherits its parent's properties, so the first of these that defines the property wins.
* `-P` arguments are not read: Code on the Go passes none for this property.
*
* A file that cannot be read is reported to [onReadFailure] and counts as not defining it.
*
* @param moduleDirs the directories of the app modules the plugin is applied to.
*/
fun isSqliteDebuggerEnabled(
projectRoot: File,
gradleUserHome: File?,
moduleDirs: List<File> = emptyList(),
onReadFailure: (File, Throwable) -> Unit = { file, error ->
log.warn("Cannot read {}; treating it as not defining the SQLite debugger opt-in", file, error)
},
readText: (File) -> String = File::readText,
): Boolean {
val files =
listOfNotNull(gradleUserHome) + moduleDirs + projectRoot
for (entry in files) {
val file = File(entry, "gradle.properties")
val text =
try {
file.takeIf { it.isFile }?.let(readText)
} catch (e: IOException) {
onReadFailure(file, e)
null
} ?: continue
val value = propertyValue(text) ?: continue
return value == "true"
}
return false
}

private fun propertyValue(gradleProperties: String): String? =
try {
Properties()
.apply { load(StringReader(gradleProperties)) }
.getProperty(GradlePluginConfig.PROPERTY_SQLITE_DEBUGGER_ENABLED)
} catch (e: IllegalArgumentException) {
null
}

private val log = LoggerFactory.getLogger("QB-Support")
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ import com.itsaky.androidide.tooling.api.ForwardingToolingApiClient
import com.itsaky.androidide.tooling.api.GradlePluginConfig.PROPERTY_JDWP_ENABLED
import com.itsaky.androidide.tooling.api.GradlePluginConfig.PROPERTY_LOG_SENDER_AAR
import com.itsaky.androidide.tooling.api.GradlePluginConfig.PROPERTY_LOG_SENDER_ENABLED
import com.itsaky.androidide.tooling.api.GradlePluginConfig.PROPERTY_SQLITE_DEBUGGER_AAR
import com.itsaky.androidide.tooling.api.GradlePluginConfig.PROPERTY_SQLITE_REWRITE_RUNTIME_AAR
import com.itsaky.androidide.tooling.api.IToolingApiClient
import com.itsaky.androidide.tooling.api.IToolingApiServer
import com.itsaky.androidide.tooling.api.messages.BuildId
Expand Down Expand Up @@ -726,6 +728,10 @@ class GradleBuildService :
extraArgs.add("-P${PROPERTY_JDWP_ENABLED}=$enableJdwp")
extraArgs.add("-P${PROPERTY_LOG_SENDER_ENABLED}=$enableLogSender")
extraArgs.add("-P${PROPERTY_LOG_SENDER_AAR}=${Environment.LOGSENDER_AAR.absolutePath}")
// Always passed, like logsender's: the plugin reads it only for a project that opted in, and
// then names the missing file instead of a missing property.
extraArgs.add("-P${PROPERTY_SQLITE_DEBUGGER_AAR}=${Environment.SQLITE_DEBUGGER_AAR.absolutePath}")
extraArgs.add("-P${PROPERTY_SQLITE_REWRITE_RUNTIME_AAR}=${Environment.SQLITE_REWRITE_RUNTIME_AAR.absolutePath}")

extraArgs.addAll(relocatedBuildOutputArgs(isSync))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,26 @@ class GradleQuickBuildProvisionerFailureArmsTest {
assertThat(gradle.executedTasks).isNull()
}

@Test
fun `a project that opted into the SQLite debugger is refused before staging, with its own message`() =
runTest {
File(projectRoot, "gradle.properties").writeText("cogo.sqliteDebugger=true\n")
var staged = 0
val gradle = FakeBuildService()

val outcome =
testProvisioner(
context = context,
projectRoot = projectRoot,
buildService = gradle,
stage = { _, _ -> staged++ },
).provision()

assertThat(failureText(outcome)).isEqualTo(context.getString(R.string.quick_build_disabled_sqlite_debugger))
assertThat(staged).isEqualTo(0)
assertThat(gradle.executedTasks).isNull()
}

@Test
fun `a slot that goes busy between the staging and the build still reads as a busy slot`() =
runTest {
Expand Down
Loading
Loading