ToolsSlide 84 of 86
84exportTools
Packaging an app
hive build writes a program; hive export writes an app. hive export taps.hive --target android/arm64 produces taps-android-arm64.apk, ready to install.
The window needs no changes. A hive.ui.window already serves its own page over loopback with every asset embedded, so on a handset the platform's own WebView shows it. The program is never told it is on a phone: it serves the same tree it would serve a browser, and the same view answers both.
android/arm64is the only Android target. It is the only one Go links without a C cross-compiler, so the other three are refused by name, and it is what handsets run.- A program with no window is refused, not packaged: an app that shows nothing has no way to be started.
hive buildis for a program that serves or prints. - No tool but Go is involved. The file holds the program, a fixed WebView host, a binary manifest, and
assets/icon.pngas the launcher icon where the program ships one. The build writes the manifest, the resource table, the archive and its signature itself: no Android SDK, and no network. - The application id comes from the entrypoint's name:
taps.hiveishive.taps. Two apps whose entrypoints are bothmain.hiveare one app to the phone, and the second installs over the first, so name the entrypoint after the app.
The APK is signed with APK Signature Scheme v2, under a key made on first use at ~/.hive/android.key. Each machine keeps one stable key, so a later build installs over an earlier one instead of being refused as a different app.
A program that is also an app
type Msg {
Tapped
}
func view(count: Int): ui.View {
return ui.column([ui.pad(24), ui.gap(12), ui.align(ui.Align.Center())], [
ui.text([ui.size(ui.TextSize.Title())], "Tapped {count} times"),
ui.button([ui.on(Msg.Tapped()), ui.tone(ui.Tone.Good())], "Tap"),
])
}
proc update(count: mut Int, msg: Msg): Msg {
if msg is Msg.Tapped {
count += 1
}
return msg
}
proc main(): void {
spawn(ui.window("Taps", view, update), 0)
}Run it here, install it there
$ hive run taps.hive # a window on this machine
$ hive export taps.hive --target android/arm64
Packaged taps.hive -> taps-android-arm64.apk (4s)
$ adb install taps-android-arm64.apk
SuccessThe four ways it says no
$ hive export taps.hive
hive: `hive export` needs a target, and the one it knows is `--target android/arm64`.
$ hive export taps.hive --target android/amd64
hive: `--target android/amd64` needs a C cross-compiler, which is the one thing a machine with the Go toolchain on it cannot be assumed to have. `android/arm64` is the only Android target Go links on its own, and it is what a handset is.
$ hive export taps.hive --target linux/arm64
hive: `hive export` knows one format, and it is Android's. It takes `--target android/arm64`; `linux/arm64` has no app to be packaged into.
$ hive export server.hive --target android/arm64
server.hive:1: `server.hive` opens no window, so there is nothing for an app to show and no way to start it. `hive build` is what compiles a program that serves or prints.