Skip to content

Commit d7fb671

Browse files
committed
feat: Add llama.cpp Android library with Kotlin API and sample app
1 parent 29c0525 commit d7fb671

12 files changed

Lines changed: 503 additions & 8 deletions

File tree

.gitignore

Lines changed: 87 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,89 @@
1+
# Built application files
2+
*.apk
3+
*.aar
4+
*.ap_
5+
*.aab
6+
7+
# Files for the ART/Dalvik VM
8+
*.dex
9+
10+
# Java class files
11+
*.class
12+
13+
# Generated files
14+
bin/
15+
gen/
16+
out/
17+
build/
18+
19+
# Gradle files
20+
.gradle/
21+
gradle-app.setting
22+
!gradle-wrapper.jar
23+
24+
# Local configuration file (sdk path, etc)
25+
local.properties
26+
27+
# Proguard folder generated by Eclipse
28+
proguard/
29+
30+
# Log Files
31+
*.log
32+
33+
# Android Studio Navigation editor temp files
34+
.navigation/
35+
36+
# Android Studio captures folder
37+
captures/
38+
39+
# IntelliJ
140
*.iml
2-
.gradle
3-
/local.properties
4-
.idea
41+
.idea/
42+
43+
# Keystore files
44+
*.jks
45+
*.keystore
46+
47+
# External native build folder
48+
.externalNativeBuild/
49+
.cxx/
50+
51+
# Google Services (e.g. APIs or Firebase)
52+
google-services.json
53+
54+
# Freeline
55+
freeline.py
56+
freeline/
57+
freeline_project_description.json
58+
59+
# fastlane
60+
fastlane/report.xml
61+
fastlane/Preview.html
62+
fastlane/screenshots
63+
fastlane/test_output
64+
fastlane/readme.md
65+
66+
# Version control
67+
vcs.xml
68+
69+
# lint
70+
lint/intermediates/
71+
lint/generated/
72+
lint/outputs/
73+
lint/tmp/
74+
75+
# Kotlin
76+
.kotlin/
77+
*.kotlin_module
78+
79+
# macOS
580
.DS_Store
6-
/build
7-
/captures
8-
.externalNativeBuild
9-
.cxx
10-
local.properties
81+
.AppleDouble
82+
.LSOverride
83+
._*
84+
85+
# GGUF model files (large binary files)
86+
*.gguf
87+
88+
# NDK
89+
obj/

app/src/main/cpp/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ set(CMAKE_CXX_EXTENSIONS OFF)
1111
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -DNDEBUG")
1212
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -DNDEBUG")
1313

14+
# 16 KB page size compatibility for Android 15+ (required from Nov 2025)
15+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,max-page-size=16384")
16+
1417
# ARM NEON optimization for ARM architectures
1518
if(${ANDROID_ABI} STREQUAL "arm64-v8a")
1619
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8-a+fp+simd")

gradle/libs.versions.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ appcompat = "1.7.1"
99
material = "1.13.0"
1010
coroutines = "1.8.1"
1111
annotation = "1.9.1"
12+
activity = "1.10.1"
13+
constraintlayout = "2.2.1"
14+
lifecycle = "2.9.0"
1215

1316
[libraries]
1417
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
@@ -21,6 +24,10 @@ material = { group = "com.google.android.material", name = "material", version.r
2124
kotlinx-coroutines-android = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-android", version.ref = "coroutines" }
2225
kotlinx-coroutines-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "coroutines" }
2326
kotlinx-coroutines-test = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-test", version.ref = "coroutines" }
27+
androidx-activity = { group = "androidx.activity", name = "activity-ktx", version.ref = "activity" }
28+
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
29+
androidx-lifecycle-viewmodel-ktx = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-ktx", version.ref = "lifecycle" }
30+
androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycle" }
2431

2532
[plugins]
2633
android-application = { id = "com.android.application", version.ref = "agp" }

sample/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

sample/build.gradle.kts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
plugins {
2+
id("com.android.application")
3+
id("org.jetbrains.kotlin.android")
4+
}
5+
6+
android {
7+
namespace = "com.llamakotlin.sample"
8+
compileSdk = 36
9+
10+
defaultConfig {
11+
applicationId = "com.llamakotlin.sample"
12+
minSdk = 24
13+
targetSdk = 36
14+
versionCode = 1
15+
versionName = "1.0"
16+
17+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
18+
}
19+
20+
buildTypes {
21+
release {
22+
isMinifyEnabled = false
23+
proguardFiles(
24+
getDefaultProguardFile("proguard-android-optimize.txt"),
25+
"proguard-rules.pro"
26+
)
27+
}
28+
}
29+
30+
compileOptions {
31+
sourceCompatibility = JavaVersion.VERSION_17
32+
targetCompatibility = JavaVersion.VERSION_17
33+
}
34+
35+
kotlinOptions {
36+
jvmTarget = "17"
37+
}
38+
39+
buildFeatures {
40+
viewBinding = true
41+
}
42+
}
43+
44+
dependencies {
45+
// Use the local library module
46+
implementation(project(":app"))
47+
48+
implementation(libs.androidx.core.ktx)
49+
implementation(libs.androidx.appcompat)
50+
implementation(libs.material)
51+
implementation(libs.androidx.activity)
52+
implementation(libs.androidx.constraintlayout)
53+
implementation(libs.kotlinx.coroutines.android)
54+
implementation(libs.androidx.lifecycle.viewmodel.ktx)
55+
implementation(libs.androidx.lifecycle.runtime.ktx)
56+
57+
testImplementation(libs.junit)
58+
androidTestImplementation(libs.androidx.junit)
59+
androidTestImplementation(libs.androidx.espresso.core)
60+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
4+
5+
<!-- Storage permission for loading model files -->
6+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
7+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
8+
android:maxSdkVersion="28" />
9+
10+
<application
11+
android:allowBackup="true"
12+
android:icon="@mipmap/ic_launcher"
13+
android:label="@string/app_name"
14+
android:roundIcon="@mipmap/ic_launcher_round"
15+
android:supportsRtl="true"
16+
android:theme="@style/Theme.LlamaKotlinAndroid"
17+
android:requestLegacyExternalStorage="true"
18+
tools:replace="android:theme">
19+
20+
<activity
21+
android:name=".MainActivity"
22+
android:exported="true"
23+
android:label="@string/app_name"
24+
android:theme="@style/Theme.LlamaKotlinAndroid">
25+
<intent-filter>
26+
<action android:name="android.intent.action.MAIN" />
27+
<category android:name="android.intent.category.LAUNCHER" />
28+
</intent-filter>
29+
</activity>
30+
</application>
31+
32+
</manifest>

0 commit comments

Comments
 (0)