Create hello-platform for Android (#12)

Co-authored-by: Михаил Капелько <kornerr@gmail.com>
This commit is contained in:
kornerr authored and Михаил Капелько committed 2026-11-01 15:52:24 +01:00
1 parent cf79e89dc4
commit 45ca185094
45 files changed
+985 -25

No files matched your search

+67 -14
View File
@@ -1,8 +1,9 @@
# hello-platform
Minimal macOS and iOS app that validates the platform foundation: a "Hello,
platform!" title, a count label and an Increment button. All state lives in
Dialect; SwiftUI only renders the view model and sends one input event.
Minimal macOS, iOS and Android app that validates the platform foundation: a
"Hello, platform!" title, a count label and an Increment button. All state lives
in Dialect; SwiftUI and Compose only render the view model and send one input
event.
## Layout
@@ -13,6 +14,7 @@ hello/hello-platform/
│ ├── build-mac generate → build → package
│ ├── run-mac run the packaged .app
│ ├── prepare-ios generate → xcodegen project
│ ├── prepare-android generate Kotlin dialect.kt
│ └── step/
│ ├── generateDialect sibling ../dialect generator on dialect.yml
│ ├── buildMac swift build in ver-mac/
@@ -48,11 +50,35 @@ hello/hello-platform/
└── other/other.swift same symlink as the macOS tree
```
The Android target mirrors the same layout:
```text
hello/hello-platform/ver-android/
├── settings.gradle.kts rootProject "hello-platform", includes app
├── app/build.gradle.kts org.opengamestudio.helloplatform, Compose
├── gradle/ AGP 8.7.3, Kotlin 2.1.0, wrapper 9.3.1
├── local.properties sdk.dir, git-ignored
├── build/ Gradle output and APK (git-ignored)
└── app/src/main/
├── AndroidManifest.xml label hello-platform, Theme.MyApplication
├── res/ strings, theme, adaptive launcher icon
└── kotlin/org/opengamestudio/
├── MainActivity.kt Compose Box → HPView, edge-to-edge
├── HPActivityDelegate.kt HPComponent + logging, calls setup()
├── dialect.kt generated Kotlin, never hand-edited
├── hp/ relative symlinks into components/hp/android
│ ├── hp.kt
│ ├── hpVM.kt
│ └── view/HPView.kt → components/hp/android/view/HPView.kt
└── other/other.kt relative symlink into components/other
```
`components/` is the source of truth. The `src/hp` and `src/other` entries are
symlinks, so edit the real files under `components/` and keep the links intact.
Both platforms share one `dialect.swift` (the iOS one is a symlink to `ver-mac`),
macOS and iOS share one `dialect.swift` (the iOS one is a symlink to `ver-mac`),
one `HPView` body (the iOS `components/hp/ios/view/HPView.swift` links back to
the macOS view) and one `res/AppIcon.png`.
the macOS view) and one `res/AppIcon.png`. Android has its own generated
`dialect.kt` and Compose view, with the same state and layout.
## Shared components
@@ -65,7 +91,10 @@ the macOS view) and one `res/AppIcon.png`.
button dispatches `hpSet(F.didClickIncrement, true)`. It is platform-neutral,
so `components/hp/ios/view/HPView.swift` is a symlink back to it and both
`src/hp/view/HPView.swift` links resolve to the same file.
- `components/other/other.swift` — helpers, including
- `components/hp/android/` — the Android mirror: `hp.kt` (same `HPComponent`),
`hpVM.kt` (`HPVM` with a Compose `mutableStateOf`) and `view/HPView.kt`
(Compose `Column`, headline, monospaced label, Increment button).
- `components/other/other.swift` / `other.kt` — helpers, including
`otherSetupConsoleLogging(ctrl, "HP")`, which prints every processed field to
stderr as `ИГР HP k/v: '<field>'/'<value>'`.
@@ -74,8 +103,9 @@ the macOS view) and one `res/AppIcon.png`.
1. `HPAppDelegate` creates `HPComponent` (which sets `HPComponent.singleton`)
and then `HPVM` (which sets `HPVM.shared`).
2. The launch callback (`applicationDidFinishLaunching` on macOS,
`application(_:didFinishLaunchingWithOptions:)` on iOS) registers console
logging and calls `hp.setup()`; the macOS one also activates the app.
`application(_:didFinishLaunchingWithOptions:)` on iOS,
`HPActivityDelegate.setup()` in `MainActivity.onCreate` on Android) registers
console logging and calls `hp.setup()`; the macOS one also activates the app.
3. `setup()` queues `didSetup` in the controller.
4. The controller applies the changed field, runs every registered should in
order, and queues each new `recentField` a should returns. Finally it reports
@@ -111,9 +141,9 @@ util/run-mac
`generateDialect` expects the sibling `../dialect` checkout (so
`/Volumes/MOE/p/dialect` for this workspace). `build-mac` runs the steps in
order: regenerate `ver-mac/src/dialect.swift`, `swift build`, then package
`ver-mac/.build/debug/hello-platform`, `Info.plist` and `res/` into
`ver-mac/.build/hello-platform.app`.
order: regenerate `ver-mac/src/dialect.swift` and the Android `dialect.kt`,
`swift build`, then package `ver-mac/.build/debug/hello-platform`, `Info.plist`
and `res/` into `ver-mac/.build/hello-platform.app`.
iOS needs `xcodegen` (see README prerequisites):
@@ -130,10 +160,31 @@ xcodebuild -project ver-ios/hello-platform.xcodeproj \
`ver-ios/`. The generated `.xcodeproj` and `.build/` are git-ignored, so
re-run it after changing `project.yml` or `Info.plist`.
Android needs the SDK and a JDK; `prepare-android` writes the Kotlin dialect,
then Gradle builds the app:
```sh
cd hello/hello-platform
util/prepare-android
cd ver-android
JAVA_HOME="$HOME/.gradle/jdks/eclipse_adoptium-21-aarch64-os_x.2/jdk-21.0.7+6/Contents/Home" \
./gradlew assembleDebug
```
`ver-android/local.properties` points at `~/Library/Android/sdk` and is
git-ignored, so each checkout needs it once. Install the APK with
`adb install -r app/build/outputs/apk/debug/app-debug.apk` and start
`org.opengamestudio.helloplatform/org.opengamestudio.MainActivity`. Use JDK 21:
AGP 8.7.3 does not accept every newer JDK.
## Pitfalls
- Change `dialect.yml`, not `dialect.swift`; retyping or reformatting the
generated file is pointless because every build overwrites it.
- Change `dialect.yml`, not the generated `dialect.swift` / `dialect.kt`;
retyping or reformatting them is pointless because every build overwrites
them.
- The Kotlin output is transpiled through the local LLM, so `ollama serve` must
be running (with `qwen2.5-coder:3b` pulled) before `prepare-android` or
`build-mac`; otherwise generation aborts and `dialect.kt` is left stale.
- Every should label (`1. Upon ...`) must end with a colon: the sibling generator
drops its last character (`../dialect/components/yml/ymlFun.swift`).
- A should function may change only one field; its returned `recentField` drives
@@ -141,4 +192,6 @@ re-run it after changing `project.yml` or `Info.plist`.
- The generated oneliner and `hpSet` force-unwrap `HPVM.shared` /
`HPComponent.singleton`; both must exist before dispatch.
- Only one `dialect.swift` exists: `ver-ios/src/dialect.swift` is a symlink to
the macOS file, so `prepare-ios` regenerates the same source.
the macOS file, so `prepare-ios` regenerates the same source. The Kotlin
`dialect.kt` lives in `ver-android` and is generated from the same
`dialect.yml`.