{"slug": "build-intelligent-android-apps-cloud-and-hybrid-inference", "title": "Build intelligent Android apps: Cloud and hybrid inference", "summary": "Google's Firebase AI Logic SDK now supports cloud and hybrid inference for Android apps, enabling developers to build intelligent features that combine on-device Gemini Nano models with cloud fallback for compatibility. The Jetpacker sample app demonstrates three implementations: a museum assistant using grounding techniques for real-time data, a restaurant review feature with hybrid routing, and tools to balance latency, cost, and offline availability.", "body_md": "Welcome back to the blog post series \"[Build intelligent Android apps](http://android-developers.googleblog.com/2026/07/build-intelligent-android-apps-introduction-jetpack.html)\" where we take a basic Android app and transform it into a **personalized**, **intelligent**, and **agentic** experience. In our [previous post](http://android-developers.googleblog.com/2026/07/android-on-device-inference.html) we explored how to build intelligent on-device features using Gemini Nano through ML Kit's Prompt API.\n\nIn this post, we will look at how you can leverage ** Firebase AI Logic **to build cloud-hosted and hybrid AI features:\n\nSometimes a use case requires AI models with greater world knowledge, a much larger context window, or the ability to handle complex queries. In those scenarios, we can leverage cloud models.\n\nOther times, you want the best of both worlds: using hybrid inference to run on-device when available to lower costs, while falling back to the cloud to ensure compatibility for all devices.\n\nLet’s look at how we implemented three cloud and hybrid features in [Jetpacker](https://github.com/android/ai-samples/tree/main/jetpacker):\n\nThe **Museum assistant **is an interactive chatbot designed to help users plan their museum visits. It provides visitors with up-to-date details regarding specific exhibits, current opening hours, ticket pricing, and more.\n\nWhen building AI features, getting the model to answer with fresh, accurate, and specific real-world information is a common challenge. While cloud models possess massive amounts of world knowledge, they might not know about seasonal exhibits or the current day’s opening hours.\n\nTo bridge this gap, we can use grounding techniques to add extra context to the model’s context window. The [Firebase AI Logic SDK](https://firebase.google.com/products/firebase-ai-logic) supports three types of grounding:\n\nIn Jetpacker, we dynamically construct the available tools based on enabled feature flags and initialize the generative model using the Firebase AI SDK:\n\n``` js\n// implementation(\"com.google.firebase:firebase-ai-logic\")\n\nprivate var toolList = mutableListOf<Tool>()\n\ninit {\n    if (ENABLE_SEARCH_GROUNDING) {\n        toolList.add(Tool.googleSearch())\n    }\n    if (ENABLE_URL_GROUNDING) {\n        toolList.add(Tool.urlContext())\n    }\n}\n\nprivate val generativeModel = Firebase.ai(backend = GenerativeBackend.googleAI())\n    .generativeModel(\n        modelName = \"gemini-3-flash\",\n        systemInstruction = content {\n            text(\"You are a helpful museum assistant answering questions about a museum. Use plain text.\")\n        },\n        tools = toolList\n    )\n```\n\nWhen the user queries the assistant, if URL grounding is enabled, we append the specific museum resource URLs directly into the prompt:\n\n```\nval groundingText = if (FeatureFlags.ENABLE_URL_GROUNDING) {\n    \"\\n If the following message above is about the rules and terms to visit Le Louvre, \" +\n    \"if needed answer this urls ${urlList.joinToString()}\"\n} else {\n    \"\"\n}\n\nval prompt = \"$text $groundingText\"\n\nvar response = chat.sendMessage(prompt)\n```\n\nNot every AI task requires a cloud-based model, and not every device is online. To help developers balance latency, cost, and offline availability, we recently introduced the [Firebase API for Hybrid Inference](https://firebase.google.com/docs/ai-logic/hybrid/android/get-started?api=dev).\n\nIn Jetpacker, the **restaurant review** feature lets users review select topics and automatically drafts a review. To enable this for all users, we prioritize local execution with Gemini Nano, and fall back to cloud models on devices that don’t support Gemini Nano.\n\n```\n// implementation(\"com.google.firebase:firebase-ai-logic\")\n// implementation(\"com.google.firebase:firebase-ai-ondevice:16.0.0-beta03\")\n\n// Initialize the model with hybrid routing configuration\nval reviewModel = Firebase.ai.generativeModel(\n    modelName = \"gemini-3.1-flash-lite\",\n    onDeviceConfig = OnDeviceConfig(\n        inferenceMode = InferenceMode.PREFER_ON_DEVICE\n    )\n)\n```\n\nThe Hybrid Inference API supports four distinct routing modes:\n\nOnce the review is generated, we copy it to the clipboard and use an intent to open Google Maps directly to the restaurant's review page, providing a seamless user experience:\n\n```\nprivate fun copyAndOpenMapsReview(context: Context, reviewText: String, placeId: String) {\n    val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager\n    val clip = ClipData.newPlainText(\"User Review\", reviewText)\n    clipboard.setPrimaryClip(clip)\n\n    val uri = Uri.parse(\"https://search.google.com/local/writereview/mobile?placeid=$placeId\")\n    val intent = Intent(Intent.ACTION_VIEW, uri).apply {\n        setPackage(\"com.google.android.apps.maps\")\n    }\n    context.startActivity(intent)\n}\n```\n\nThe **hotel support chat** was built to let users finalize logistics and check on hotel details. This feature uses system instructions to configure a localized receptionist assistant. By passing specific information—such as the preferred language and hotel information—in the instructions, we can set up a conversational persona representing a specific hotel.\n\n```\nprivate val generativeModel = Firebase.ai(backend = GenerativeBackend.googleAI())\n    .generativeModel(\n        systemInstruction = content {\n            text(\"\"\"\n              You are a helpful hotel receptionist at $hotelName only speaking $language. \n              Answer politely in $language. The bar closes at 10pm and breakfast is from 7am to 10am.\n              There's someone at the desk 24/7. You can retrieve your luggage from the storage room \n              at the back of the lobby at any time.\n              \"\"\")\n        },\n        modelName = \"gemini-3-flash-preview\"\n    )\n```\n\nBecause receptionist responses are in the hotel's local language (for example, French for Hotel Le Meurice in Paris), we need to translate messages to the user’s preferred language.\n\nWhile hybrid models can configure simple routing preferences, complex scenarios require custom routing logic. In Jetpacker, we implement a custom routing stack that takes into account:\n\n```\n// implementation(\"com.google.android.gms:play-services-mlkit-language-id:17.0.0\") \n\n// ML Kit for Language Identification (powered by Google Play Services)\nprivate val languageIdentifier = LanguageIdentification.getClient()\n\n// On-device translator model (prefer Gemini Nano) for translating common language pairs\nprivate val hybridTranslationModel = Firebase.ai(backend = GenerativeBackend.googleAI())\n    .generativeModel(\n        modelName = \"gemini-3-flash\",\n        onDeviceConfig = OnDeviceConfig(mode = InferenceMode.PREFER_ON_DEVICE)\n    )\n\n// Cloud translator model for more complex language pairs\nprivate val cloudTranslationModel = Firebase.ai(backend = GenerativeBackend.googleAI())\n    .generativeModel(\n        modelName = \"gemini-3-flash\"\n    )\n```\n\nWhen a message needs to be translated, we identify the source language and apply our custom routing logic, executing either on-device or cloud translation:\n\n```\nfun translateMessage(message: SupportChatMessage) {\n    viewModelScope.launch {\n        // 1. Detect language using ML Kit Language Identification\n        val sourceLang = try {\n            Tasks.await(languageIdentifier.identifyLanguage(message.text))\n        } catch (e: Exception) {\n            \"Undefined\"\n        }\n\n        // 2. Custom routing: we've verified the translation quality for English and Korean with Gemini Nano, and will translate message on-device for those two languages\n        val routeToCloud = sourceLang != \"en\" && sourceLang != \"kr\"\n\n        val prompt = \"Translate the following text to $selectedLanguage. Just return the translated sentence: ${message.text}.\"\n\n        val (translatedText, routePrefix) = if (routeToCloud) {\n            val result = cloudTranslationModel.generateContent(prompt)\n            result.text to \"[Cloud]\"\n        } else {\n            val result = hybridTranslationModel.generateContent(prompt)\n            result.text to \"[On-Device]\"\n        }\n\n        if (translatedText != null) {\n            _translations.update { current ->\n                current + (message.id to \"$routePrefix: $translatedText\")\n            }\n        }\n    }\n}\n```\n\nIn this example, the custom routing logic only takes into consideration the translation’s source and target language. However, based on your app’s use case, you can expand the routing logic to include other factors such as the on-device model version, network connectivity, battery status, and more.\n\nLastly, using AI in the cloud opens up possibilities of API key abuse or unauthorized billing. To secure API calls, we integrated [ Firebase App Check](https://firebase.google.com/docs/app-check) using both Play Integrity (production) and the local Debug Provider (for local development or emulators).\n\nIn the [JetPackerApplication.kt](https://github.com/android/ai-samples/blob/main/jetpacker/android/app/src/main/kotlin/com/example/jetpacker/JetPackerApplication.kt) file, we install the debug provider at startup and trigger anonymous authentication to establish a secure user session:\n\n```\n//  implementation(\"com.google.firebase:firebase-appcheck-playintegrity\") \n//  implementation(\"com.google.firebase:firebase-appcheck-debug\")  \n//  implementation(\"com.google.firebase:firebase-auth\") \n\noverride fun onCreate() {\n    super.onCreate()\n    Firebase.initialize(context = this)\n    Firebase.appCheck.installAppCheckProviderFactory(\n        DebugAppCheckProviderFactory.getInstance()\n    )\n    Firebase.auth.signInAnonymously()\n}\n```\n\nWhen building locally on an emulator, App Check prints a local token secret to logcat:\n\nEnter this debug secret into the allow list in the Firebase Console: a8c2dd4c-xxxx-xxxx-xxxx-ef6c114ba27e\n\nOnce registered in the Firebase console, local requests are fully verified and authenticated by App Check, protecting our backend while letting us test the app locally.\n\nBy combining cloud model capabilities (grounding, system instructions) with on-device capabilities (hybrid routing, translation, security app checks), we created a travel app that is smart, secure, and available offline.\n\nCheck out the [full source code for Jetpacker on GitHub](https://github.com/android/ai-samples/tree/main/jetpacker), and explore the Firebase documentation to get started:\n\n[Firebase AI Logic Documentation](https://firebase.google.com/docs/ai-logic/get-started)[Firebase Hybrid Inference API](https://firebase.google.com/docs/ai-logic/hybrid/android/get-started)\n\nCheck out the other parts of this blog post series:\n\n** Part 1:** Introduction of the app and a high-level overview.\n\nInterested in more on Android Development? Follow Android Developers on [YouTube](https://www.youtube.com/@AndroidDevelopers) or [LinkedIn](https://www.linkedin.com/showcase/androiddev/)!\n\nAll code snippets in this blog post follow the following copyright notice:\n\n```\nCopyright 2026 Google LLC.\nSPDX-License-Identifier: Apache-2.0\n```\n\n", "url": "https://wpnews.pro/news/build-intelligent-android-apps-cloud-and-hybrid-inference", "canonical_source": "https://android-developers.googleblog.com/2026/07/build-intelligent-android-apps-cloud-hybrid-inference.html", "published_at": "2026-07-21 13:00:00+00:00", "updated_at": "2026-07-21 17:17:12.489013+00:00", "lang": "en", "topics": ["artificial-intelligence", "ai-tools", "ai-infrastructure", "ai-products", "generative-ai"], "entities": ["Google", "Firebase AI Logic SDK", "Gemini Nano", "Gemini 3 Flash", "Gemini 3.1 Flash Lite", "Jetpacker", "ML Kit", "Android"], "alternates": {"html": "https://wpnews.pro/news/build-intelligent-android-apps-cloud-and-hybrid-inference", "markdown": "https://wpnews.pro/news/build-intelligent-android-apps-cloud-and-hybrid-inference.md", "text": "https://wpnews.pro/news/build-intelligent-android-apps-cloud-and-hybrid-inference.txt", "jsonld": "https://wpnews.pro/news/build-intelligent-android-apps-cloud-and-hybrid-inference.jsonld"}}