Skip to content

nsgo dev on Android and the iOS simulator: a Go change repackages, reinstalls and relaunches the whole app instead of replacing the Go binary #661

In review

Description

@houko

Context

On the mobile targets, every Go change under nsgo dev rebuilds, reinstalls and relaunches the whole app (main at 30a5b8b):

  • Android (androidSession, cmd/nsgo/android.go:360): buildAndroidAPK packs a complete APK (android.go:378: classes.dex, lib/<abi>/libnsgo.so, every resource under assets/, the icon, signed), then adb install -r (:392), then am start -S (:400), which stops the process.
  • iOS simulator (iosSession, cmd/nsgo/ios.go:246): buildIOSApp builds the whole bundle (:252), then simctl install (:274), then simctl launch --terminate-running-process (:278).

A Go change only changes one file of all that: the Go binary (libnsgo.so on Android, the executable in the .app on iOS). Packaging, signing and installing a full app on each save multiplies the restart cost that #658 measures on the desktop, where only the binary is rebuilt. I have not timed the mobile loop separately.

Why it matters

iOS and Android are where an NSGo app looks and behaves most differently from the desktop it is written on, so they are where a developer most needs a short loop. Installing takes seconds on its own, before the app starts, and grows with the app's resources.

Proposal

After the first install of a dev session, replace only the Go binary:

  • Android: the Go side is not a library the app loads but an executable the runtime starts: NsgoView runs libnsgo.so from nativeLibraryDir with a ProcessBuilder (internal/platform/android/java/dev/oneo/nsgo/NsgoView.java:643-644) and talks to it over its stdin and stdout (NsgoEngine.java). With targetSdkVersion 34 (internal/platform/android/runtime/AndroidManifest.xml:15), Android does not let an app exec files in its own writable storage (apps targeting API 29 or later), so a new binary cannot be pushed beside the installed one; only an install writes nativeLibraryDir. What the two-process design allows instead is an opt-in dev mode in which the Go process runs on the development machine and speaks the same protocol to the device's runtime over a socket adb forwards, in place of the pipe. A Go change then rebuilds and restarts a host process and reconnects: nothing is packaged or installed, and the Activity, its window and the Java side stay as they are, which is nsgo dev: a Go change closes the app's window and opens a new one, losing its place on screen (tiling, Split View) and the page it was on #658's "keep the window" for free on Android. The cost is fidelity: the Go code runs as the host's GOOS, so _android.go code and whatever Go does directly with files, the network or the system behave as on the host. It suits UI work; platform code still needs the full install, which stays the default.
  • iOS simulator: the installed app's container is on the Mac (xcrun simctl get_app_container <udid> <id>), so nsgo dev can write the new executable into it, sign it ad hoc as the simulator requires, and relaunch, skipping simctl install unless something besides the executable changed.
  • Physical devices need a signed reinstall and stay as they are.

Acceptance

  • In the opt-in mode, on an Android device or emulator, a Go-only change under nsgo dev runs the new code without adb install, and the Activity is not restarted.
  • In the iOS simulator, a Go-only change restarts the app without simctl install.
  • A change to resources, the icon, the manifest or nsgo.yaml still reinstalls.
  • Release builds (nsgo build) are unchanged.

  • Platforms: Android, iOS simulator (nsgo dev)
  • NSGo: main at 30a5b8b (2026-11-18)
  • Development machine: macOS 27.2 (Apple M4 Pro), Go 1.27.3

Activity

  1. houko commented on Nov 18, 2026

    @houko
    CollaboratorAuthor

    Corrected the Android part of the proposal. It first suggested pushing a new libnsgo.so into the app's private storage and loading it from there, but libnsgo.so is an executable that NsgoView starts with ProcessBuilder (NsgoView.java:643-644), and an app targeting API 29+ (targetSdkVersion 34 here) cannot exec files in its own writable storage, so that would not run. The proposal now uses the two-process design instead: an opt-in dev mode in which the Go process runs on the development machine and talks to the device's runtime over an adb-forwarded socket, which also keeps the Activity and its window across Go changes (#658). The iOS simulator part is unchanged.

  2. self-assigned this
    on Nov 20, 2026
  3. houko commented on Nov 20, 2026

    @houko
    CollaboratorAuthor

    I audited the current mobile dev sessions. Android still rebuilds/signs/installs an APK on every build, and iOS simulator still installs the full app bundle. The proposed Android host-process mode changes execution fidelity and needs a new socket protocol, while simulator executable replacement needs signing/container handling and resource-change invalidation. This is a broad toolchain feature rather than a safe local fix, so I left the issue open without a partial implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions