# Getting Ragreen mobile onto Codemagic (APK + IPA, no Mac required)

## Step 0 — Scaffold the native projects (must run once, locally, with Flutter installed)

`ragreen_mobile/` currently has only `lib/` + `pubspec.yaml`. Before *any* build
tool (Codemagic included) can produce an APK or IPA, the native Android and
iOS project folders need to exist. This is a one-time, safe, additive command
— it does **not** touch your `lib/` code or your existing dependencies:

```bash
cd ragreen_mobile
flutter create --org com.eventus --project-name ragreen_mobile --platforms=android,ios .
```

- Replace `com.eventus` with whatever reverse-domain identifier you want as
  the base of your app IDs (this becomes `com.eventus.ragreen_mobile` on
  Android, and the iOS bundle ID template — you'll set the final bundle ID
  in Xcode/Codemagic).
- Run `flutter pub get` afterward, then `flutter analyze` and (if you have an
  emulator) `flutter run` once locally to confirm it launches, before pushing
  to CI.
- Commit the new `android/`, `ios/`, and `.metadata` files/folders to git.

## Step 1 — Put the project on GitHub (or GitLab/Bitbucket)

Codemagic builds from a git repo — it can't build from a zip upload.

```bash
git init
git add .
git commit -m "Add native android/ios scaffolding, Organic design theme"
git remote add origin https://github.com/<your-username>/ragreen_mobile.git
git push -u origin main
```

(Private repos are fine — Codemagic's free tier supports them.)

## Step 2 — Create a Codemagic account and connect the repo

1. Sign up at codemagic.io with the same GitHub account.
2. "Add application" → select the `ragreen_mobile` repo.
3. Codemagic will detect it's a Flutter project. When it asks how to
   configure builds, choose **"Use existing codemagic.yaml"** — I've
   included one at the root of this folder; copy it into your repo root
   before connecting, or add it via Codemagic's file editor after.

## Step 3 — Android signing (needed for a real, installable release APK)

An unsigned debug APK works for testing on your own device without any of
this — `flutter build apk --debug`. For a real release build:

1. Generate a keystore once, locally:
   ```bash
   keytool -genkey -v -keystore ragreen-release.jks -keyalg RSA \
     -keysize 2048 -validity 10000 -alias ragreen
   ```
   Keep this file and its passwords safe forever — losing it means you can
   never update the app under the same identity again.
2. In Codemagic: Team settings → Code signing identities → Android
   keystores → upload `ragreen-release.jks`, note the reference name.
3. Team settings → Group variables → create a group called
   `ragreen_android_signing` and add the keystore reference plus its
   passwords as variables (Codemagic's UI walks you through the exact
   variable names it expects once you upload the keystore).

## Step 4 — iOS signing (this is the part a Mac normally exists for)

There's no way around one requirement: **you need an Apple Developer
Program membership** ($99/year) to sign an app for real devices or
TestFlight/App Store — Codemagic can't waive that, it's Apple's rule, not a
tooling limitation.

Once you have that:

1. In App Store Connect, create the app record with your bundle ID
   (e.g. `com.eventus.ragreen`).
2. Generate an **App Store Connect API key**: App Store Connect → Users and
   Access → Integrations → App Store Connect API → generate a key with
   "App Manager" access, download the `.p8` file.
3. In Codemagic: Team settings → Code signing identities → App Store
   Connect → add the API key (key ID, issuer ID, the `.p8` file).
4. Codemagic's `app-store-connect fetch-signing-files` step (already in the
   `codemagic.yaml` I've included) will then automatically generate and
   install the right certificates and provisioning profiles at build time —
   you never touch Xcode or a Mac yourself.
5. Update `BUNDLE_ID` in `codemagic.yaml` to match what you registered.

## Step 5 — Run it

Push a commit, or click "Start new build" in Codemagic, and pick the
`ragreen-android` or `ragreen-ios` workflow. Android builds run on Linux
instances (fast, cheap, included free). iOS builds run on Codemagic's
Mac Mini M2 cloud instances — this is what replaces owning a physical Mac.

Free tier gives ~500 build minutes/month, which is normally enough for a
solo developer doing a handful of builds a week.

## Where the output lands

- APK: `build/app/outputs/flutter-apk/app-release.apk` — Codemagic attaches
  it to the build as a downloadable artifact, and can also email it to you
  automatically (see the `publishing.email` block).
- IPA: `build/ios/ipa/*.ipa` — same, plus optional auto-submit to
  TestFlight (`submit_to_testflight: true` is already set in the config).
