https://github.com/google/secrets-gradle-plugin

import com.google.ai.client.generativeai.GenerativeModel

val model = GenerativeModel(
“gemini-2.0-flash-exp”,
// Retrieve API key as an environmental variable defined in a Build Configuration
// see GitHub - google/secrets-gradle-plugin: A Gradle plugin for providing your secrets to your Android project. for further instructions
BuildConfig.geminiApiKey,
generationConfig = generationConfig {
temperature = 1.55f
topK = 40
topP = 0.95f
maxOutputTokens = 8192
responseMimeType = “application/json”
},
)

val chatHistory = listOf(
)

val chat = model.startChat(chatHistory)

// Note that sendMessage() is a suspend function and should be called from
// a coroutine scope or another suspend function
val response = chat.sendMessage(“INSERT_INPUT_HERE”)

// Get the first text part of the first candidate
println(response.text)
// Alternatively
println(response.candidates.first().content.parts.first().asTextOrNull())