README.md
iosApp/README.md
1# iOS Host App23This directory contains the native SwiftUI host for the Compose Multiplatform app.45Open `iosApp.xcodeproj` or use the shared `iosApp` scheme from Android Studio. The `BuildSharedFramework.sh` build phase calls:67```bash8./gradlew :composeApp:embedAndSignAppleFrameworkForXcode9```1011The generated `YokanShared.framework` is imported by `YokanApp.swift`, which mounts the shared `MainViewController()`.1213## TestFlight with Codemagic1415The `ios-testflight` workflow in `../codemagic.yaml` archives the shared `iosApp`16scheme in Release, signs it for App Store distribution, uploads the IPA, and17distributes it to the **Yokan Testers** TestFlight group. It runs on pushes to18`main` and can also be started manually in Codemagic. It does not submit an App19Store release.2021Configure these once before the first run. All setup can be done from Linux;22Codemagic supplies the macOS build machine and Xcode.23241. Use an active Apple Developer Program membership. In Apple Developer →25 Certificates, Identifiers & Profiles, register an explicit App ID with bundle26 ID `eu.friedcutlet.yokan`. In App Store Connect → My Apps → **+ → New App**,27 create **Yokan**, select iOS and that bundle ID, choose a primary language,28 and enter a unique SKU such as `yokan-ios`. Record its numeric **Apple ID**29 from **App Information**. Use the same Apple team throughout signing.302. In Forgejo → your avatar → **Settings → Applications → Generate New Token**,31 create a dedicated token named `codemagic-yokan`. Grant **Repository → Read**32 (`read:repository`). If your Forgejo version offers **Specific repositories**,33 select `friedcutlet/yokan`, `friedcutlet/kmp-mpv`, and `friedcutlet/yokan-ext`;34 otherwise allow private repository access. The account creating the token35 must have read access to all three. Copy the generated token immediately;36 Forgejo displays it only once. No repository write or administrator scope is37 needed for these builds.383. In Codemagic, select your team (enable billing if the team setup requires it)39 and choose **Add application → Other**. Enter40 `https://git.friedcutlet.com/friedcutlet/yokan.git`, select private repository41 authentication, and enter your Forgejo username with the token from step 242 as the **Password**. Choose the non-Flutter/Other project type and use the43 root `codemagic.yaml`. For an existing app, update **App settings → Repository44 settings** with these HTTPS credentials. Keep the URL free of credentials.454. In Codemagic's environment variables, create the group46 `private_git_credentials`. Add **`FORGEJO_USERNAME`** with your Forgejo login47 (for example `friedcutlet`), and **`FORGEJO_TOKEN`** with the token from step48 2, marked **Secret**. Remove the old `FORGEJO_SSH_KEY` variable if migrating49 from SSH. The connection in step 3 fetches the main repository before scripts50 run; these variables authenticate the private HTTPS submodules through51 `scripts/init-private-submodules.sh`. Both settings are required.525. In App Store Connect → **Users and Access → Integrations → App Store Connect53 API → Team Keys**, generate a dedicated key with **App Manager** access.54 An Account Holder may need to enable API access first. Download its `.p8`55 file (available once), and note the issuer ID and key ID. In Codemagic56 **Team settings → Team integrations → Developer Portal → Manage keys**, add57 those values and the `.p8` file. Name the integration **`yokan-testflight`**58 exactly, matching the YAML.596. In Codemagic **Team settings → codemagic.yaml settings → Code signing60 identities → iOS certificates**, select **Generate certificate**, choose61 **Apple Distribution**, select `yokan-testflight`, and give it a reference62 name such as `yokan_distribution`. Alternatively upload a `.p12` containing63 both an existing distribution certificate and its private key, plus its64 password if required. A `.cer` file alone is insufficient.657. In Apple Developer → **Profiles → +**, create an **App Store Connect**66 distribution profile for `eu.friedcutlet.yokan`, selecting the certificate67 from step 6. Download it. In Codemagic's **iOS provisioning profiles** tab,68 upload the `.mobileprovision` file, or use **Fetch profiles** to import it.69 Give it a reference name such as `yokan_app_store`; verify its matching70 certificate has a green checkmark. The YAML selects these files by bundle ID71 and distribution type, so the reference names are your choice.728. Create a variable group named **`ios_testflight`** containing73 **`APP_STORE_APPLE_ID`**, set to the numeric Apple ID from step 1. This is74 the app's identifier in App Store Connect, not your Apple account email or75 the bundle ID. Ensure both variable groups are available to this app.769. In App Store Connect → Yokan → **TestFlight**, create an internal testing77 group named **`Yokan Testers`** exactly. Add eligible App Store Connect users78 (invite them through **Users and Access** first if necessary). Enable79 automatic distribution to the group when offered. Complete required beta80 information and export compliance questions. External testers require an81 external group and TestFlight App Review instead.8210. In Codemagic, choose **Start new build**, branch **`main`**, and workflow83 **iOS TestFlight** (`ios-testflight`). Check source fetching, signing,84 archiving, and publishing logs. After Apple's processing completes, resolve85 any **Missing Compliance** prompt and confirm the build is available to86 **Yokan Testers**. Install Apple's **TestFlight** app on the iPhone and87 accept the tester invitation.8889For automatic push builds, open the app's **Webhooks** tab in Codemagic and copy90its payload URL, `https://api.codemagic.io/hooks/<appId>`. In Forgejo → Yokan →91**Settings → Webhooks → Add webhook → Forgejo** (or Gitea on older instances),92set that URL, method **POST**, content type **application/json**, **Push Events**,93branch filter **main**, and **Active**. Match any webhook secret configured in94Codemagic. Test delivery and inspect Codemagic's received webhooks and build95list. Forgejo supplies GitHub-compatible event headers, but Codemagic does not96document Forgejo as a supported provider; confirm an actual `main` push starts97the workflow before relying on it. Manual builds work independently of webhooks.98The existing sideload and macOS workflows also match `main` pushes; remove their99`triggering` sections if you only want automatic TestFlight builds.100101The workflow reads the102marketing version from `../version.xcconfig` (or `YOKAN_VERSION`) and chooses a103build number greater than all existing TestFlight builds, with the repository's104derived build number as its minimum. Authentication or build-number lookup105failures stop the build. Run one TestFlight build at a time so parallel runs do106not choose the same next number. Both Gradle and Xcode receive the same version107and build-number overrides.108109TestFlight builds disable `YOKAN_SIDELOAD_RUNTIME` and omit the embedded JVM and110extension-server JAR. On iOS, profiles without a saved extension-server URL use111`https://bridge.mangayomi.30062022.xyz`; an explicitly saved URL takes precedence.112Android, desktop, and web retain their existing defaults.113114Both Codemagic iOS workflows use Java 21 and preserve `~/.konan` alongside the115Gradle caches. Kotlin/Native release binary caching is enabled in116`../gradle.properties` to compile dependencies separately and reduce the heap117needed by the final framework link on the 8 GB M2 runner. The first build must118populate these caches. This mode trades some whole-program optimization for119lower build memory use; see [Kotlin's release caching guidance](https://kotlinlang.org/docs/native-improving-compilation-time.html#enable-caches-for-release-binaries).120The two cache properties must be kept together when updating Kotlin, including121the documented internal Gradle plugin property. The Xcode Gradle phase includes122stack traces so a failure's compiler stage is visible in the build log.123124See [adding custom repositories](https://docs.codemagic.io/getting-started/adding-apps/),125[Forgejo access tokens](https://forgejo.org/docs/latest/user/authentication/token-scope/),126[iOS signing](https://docs.codemagic.io/yaml-code-signing/signing-ios/),127[App Store Connect publishing](https://docs.codemagic.io/yaml-publishing/app-store-connect/),128[Codemagic webhooks](https://docs.codemagic.io/configuration/webhooks/), and129[Forgejo webhooks](https://forgejo.org/docs/latest/user/repository/webhooks/).130131## Sideloaded extension server132133Sideloaded device builds embed Mangatan's pinned OpenJDK Zero framework and134iOS-specific M-Extension-Server JAR. The framework is loaded only when the135server starts, runs without a JIT entitlement, and pauses its loopback listener136while the app is backgrounded. Simulator and App Store builds omit the runtime.137138Device builds include the Java runtime and M-Extension-Server only when the139`YOKAN_SIDELOAD_RUNTIME=YES` build setting is present. This mode is for140sideloading and is intentionally excluded from ordinary distribution builds:141142```bash143xcodebuild -project iosApp.xcodeproj -scheme iosApp \144 -destination 'generic/platform=iOS' \145 YOKAN_SIDELOAD_RUNTIME=YES YOKAN_SIDELOAD_RUNTIME_ENABLED=1 build146```147