DEV Community

Cover image for Keep Gemini API keys out of Google AI Studio Android app builds
Dave Kurian
Dave Kurian

Posted on Originally published at otf-kit.dev

Keep Gemini API keys out of Google AI Studio Android app builds

An Android API key inside an APK is not private. Anyone who can download the app can inspect the package, recover embedded strings, and try the key elsewhere. Google AI Studio’s Firebase integration gives one specific path for AI-built Android apps: route Gemini requests through Firebase AI Logic and require Firebase App Check to verify the calling app.

The important qualifier is “built in Google AI Studio.” The automatic wiring described here is not a universal setup for every Android IDE, framework, or existing app. If you are using another toolchain, you still need to configure Firebase AI Logic and App Check for that project yourself.

Byte and Dex inspect a blank phone request and matching app card passing through an inspection gate; a separate brass provider key stays behind glass in the relay cabinet.

Conceptual view of App Check verifying the app before requests reach Firebase AI Logic; it is an added protection layer, not a guarantee against every attack.

What Google AI Studio wires up

When you enable the Firebase integration for an Android app with generative AI features, Google AI Studio can add Firebase AI Logic and enforce Firebase App Check. Firebase AI Logic sends model requests through a Firebase proxy. With the Gemini Developer API provider, that proxy keeps the provider key on the server instead of embedding it in the APK. App Check adds an attestation check so Firebase can reject requests that do not come from a verified app instance.

This changes the threat model. You are no longer treating a string shipped in a downloadable binary as a secret. Instead, the app calls a service that can verify requests before forwarding them. App Check helps protect the project and quota from unauthorized clients; it does not make a client app impossible to inspect, replace authentication or authorization, or guarantee that every request is benign.

The setup path in Google AI Studio

Start by asking the AI Studio Build agent to add Firebase AI Logic to the Android app, then enable Firebase in the integration card. You can choose an existing Google Cloud project that you own or use a project created for the app. If you select an existing project, check that it meets the integration’s requirements before asking the agent to provision services.

For Android generative-AI apps, the integration can configure Firebase AI Logic, Firebase App Check, and the release attestation path. The generated project files and Firebase console settings are part of the implementation, so inspect them in the repository and in the console instead of treating a successful generation message as proof that the production path is correct.

Use a short validation sequence:

  1. Confirm the app is calling Gemini through Firebase AI Logic rather than a direct provider endpoint.
  2. Check that App Check enforcement is enabled for Firebase AI Logic in the intended Firebase project.
  3. Run a debug build in the AI Studio emulator or on a test phone and make a real model request.
  4. Build a release variant and verify the production attestation path before distributing it through Google Play.
  5. Review API usage, quotas, and the generated security configuration in the Firebase console.

That sequence keeps three questions separate: did the app connect, did Firebase verify it, and did the release configuration behave as expected? A generated code diff answers only the first part until you test the other two.

Debug tokens and Google Play releases are different

During development and trusted testing, Google AI Studio manages an App Check debug token for the app. That token is intended for debug builds: it lets the emulator, a USB-installed test build, or trusted collaborators make requests without publishing a production attestation configuration first.

Treat a debug token as a development credential. Do not ship it in a production build or paste it into a public issue. Keep debug and release variants easy to distinguish, and confirm that the release artifact is not using the debug provider.

For a release build intended for Google Play, the current AI Studio integration documentation says the app switches to reCAPTCHA Enterprise using a preconfigured site key. That behavior is specific to this guided AI Studio flow. Firebase’s general Android App Check documentation also describes other provider configurations, including Play Integrity, but do not assume that the AI Studio build path and a hand-configured Android app use the same defaults. Follow the provider shown for the exact path you are shipping.

Test the release build as a release build. If it only works while the debug provider is active, you have tested your development setup, not the production attestation flow. Check the Firebase console’s App Check request metrics and enforcement state, and make sure the app is registered in the same project that the generated code uses.

Luna and Nova compare a test phone with a removable debug-token tag to a separate release package passing through an attestation scanner.

The guided Google AI Studio Build-mode flow separates debug-token testing from production release attestation; its official guide specifies reCAPTCHA Enterprise for the Google Play release path.

App Check is one layer, not the whole security design

App Check helps establish that a request comes from an attested app or environment. It does not decide which signed-in person may access a record, and it does not validate every action your app exposes. Keep Firebase Authentication and database security rules aligned with the data users should be able to read or change. Review AI-generated rules by hand and test both allowed and denied cases before release.

Also plan for quota and abuse controls. App Check makes unauthorized requests harder; it is not a substitute for monitoring usage, setting project limits, or designing the feature so a user cannot trigger unlimited expensive work. Watch request metrics after enabling enforcement. For an existing released app, moving directly to enforcement can block older app versions that do not send valid App Check tokens, so stage that rollout deliberately.

New AI Studio Android projects should test with enforcement from the start. If you already have a released app, review its App Check metrics and version coverage before changing enforcement so older clients do not fail unexpectedly.

When this integration fits

This route fits a narrow case: you are building an Android app in Google AI Studio Build mode, the app calls Gemini, and you want to avoid embedding the provider key in a downloadable APK. It is especially useful when the app is still early enough to validate the generated Firebase project, request path, and release configuration before users depend on it.

It is not a drop-in security layer for every Android app. A project built in another environment needs its own Firebase AI Logic and App Check setup. An app that needs custom server-side policy, provider routing, or application-specific request validation may still need a backend designed for those jobs. Keep the mechanism matched to the threat model rather than treating “App Check enabled” as a complete security review.

If you want a separate mobile app shell to extend, OTF’s Fitness Kit is an optional Expo and React Native starter with Android and iOS screens, sign-in, and a Postgres database. It costs $99 one-time as checked on October 15, 2026. Firebase AI Logic, Gemini, and App Check are not included; you would add and verify that integration yourself. See the Fitness Kit and current pricing before deciding whether that starting point fits your app.

A release checklist

Before shipping, verify the Google AI Studio integration actually generated the expected Firebase AI Logic and App Check configuration. Confirm the provider key does not appear in the app bundle, while remembering that the Firebase project key in configuration is an identifier rather than an authorization secret. Test debug builds with the managed debug token, then test the release build using the production attestation path. Review generated Firebase Security Rules, confirm enforcement and metrics in the intended project, and keep authentication, authorization, quotas, and abuse monitoring in scope.

The value of the integration is a shorter route to a safer default for one clearly defined workflow. It does not remove the need to inspect the generated app or test the exact artifact you plan to distribute. For the broader question of how to carry an AI-built app into a maintainable repository, see the first-prompt-in-a-new-repo guide, then start with an editable kit if you want a codebase to extend.

Sources

Top comments (0)