Import the api package
RunAnywhere.llm does not
resolve, and the error message points at the property rather than the missing import.
Initialize in Application.onCreate
Let generation load the model
models.load when you want to
control when the cost is paid, such as warming a model behind a splash screen.
Collect in viewModelScope
Stream anything a person waits for
A 200-token reply takes seconds. Streaming turns that into words appearing immediately.Cap output length
maxOutputTokens is the biggest lever on latency and battery.
Unload what you are not using
ERROR_CODE_INSUFFICIENT_MEMORY.
Trim conversations
History grows until it exceeds the context window. Keep the system message and the recent turns.Never swallow CancellationException
Close what holds hardware
Voice sessions hold the microphone;AudioRecord and AudioTrack hold audio devices. Close
them in onCleared, or in a finally.
Use structured output rather than asking nicely
Asking for JSON in a system prompt works most of the time, which is the problem.CONSTRAINED is not implemented and throws.
Test on an ARM64 device
The NPU backend is arm64 only and absent from x86_64 emulators. Performance measured on an emulator means nothing.Keep the Hugging Face token out of source
EncryptedSharedPreferences or the Keystore, never in code, assets, or logs.