Add an LLM to your Android app with Arm's AI Chat library
Introduction
Create the Android project
Configure the AI Chat library dependency
Create the UI layouts and message adapter
Implement the main activity logic
Download a model and run the app
Next Steps
Add an LLM to your Android app with Arm's AI Chat library
Verify repository configuration
Your freshly created Android Studio project should already have top-level repositories including google() and mavenCentral() in settings.gradle.kts. Verify that both repositories are present to ensure the app can find the AI Chat library.
Add the Maven dependency
Add the AI Chat library in the app module build file app/build.gradle.kts (not the project-level build.gradle.kts in the root of the project).
In the dependencies section at the bottom, add:
implementation("com.arm:ai-chat:0.1.0")
This adds the library to your project along with all LLM functionality. Also in this file, verify that:
targetSdkandcompileSdkare 36- the Java version in
compileOptionsisJavaVersion.VERSION_17 - the
jvmTargetinkotlinOptionsis 17
In libs.version.toml, check that:
kotlinversion is2.2.20
Finally, there will be a banner at the top of these settings files saying the “Gradle files have changed since last project sync.” Select the option to “Sync Now” and let the project update.
Configure the manifest
Adjust the AndroidManifest.xml file, which is in app\src\main.
Most of the file consists of an XML tag <application ...>. Within the tag are several android: options. Add an additional flag to enable loading of the required llama.cpp native libraries:
<application
...
android:extractNativeLibs="true"
... >
Your project is now configured with the AI Chat library dependency and the necessary manifest settings to load native libraries. In the next section, you’ll create the user interface layouts and message adapter for the chat functionality.