
Facilitates building AI-powered mobile and web applications using Gemini and Imagen models. Offers integration with Firebase AI Logic, enabling content generation and AI functionalities through straightforward setup.
⚠️ : This is an experimental library and may be subject to breaking changes.
Build AI-powered mobile and web apps and features with the Gemini and Imagen models using Firebase AI Logic
| Platform | Targets Supported |
|---|---|
| Android | androidTarget |
| iOS |
iosArm64, iosX64, iosSimulatorArm64
|
Add the dependency
libs.versions.toml:[versions]
firebase-ai-kmp = "0.4.0"
[libraries]
firebase-ai-kmp = { module = "io.github.seanchinjunkai:firebase-ai-kmp", version.ref = "firebase-ai-kmp" }
commonMain source set:commonMain.dependencies {
implementation(libs.firebase.ai.kmp)
}
Firebase Console Setup
AI -> AI Logic then open Settings.NOTE: Using the Vertex AI Gemini API requires that your project is linked to a Cloud Billing account. This means that your Firebase project is on the pay-as-you-go Blaze pricing plan.
Link the native iOS Bridge
Since the SDK depends on a native Firebase iOS framework, FirebaseAIBridge, this will need to be linked to your existing iOS project.
Using CocoaPods
pod 'FirebaseAIBridge', :git => 'https://github.com/SeanChinJunKai/FirebaseAIBridge.git', :tag => '0.4.0'
iOS Setup
GoogleService-Info.plist and place it under iosApp/iosApp directory.Podfile:pod 'FirebaseCore', :git => 'https://github.com/firebase/firebase-ios-sdk.git', :tag => '11.15.0'
iosApp/iosApp/iOSApp.swift
import SwiftUI
import FirebaseCore
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
FirebaseApp.configure()
return true
}
}
@main
struct YourApp: App {
// register app delegate for Firebase setup
@UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
var body: some Scene {
WindowGroup {
NavigationView {
ContentView()
}
}
}
}
iosApp directoryAndroid Setup
google-services.json and place it in composeApp directory.libs.versions.toml:[versions]
googleServices = "4.4.3"
[plugins]
googleServices = { id = "com.google.gms.google-services", version.ref = "googleServices" }
build.gradle.kts add the plugin:plugins {
alias(libs.plugins.googleServices) apply false
}
composeApp/build.gradle.kts, add the plugin:plugins {
alias(libs.plugins.googleServices)
}
Import FirebaseAI
You should now be able to import FirebaseAI in commonMain
import io.github.seanchinjunkai.firebase.ai.Firebase
import io.github.seanchinjunkai.firebase.ai.GenerativeBackendEnum
Quick start
// Initialize the Gemini Developer API backend service
// Create a `GenerativeModel` instance with a model that supports your use case
val model = Firebase.ai(GenerativeBackend.googleAI()).generativeModel("gemini-2.0-flash")
val prompt = "Write a story about a magic backpack."
val response = model.generateContent(prompt)
print(response.text)
firebase-ai-sample - Kotlin Multiplatform sample application that showcases Firebase AI integration. Runs on both Android and iOS
⚠️ : This is an experimental library and may be subject to breaking changes.
Build AI-powered mobile and web apps and features with the Gemini and Imagen models using Firebase AI Logic
| Platform | Targets Supported |
|---|---|
| Android | androidTarget |
| iOS |
iosArm64, iosX64, iosSimulatorArm64
|
Add the dependency
libs.versions.toml:[versions]
firebase-ai-kmp = "0.4.0"
[libraries]
firebase-ai-kmp = { module = "io.github.seanchinjunkai:firebase-ai-kmp", version.ref = "firebase-ai-kmp" }
commonMain source set:commonMain.dependencies {
implementation(libs.firebase.ai.kmp)
}
Firebase Console Setup
AI -> AI Logic then open Settings.NOTE: Using the Vertex AI Gemini API requires that your project is linked to a Cloud Billing account. This means that your Firebase project is on the pay-as-you-go Blaze pricing plan.
Link the native iOS Bridge
Since the SDK depends on a native Firebase iOS framework, FirebaseAIBridge, this will need to be linked to your existing iOS project.
Using CocoaPods
pod 'FirebaseAIBridge', :git => 'https://github.com/SeanChinJunKai/FirebaseAIBridge.git', :tag => '0.4.0'
iOS Setup
GoogleService-Info.plist and place it under iosApp/iosApp directory.Podfile:pod 'FirebaseCore', :git => 'https://github.com/firebase/firebase-ios-sdk.git', :tag => '11.15.0'
iosApp/iosApp/iOSApp.swift
import SwiftUI
import FirebaseCore
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
FirebaseApp.configure()
return true
}
}
@main
struct YourApp: App {
// register app delegate for Firebase setup
@UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
var body: some Scene {
WindowGroup {
NavigationView {
ContentView()
}
}
}
}
iosApp directoryAndroid Setup
google-services.json and place it in composeApp directory.libs.versions.toml:[versions]
googleServices = "4.4.3"
[plugins]
googleServices = { id = "com.google.gms.google-services", version.ref = "googleServices" }
build.gradle.kts add the plugin:plugins {
alias(libs.plugins.googleServices) apply false
}
composeApp/build.gradle.kts, add the plugin:plugins {
alias(libs.plugins.googleServices)
}
Import FirebaseAI
You should now be able to import FirebaseAI in commonMain
import io.github.seanchinjunkai.firebase.ai.Firebase
import io.github.seanchinjunkai.firebase.ai.GenerativeBackendEnum
Quick start
// Initialize the Gemini Developer API backend service
// Create a `GenerativeModel` instance with a model that supports your use case
val model = Firebase.ai(GenerativeBackend.googleAI()).generativeModel("gemini-2.0-flash")
val prompt = "Write a story about a magic backpack."
val response = model.generateContent(prompt)
print(response.text)
firebase-ai-sample - Kotlin Multiplatform sample application that showcases Firebase AI integration. Runs on both Android and iOS