AI Assistant Development in Mobile Application Based on Gemini (Google)
Gemini — only top model with native Android SDK from Google. google-ai-android (Generative AI SDK) integrates via Gradle without server proxy, simplifying start. But for production direct mobile access — mistake: API key extractable from APK. This contradiction between convenience and security needs solving at project start.
Google AI SDK: Android and iOS
On Android official path:
// build.gradle.kts
implementation("com.google.ai.client.generativeai:generativeai:0.9.0")
val model = GenerativeModel(
modelName = "gemini-1.5-pro",
apiKey = BuildConfig.GEMINI_API_KEY,
generationConfig = generationConfig {
temperature = 0.7f
maxOutputTokens = 2048
topK = 40
topP = 0.95f
},
safetySettings = listOf(
SafetySetting(HarmCategory.HARASSMENT, BlockThreshold.MEDIUM_AND_ABOVE)
)
)
On iOS — GoogleGenerativeAI via Swift Package Manager. API identical, difference only in syntax.
For Flutter — google_generative_ai package covers both platforms.
Multimodality: Gemini's Native Advantage
Gemini 1.5 Pro processes text, images, audio, video and PDF in single request with context up to 1 million tokens. For mobile assistant opens scenarios unavailable to other models: pass 30-minute video and request summary, or upload meeting recording for transcription with summary.
Image transmission via Android SDK:
val image = BitmapFactory.decodeResource(resources, R.drawable.photo)
val content = content {
image(image)
text("Describe what's happening in this photo")
}
val response = model.generateContent(content)
Files over 20 MB must upload via File API (POST https://generativelanguage.googleapis.com/upload/v1beta/files), not pass inline base64. File API stores file 48 hours, returns file_uri used in subsequent requests.
Streaming and Native Kotlin Coroutines
Gemini Android SDK returns Flow<GenerateContentResponse> for streaming — native Kotlin coroutines integration:
viewModelScope.launch {
model.generateContentStream(prompt).collect { chunk ->
val text = chunk.text ?: return@collect
_uiState.update { it + text }
}
}
Cleaner than manual SSE parsing. On iOS similar AsyncThrowingStream<GenerateContentResponse, Error>.
Gemini vs Vertex AI: Production Choice
Google offers two paths:
- Google AI (Gemini API) — direct access, simple start, for MVP and small apps
- Vertex AI — enterprise option with extras: fine-tuning, corporate SLA, data not used for training, Google Cloud IAM integration
For mobile app with user data — Vertex AI with server proxy. For prototype or B2B tool without sensitive data — Gemini API sufficient.
Vertex AI SDK on Android: com.google.cloud:google-cloud-aiplatform, but requires service account authentication, implying server layer.
Safety Settings and Content Filtering
Gemini has built-in blocking system by categories: HARASSMENT, HATE_SPEECH, SEXUALLY_EXPLICIT, DANGEROUS_CONTENT. Default threshold BLOCK_MEDIUM_AND_ABOVE — quite aggressive. For medical or legal apps needing sensitive topic discussion, threshold lowered to BLOCK_ONLY_HIGH or BLOCK_NONE for specific categories.
Blocked content response returns finishReason: SAFETY, not HTTP error — must explicitly check this field, otherwise user gets empty response without explanation.
Timeline Estimates
Text assistant with native SDK — 1 week. Multimodal assistant with File API, streaming and server proxy — 3–4 weeks.







