Firebase AI Logic for Android Developers

Sandra KuriaSandra Kuria
3 min read

Artificial Intelligence is revolutionising the way we build android apps. From personalised recommendations to AI-powered chatbots, bringing these modern app experiences is now achievable with just a few lines of code!

Firebase AI logic (previously known as ‘Vertex AI in Firebase’) enables developers to use Google’s generative AI models (Gemini & Imagen) in their app in a simple and secure way. To integrate Gemini and Imagen APIs directly into your app(without needing a backend), Firebase offers dedicated client SDKs for this purpose. It’s currently supported in android, iOS, Flutter, web and Unity.

To enhance the security of your app, Firebase AI Logic works seamlessly with App Check to block unauthorised requests and protect your app against misuse. With App Check enforced, only verified versions of your app running on secure and untampered devices can make valid calls to the AI logic client SDKs. This verification is handled through attestation services like Play Integrity for android, DeviceCheck/App Attest for iOS and reCAPCHA Enterprise for web apps. Any requests that don’t come from an approved app or verified device will be automatically denied.

To set up Firebase AI Logic on android, the following steps are required;

Pre-requisites

  • Android Studio (latest version)

  • Target API level 21+

Setting up Firebase

To enable Firebase AI logic, go to the Firebase console and set up a new project. In the console, navigate to the Firebase AI logic page and select ‘Get Started’.

Next, select the Gemini API provider that you’d like to integrate with the AI logic SDK.

Once you’ve selected, enable the API and then add the Firebase AI logic SDK in your android app.

Android setup

In Android Studio, add the following dependencies in the app-level Gradle file;

implementation(platform("com.google.firebase:firebase-bom:34.0.0"))
implementation("com.google.firebase:firebase-ai")

We have added the Firebase Bill of Materials(BoM) to help make sure all the Firebase libraries in the project use versions that are compatible with each other, instead of manually updating versions for each library.

Next in your code, define which model you would like to use by calling the generativemodel() function. In this case, we are using Gemini 2.5 flash, which is lightweight and suitable for mobile devices.

val model = Firebase.ai(backend = GenerativeBackend.googleAI())
                        .generativeModel("gemini-2.5-flash")

For this project, PackMate will be a simple app that generates packing lists (powered by Gemini) based on the travel destination entered by the user.

Here, a dynamic prompt is created using the selected trip type to ask the AI model for a relevant packing list suggestion.

val prompt = "Generate a detailed packing list for a ${tripType.value} trip."

If the AI response doesn’t contain any text, the app defaults to showing “No items found” as a fallback message.

val output = response.text ?: "No items found."

This is the app in action, from prompting your trip to getting your personalised packing list.

Firebase AI logic is a great way to start experimenting with AI in application development with endless possibilities to explore and surprisingly simple setup!

Thanks for reading!

0
Subscribe to my newsletter

Read articles from Sandra Kuria directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Sandra Kuria
Sandra Kuria

Android engineer | Google WTM ambassador | Lead-Firebase Kenya