# Jetpack Compose + Google AI Studio Playbook: Gemini Security, Baseline Profiles & Closed Testing

> Take a modern Kotlin 2.1+ & Jetpack Compose Material 3 app powered by Gemini / Firebase AI Logic from Android Studio to Google Play Production — locking down API keys with Play Integrity, generating Baseline Profiles, and running 12-tester QA.

- **Canonical URL**: https://gootester.com/frameworks/jetpack-compose-ai-studio
- **Config File**: app/build.gradle.kts & gradle/libs.versions.toml
- **Build Command**: `./gradlew :app:generateBaselineProfile :app:bundleRelease`

```kotlin
import android.app.Application
import com.google.firebase.Firebase
import com.google.firebase.appcheck.appCheck
import com.google.firebase.appcheck.playintegrity.PlayIntegrityAppCheckProviderFactory
import com.google.firebase.initialize

class ComposeAiApp : Application() {
    override fun onCreate() {
        super.onCreate()
        Firebase.initialize(this)
        // Enforce hardware-backed Play Integrity before calling Firebase AI Logic (Gemini):
        Firebase.appCheck.installAppCheckProviderFactory(
            PlayIntegrityAppCheckProviderFactory.getInstance()
        )
    }
}
```

## Critical Play Console Gotchas
1. **Shipping Google AI Studio `AIza...` Gemini API keys inside `BuildConfig` via Secrets Gradle Plugin**: Google's own AI Studio quickstart templates put `GEMINI_API_KEY` in `local.properties` for 5-minute prototyping — explicitly warning NOT to ship client keys in production! Bots scan Play Store APKs continuously and drain exposed `AIza` Gemini quotas within hours. Migrate to Firebase AI Logic + App Check or a backend Worker.
2. **Play Integrity App Check failing on Closed Testing builds due to missing Play Signing SHA-256**: Enabling `PlayIntegrityAppCheckProviderFactory` blocks your own closed testers with `403 App attestation failed` if you registered only your debug/upload SHA-256 in Firebase instead of copying the **App signing key certificate SHA-256** from `Play Console -> Setup -> App signing`.
3. **Severe first-launch Compose scroll jank on mid-range ARM64 phones without Baseline Profiles**: Jetpack Compose compiles as unbundled Kotlin bytecode rather than precompiled OS framework `View` classes; without `androidx.profileinstaller` and Baseline Profiles, ART JIT-compiles thousands of Compose lambdas on first launch, spiking `dumpsys gfxinfo` slow frames past 50%.
4. **Forgetting `enableEdgeToEdge()` and `imePadding()` on AI chat prompt inputs**: Targeting API 35/36 enforces edge-to-edge system bars; omitting `Modifier.imePadding().navigationBarsPadding()` on bottom prompt text fields hides the user's typing cursor behind the soft keyboard.

## Graduating From AI Studio Prototype Key to Play Integrity Attestation

Google AI Studio and Gemini in Android Studio make prototyping multimodal Kotlin + **Jetpack Compose** apps remarkably fast: drop an image, stream structured JSON from `gemini-2.5-flash`, and render Material 3 cards in 80 lines of code. Yet the exact pattern used in starter templates (`GenerativeModel(apiKey = BuildConfig.apiKey)`) is unsafe for any APK uploaded to Google Play.
Before cutting your Closed Testing release, migrate your Gemini client either to **Firebase AI Logic** enforced by **Firebase App Check (`PlayIntegrityAppCheckProviderFactory`)** or behind your own Cloudflare Worker / Cloud Run proxy verifying user tokens + Play Integrity verdicts (`MEETS_DEVICE_INTEGRITY`). Crucially, copy your **Play App Signing SHA-256** fingerprint from Play Console into Firebase Project Settings so Play-signed Closed Testing splits pass attestation seamlessly.
Simultaneously, add a 1-tap `Flag / Report AI Response` icon on every generated Compose card to satisfy `/declarations/ai-generated-content-policy`, and disclose prompt/media transmission inside `/declarations/data-safety-and-account-deletion`.

## Eliminating Compose Cold-Start & Scroll Jank with ART Baseline Profiles

On a flagship Pixel 9 Pro, unoptimized Jetpack Compose lazy lists feel effortless; on a budget Cortex-A55 handset during Closed Testing or Play Pre-Launch crawls, first-run JIT compilation and unnecessary recompositions (`List<T>` unstable collection parameters without Strong Skipping / `@Immutable`) cause visible stutter.
Enable Kotlin 2.0+ Compose Compiler Strong Skipping (on by default in modern Kotlin), attach `androidx.profileinstaller:profileinstaller`, and package a Baseline Profile (`baseline-prof.txt`) inside your `.aab` so Play Store Cloud Profiles ahead-of-time (AOT) compile critical startup and chat-scroll paths at install time.

## Proving Native Quality Across 14 Days of Human + ARM64 ADB QA

Once your Compose `.aab` is approved on Closed Testing and `testers@gootester.com` is verified (starting GOOtester's service clock), run a 12-tester ($6 Basic), 15-tester ($12 Standard), or 25-tester ($20 Premium) human cohort alongside Standard/Premium's isolated physical-device ARM64 ADB QA (`dumpsys gfxinfo` frame percentiles + `meminfo` PSS).
Shipping `versionCode 2` and `versionCode 3` with measurable frame-time and UX improvements builds clear, truthful engineering evidence for your Production Access submission (decided solely by Google Play).
