Repository navigation
ADFA-7241: Custom IDE Builder core: zip rewrite, bundle index, keystores, signing #179
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
Open
davidschachterADFA
wants to merge
17
commits into
main
Choose a base branch
from
ccr-a7f3888b-mnh66k
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+4,417
−0
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
444e226
ADFA-7241: Custom IDE Builder core: zip rewrite, bundle index, keysto…
claude 3198bd7
ADFA-7241: Custom IDE Builder plugin scaffold
claude 15e1598
ADFA-7241: Custom IDE Builder screen
claude 94c13b8
ADFA-7241: Check the v1 signature too when verifying a build
claude b25fec7
ADFA-7241: stage picked add-ons under a fixed name; plugin-review fixes
claude 6077b68
ADFA-7241: Import CoroutineScope.cancel in Session
claude f388f81
ADFA-7241: Honour cancellation in downloads; malformed redirects are …
claude 358b935
ADFA-7241: Fix zip writer edge cases and the rewriter filter
claude d6b69a2
ADFA-7241: Make cancel, save and password handling match what the hel…
claude 5c01a5d
ADFA-7241: StagingTest skips only where symlinks are unsupported
claude 98588a1
ADFA-7241: Sort the Session imports
claude 851cbca
ADFA-7241: Keep the IDE's own files in assets/templates
claude 130ab57
ADFA-7241: Refuse oversized add-ons and a full disk before downloading
claude 8bacfc6
ADFA-7241: Add the check that the key loaded is the key shown
claude 7454059
ADFA-7241: Bound the copy, check the key, zero passwords and release …
claude 9c844e1
ADFA-7241: Tooltips for the static views and dialogs; describe the ne…
claude c081926
ADFA-7241: Sort the AddonLimits import
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # Gradle | ||
| .gradle/ | ||
| build/ | ||
| gradle-app.setting | ||
| !gradle-wrapper.jar | ||
| .gradletasknamecache | ||
|
|
||
| # IDE | ||
| .idea/ | ||
| *.iml | ||
| *.ipr | ||
| *.iws | ||
| .project | ||
| .classpath | ||
| .settings/ | ||
| .kotlin/ | ||
|
|
||
| # Local configuration | ||
| local.properties | ||
|
|
||
| # OS | ||
| .DS_Store | ||
| Thumbs.db | ||
|
|
||
| # Logs | ||
| *.log | ||
|
|
||
| # Test outputs | ||
| test-results/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # Custom IDE Builder | ||
|
|
||
| Builds a copy of the installed Code on the Go with a chosen set of plugins (`.cgp`) and templates | ||
| (`.cgt`) bundled inside, signed with the user's own key. Release builds only: the host reads the bundle | ||
| from `assets/plugins/`, `assets/templates/` and `assets/bundled-addons.tsv` in its APK. | ||
|
|
||
| ## Layout | ||
|
|
||
| Everything with logic is in `org.appdevforall.customidebuilder.core` and imports nothing from | ||
| `android.*`, so its tests run on a plain JVM. | ||
|
|
||
| ```sh | ||
| ../../gradlew testDebugUnitTest # from this folder: the tests | ||
| scripts/build-plugins.sh Custom-IDE-Builder # from the repository root: the .cgp, build/plugin/custom-ide-builder.cgp | ||
| ``` | ||
|
|
||
| Works with Code on the Go 26.48 and later (`plugin.min_ide_version` 26.48, `plugin.max_ide_version` 99). | ||
|
|
||
| | File | Does | | ||
| |---|---| | ||
| | `Zip.kt` | Reads a zip's central directory; writes zips with raw (still compressed) entries, 4-byte aligned when stored (`.so` files 16 KB) | | ||
| | `ApkRewriter.kt` | Copies the host APK entry by entry, drops the old bundle and v1 signature, adds the add-ons and a new index | | ||
| | `Bundle.kt` | The bundle index, byte for byte as Code on the Go's build writes it | | ||
| | `Selection.kt` | Validates the chosen add-ons: duplicate plugin IDs, duplicate template names, `core.cgt`, entry names | | ||
| | `Staging.kt` | Names the copy of a picked file (`<n>/addon.cgp`, never the provider's name) and checks a path is inside the staging folder before any write or delete | | ||
| | `Keystores.kt` | Detects PKCS12 or BKS, rejects JKS with the `keytool` conversion, loads a key | | ||
| | `Signing.kt` | apksig: signs v1, v2 and v3, then verifies | | ||
| | `Catalog.kt`, `Download.kt` | The v2 catalog, `minAppVersion` filtering, verified downloads from `addons.appdevforall.org` only | | ||
| | `Pipeline.kt` | Rewrite, sign, verify, check alignment | | ||
|
|
||
| The Android side (`BuilderFragment`, `Session`, `AndroidBits`) is the screen, the file pickers and | ||
| the Storage Access Framework output. | ||
|
|
||
| ## Mirrors of Code on the Go | ||
|
|
||
| `AddonKind` repeats `BundledAddonKind`, and `BundleIndex.render` repeats `StageBundledAddons` | ||
| (`app/build.gradle.kts`). `BundledAddons.parseIndex` is copied into the index test with a comment naming its | ||
| source. If Code on the Go changes the bundle, change these together. | ||
|
|
||
| ## Signing dependency | ||
|
|
||
| `com.android.tools.build:apksig` is bundled into the `.cgp`. Its version is kept equal to the Android Gradle | ||
| plugin's in `settings.gradle.kts`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| "summary": "Builds a signed copy of Code on the Go with the add-ons you choose.", | ||
| "description": "Makes a copy of the Code on the Go installed on this device with the plugins and templates you pick bundled inside, and signs it with your own keystore, so you can hand out a version that arrives ready to use.", | ||
| "tags": [ | ||
| "signing", | ||
| "release", | ||
| "distribution" | ||
| ], | ||
| "origin": "appdevforall", | ||
| "license": "AGPL-3.0-or-later", | ||
| "author": { | ||
| "name": "App Dev For All", | ||
| "url": "https://www.appdevforall.org" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import org.jetbrains.kotlin.gradle.dsl.JvmTarget | ||
|
|
||
| plugins { | ||
| id("com.android.application") | ||
| id("com.itsaky.androidide.plugins.build") | ||
| } | ||
|
|
||
| pluginBuilder { | ||
| pluginName = "custom-ide-builder" | ||
| } | ||
|
|
||
| android { | ||
| namespace = "org.appdevforall.customidebuilder" | ||
| compileSdk = 36 | ||
|
|
||
| defaultConfig { | ||
| applicationId = "org.appdevforall.customidebuilder" | ||
| minSdk = 26 | ||
| targetSdk = 36 | ||
| versionCode = 1 | ||
| versionName = "1.0.0" | ||
| } | ||
|
|
||
| buildTypes { | ||
| release { | ||
| isMinifyEnabled = false | ||
| proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") | ||
| } | ||
| } | ||
|
|
||
| compileOptions { | ||
| sourceCompatibility = JavaVersion.VERSION_17 | ||
| targetCompatibility = JavaVersion.VERSION_17 | ||
| } | ||
|
|
||
| packaging { | ||
| resources { | ||
| excludes += setOf( | ||
| "META-INF/versions/9/OSGI-INF/MANIFEST.MF", | ||
| "META-INF/DEPENDENCIES", | ||
| "META-INF/LICENSE", | ||
| "META-INF/LICENSE.txt", | ||
| "META-INF/NOTICE", | ||
| "META-INF/NOTICE.txt" | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| kotlin { | ||
| compilerOptions { | ||
| jvmTarget.set(JvmTarget.JVM_17) | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| // plugin-api is the IDE-side contract: compile against it, the IDE provides it. | ||
| compileOnly(files("../../libs/plugin-api.jar")) | ||
|
|
||
| // Code on the Go loads classes parent-first and carries its own AndroidX, so the Fragment and | ||
| // Activity Result classes this screen uses come from the host, never from a bundled copy. | ||
| compileOnly("androidx.fragment:fragment:1.8.8") | ||
|
|
||
| implementation("org.jetbrains.kotlin:kotlin-stdlib:2.3.21") | ||
| implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.1") | ||
|
|
||
| // Signs the APK (v1, v2 and v3) and verifies the result. It is the same version as the Android | ||
| // Gradle plugin in settings.gradle.kts, which publishes apksig beside itself on Google Maven. | ||
| // Bundled into the .cgp: the host does not carry it. | ||
| implementation("com.android.tools.build:apksig:9.3.1") | ||
|
|
||
| // Tests run on a computer's Java. There Android's org.json is an empty stub, so they bring their own, | ||
| // and BouncyCastle writes the BKS keystores that Android's built-in provider reads and makes the test certificates. | ||
| testImplementation("junit:junit:4.13.2") | ||
| testImplementation("org.json:json:20240303") | ||
| testImplementation("org.bouncycastle:bcprov-jdk18on:1.78") | ||
| testImplementation("org.bouncycastle:bcpkix-jdk18on:1.78") | ||
| } | ||
|
|
||
| tasks.matching { | ||
| it.name.contains("checkDebugAarMetadata") || | ||
| it.name.contains("checkReleaseAarMetadata") | ||
| }.configureEach { | ||
| enabled = false | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>Custom IDE Builder</title> | ||
| <style> | ||
| body { | ||
| background: #ffffff; | ||
| color: #000000; | ||
| font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; | ||
| line-height: 1.6; | ||
| margin: 0; | ||
| padding: 1.25rem; | ||
| max-width: 760px; | ||
| } | ||
| h1 { font-size: 1.6rem; margin: 0 0 0.75rem; } | ||
| h2 { font-size: 1.2rem; margin: 1.75rem 0 0.5rem; border-bottom: 1px solid #e0e0e0; padding-bottom: 0.2rem; } | ||
| code { | ||
| background: #f4f4f4; | ||
| padding: 0.1rem 0.3rem; | ||
| border-radius: 3px; | ||
| font-family: "SF Mono", Menlo, Consolas, monospace; | ||
| font-size: 0.9em; | ||
| } | ||
| .note { | ||
| border-left: 3px solid #999; | ||
| padding: 0.25rem 0.75rem; | ||
| margin: 1rem 0; | ||
| background: #fafafa; | ||
| } | ||
| h3 { font-size: 1.05rem; margin: 1.1rem 0 0.3rem; } | ||
| li { margin: 0.3rem 0; } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <h1>Custom IDE Builder</h1> | ||
|
|
||
| <h2>Executive overview</h2> | ||
| <p><b>Custom IDE Builder</b> makes a copy of the Code on the Go installed on this device, with the | ||
| plugins and templates you choose bundled inside it, and signs the copy with your own key. Use it to | ||
| hand out a version of Code on the Go that arrives with the add-ons a class, a team or a community needs | ||
| already in place.</p> | ||
|
|
||
| <div class="note"> | ||
| <p><b>Read this before you install a copy.</b> The copy is signed with your key, not ours, so Android | ||
| treats it as a different app. It installs only after Code on the Go has been uninstalled, and | ||
| uninstalling erases the projects stored in the app's data. Copy your projects out first.</p> | ||
| </div> | ||
|
|
||
| <h2>Core functionality</h2> | ||
| <ul> | ||
| <li><b>Bundle swap.</b> The plugins (<code>.cgp</code>) and templates (<code>.cgt</code>) you choose | ||
| replace the add-ons bundled in the copy. Choosing nothing makes a copy that carries no add-ons.</li> | ||
| <li><b>Add-ons from two places.</b> Pick files from this device, or choose from the add-ons website, | ||
| which lists the ones that work with this version of Code on the Go.</li> | ||
| <li><b>Signing.</b> The copy is signed with a key from your own keystore, and the signature is checked | ||
| before the file is saved.</li> | ||
| <li><b>Output folder.</b> The finished APK is saved to a folder you choose, as | ||
| <code><app name>-<version>-custom.apk</code>.</li> | ||
| <li><b>Release builds only.</b> It is made for the release build of Code on the Go, which reads its | ||
| bundled add-ons from <code>assets/plugins/</code> and <code>assets/templates/</code> in its APK.</li> | ||
| <li><b>Installing the copy.</b> It installs only after Code on the Go is uninstalled, because it is signed | ||
| with a different key.</li> | ||
| </ul> | ||
|
|
||
| <h2>Technical architecture</h2> | ||
| <ul> | ||
| <li>The installed app's APK is copied entry by entry without being recompressed. The old bundle | ||
| (<code>assets/plugins/</code>, <code>assets/templates/</code> and the index | ||
| <code>assets/bundled-addons.tsv</code>) and the old signature are dropped, then your add-ons and a new | ||
| index are added, in the layout Code on the Go itself reads.</li> | ||
| <li>Each add-on gets a clean file name inside the APK. A plugin is named after its plugin ID, a template | ||
| after its file name, and two that would clash are refused before the build starts.</li> | ||
| <li>The APK is signed with the Android signing library (<code>apksig</code>) and then verified with it, | ||
| and its alignment is checked.</li> | ||
| <li>Files you pick are copied into this plugin's own private folder under a fixed name, whatever the file | ||
| is called, before they are checked. Downloads from the website come only from | ||
| <code>addons.appdevforall.org</code> over HTTPS and are checked against the size and SHA-256 the | ||
| website publishes. An add-on larger than 512 MB is refused, and so is one that does not fit in the free | ||
| space, before it is copied or downloaded.</li> | ||
| <li>Passwords are held only in the screen's fields and in the one running task that needs them (reading the | ||
| keys, or a build). That task's copies are zeroed when it ends, however it ends, and also if it never | ||
| starts; the fields are emptied when a build ends and when you leave the screen. The plugin asks for permission to read and write files and to use the network (for the website | ||
| list only).</li> | ||
| </ul> | ||
|
|
||
| <h2>Usage</h2> | ||
| <h3>What you need</h3> | ||
| <ul> | ||
| <li>A keystore file in <b>PKCS12</b> (<code>.p12</code>) or <b>BKS</b> format, such as one made by | ||
| <b>Keystore Generator</b>. A Java KeyStore (<code>.jks</code>) file made by <code>keytool</code> must | ||
| be converted first, on a computer: | ||
| <code>keytool -importkeystore -srckeystore old.jks -srcstoretype JKS -destkeystore new.p12 -deststoretype PKCS12</code>.</li> | ||
| <li>The add-ons: <code>.cgp</code> plugin files and <code>.cgt</code> template files from this device, or | ||
| downloaded from the add-ons website.</li> | ||
| <li>A folder to save the finished APK in, and free space for about twice the size of Code on the Go.</li> | ||
| </ul> | ||
|
|
||
| <h3>How to use it</h3> | ||
| <ol> | ||
| <li>Open <b>Custom IDE Builder</b> from the main menu.</li> | ||
| <li><b>Add-ons.</b> Tap <b>Add from this device</b> to pick several files at once. Tap | ||
| <b>Add from the website</b> to choose from the add-ons that work with this version of Code on the Go. | ||
| Nothing is downloaded until you confirm; the downloads come from <code>addons.appdevforall.org</code> | ||
| and each one is checked against the size and SHA-256 the website publishes. Tap <b>Remove</b> beside an | ||
| add-on to take it off the list.</li> | ||
| <li><b>Signing key.</b> Choose the keystore file, type the store password and tap <b>Read keys</b>, | ||
| then pick the key. Leave the key password blank if it is the same as the store password.</li> | ||
| <li><b>Output folder.</b> Choose it once; it is remembered.</li> | ||
| <li>Tap <b>Build APK</b>. Tap <b>Cancel</b> to stop it. A cancelled or failed | ||
| build saves nothing: if it had already begun writing the APK to your folder, that unfinished file is | ||
| deleted.</li> | ||
| </ol> | ||
| <p>Long-press any button or field on the screen for a short explanation.</p> | ||
|
|
||
| <h2>Key benefits</h2> | ||
| <ul> | ||
| <li>Hand out one APK that arrives with the plugins and templates a group needs, with nothing to install | ||
| afterwards.</li> | ||
| <li>It is signed with your key, so you decide who the publisher is.</li> | ||
| <li>It works offline once you have the files, and does not need a computer.</li> | ||
| <li>Every download and every selection is checked before it goes into the copy.</li> | ||
| <li>Your passwords are never saved.</li> | ||
| </ul> | ||
|
|
||
| <h2>Good to know</h2> | ||
| <ul> | ||
| <li><b>Use the same key every time.</b> A device that has a build signed with one key cannot update to | ||
| a build signed with another without being uninstalled first.</li> | ||
| <li><b>Passwords are never saved.</b> They are used for the task in front of you (reading the keys or | ||
| building) and cleared when it ends, and the fields are cleared when a build ends and when you leave the | ||
| screen.</li> | ||
| <li><b>The key is checked again at build time.</b> The keystore file is read again for the build; if the | ||
| key in it is no longer the one whose fingerprint you were shown, the build stops and asks you to read | ||
| the keys again.</li> | ||
| <li><b>Each plugin must have its own plugin ID</b> and each template its own file name; the builder | ||
| says which add-ons clash. <code>core.cgt</code> is never bundled, because Code on the Go installs it | ||
| itself.</li> | ||
| <li><b>Nothing chosen</b> makes a copy that carries no add-ons.</li> | ||
| <li>The copy is built from the APK of this installation. It does not work if Code on the Go was | ||
| installed as split APKs; the screen says so.</li> | ||
| <li>The app is copied without being recompressed, so building takes about as long as copying the file, | ||
| plus the time to sign it.</li> | ||
| </ul> | ||
| </body> | ||
| </html> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| android.useAndroidX=true | ||
| android.nonTransitiveRClass=true | ||
| kotlin.code.style=official | ||
| org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # Keep plugin classes — the IDE loads them by name via plugin.main_class and the screen by class name. | ||
| -keep class org.appdevforall.customidebuilder.** { *; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| pluginManagement { | ||
| repositories { | ||
| google() | ||
| mavenCentral() | ||
| gradlePluginPortal() | ||
| } | ||
| } | ||
|
|
||
| buildscript { | ||
| repositories { | ||
| google() | ||
| mavenCentral() | ||
| } | ||
| dependencies { | ||
| classpath(files("../../libs/plugin-api.jar")) | ||
| classpath(files("../../libs/gradle-plugin.jar")) | ||
| classpath("com.android.tools.build:gradle:9.3.1") | ||
| classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.3.21") | ||
| } | ||
| } | ||
|
|
||
| dependencyResolutionManagement { | ||
| repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) | ||
| repositories { | ||
| google() | ||
| mavenCentral() | ||
| } | ||
| } | ||
|
|
||
| rootProject.name = "custom-ide-builder" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The guide promises deletion that the save code does not guarantee.
When the build fails or is cancelled after the app creates the output document, the app calls
deleteDocumentonce. If the storage provider refuses the deletion, the partial APK stays in the chosen folder. The app ignores the result and shows no message, so the guide's statement that the unfinished file "is deleted" is not true in this case. Users who rely on the guide may not check the folder.Correct the guide so that it states the actual behavior:
Suggested guide wording
If the app should report a failed deletion instead, the message must tell the user that a partial file remains and where it is. The guide wording must then match that message.
Committable suggestion