Skip to content

Commit f39adc3

Browse files
committed
Introduce starter project for Android
Based on examples/llama.swiftui.
1 parent 76484fb commit f39adc3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1792
-0
lines changed

examples/llama.android/.gitignore

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Gradle files
2+
.gradle/
3+
build/
4+
5+
# Local configuration file (sdk path, etc)
6+
local.properties
7+
8+
# Log/OS Files
9+
*.log
10+
11+
# Android Studio generated files and folders
12+
captures/
13+
.externalNativeBuild/
14+
.cxx/
15+
*.apk
16+
output.json
17+
18+
# IntelliJ
19+
*.iml
20+
.idea/
21+
misc.xml
22+
deploymentTargetDropDown.xml
23+
render.experimental.xml
24+
25+
# Keystore files
26+
*.jks
27+
*.keystore
28+
29+
# Google Services (e.g. APIs or Firebase)
30+
google-services.json
31+
32+
# Android Profiling
33+
*.hprof

examples/llama.android/README.md

Whitespace-only changes.

examples/llama.android/app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
plugins {
2+
id("com.android.application")
3+
id("org.jetbrains.kotlin.android")
4+
}
5+
6+
android {
7+
namespace = "com.example.llama"
8+
compileSdk = 34
9+
10+
defaultConfig {
11+
applicationId = "com.example.llama"
12+
minSdk = 33
13+
targetSdk = 34
14+
versionCode = 1
15+
versionName = "1.0"
16+
17+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
18+
vectorDrawables {
19+
useSupportLibrary = true
20+
}
21+
externalNativeBuild {
22+
cmake {
23+
cppFlags += listOf()
24+
arguments += listOf()
25+
}
26+
}
27+
}
28+
29+
buildTypes {
30+
release {
31+
isMinifyEnabled = false
32+
proguardFiles(
33+
getDefaultProguardFile("proguard-android-optimize.txt"),
34+
"proguard-rules.pro"
35+
)
36+
}
37+
}
38+
compileOptions {
39+
sourceCompatibility = JavaVersion.VERSION_1_8
40+
targetCompatibility = JavaVersion.VERSION_1_8
41+
}
42+
kotlinOptions {
43+
jvmTarget = "1.8"
44+
}
45+
buildFeatures {
46+
compose = true
47+
}
48+
composeOptions {
49+
kotlinCompilerExtensionVersion = "1.5.1"
50+
}
51+
packaging {
52+
resources {
53+
excludes += "/META-INF/{AL2.0,LGPL2.1}"
54+
}
55+
}
56+
externalNativeBuild {
57+
cmake {
58+
path = file("src/main/cpp/CMakeLists.txt")
59+
version = "3.22.1"
60+
}
61+
}
62+
}
63+
64+
dependencies {
65+
66+
implementation("androidx.core:core-ktx:1.12.0")
67+
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2")
68+
implementation("androidx.activity:activity-compose:1.8.2")
69+
implementation(platform("androidx.compose:compose-bom:2023.08.00"))
70+
implementation("androidx.compose.ui:ui")
71+
implementation("androidx.compose.ui:ui-graphics")
72+
implementation("androidx.compose.ui:ui-tooling-preview")
73+
implementation("androidx.compose.material3:material3")
74+
testImplementation("junit:junit:4.13.2")
75+
androidTestImplementation("androidx.test.ext:junit:1.1.5")
76+
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
77+
androidTestImplementation(platform("androidx.compose:compose-bom:2023.08.00"))
78+
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
79+
debugImplementation("androidx.compose.ui:ui-tooling")
80+
debugImplementation("androidx.compose.ui:ui-test-manifest")
81+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.example.llama
2+
3+
import androidx.test.platform.app.InstrumentationRegistry
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
import org.junit.Assert.*
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* See [testing documentation](http://d.android.com/tools/testing).
15+
*/
16+
@RunWith(AndroidJUnit4::class)
17+
class ExampleInstrumentedTest {
18+
@Test
19+
fun useAppContext() {
20+
// Context of the app under test.
21+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22+
assertEquals("com.example.llama", appContext.packageName)
23+
}
24+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
<uses-permission android:name="android.permission.INTERNET" />
6+
7+
<application
8+
android:allowBackup="true"
9+
android:dataExtractionRules="@xml/data_extraction_rules"
10+
android:fullBackupContent="@xml/backup_rules"
11+
android:icon="@mipmap/ic_launcher"
12+
android:label="@string/app_name"
13+
android:roundIcon="@mipmap/ic_launcher_round"
14+
android:supportsRtl="true"
15+
android:theme="@style/Theme.LlamaAndroid"
16+
>
17+
18+
<activity
19+
android:name=".MainActivity"
20+
android:exported="true"
21+
android:theme="@style/Theme.LlamaAndroid">
22+
<intent-filter>
23+
<action android:name="android.intent.action.MAIN" />
24+
25+
<category android:name="android.intent.category.LAUNCHER" />
26+
</intent-filter>
27+
</activity>
28+
</application>
29+
30+
</manifest>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
# For more information about using CMake with Android Studio, read the
3+
# documentation: https://d.android.com/studio/projects/add-native-code.html.
4+
# For more examples on how to use CMake, see https://github.com/android/ndk-samples.
5+
6+
# Sets the minimum CMake version required for this project.
7+
cmake_minimum_required(VERSION 3.22.1)
8+
9+
# Declares the project name. The project name can be accessed via ${ PROJECT_NAME},
10+
# Since this is the top level CMakeLists.txt, the project name is also accessible
11+
# with ${CMAKE_PROJECT_NAME} (both CMake variables are in-sync within the top level
12+
# build script scope).
13+
project("llama-android")
14+
15+
include(FetchContent)
16+
FetchContent_Declare(
17+
llama
18+
GIT_REPOSITORY https://github.com/ggerganov/llama.cpp
19+
GIT_TAG 1fc2f265ff9377a37fd2c61eae9cd813a3491bea # b1794
20+
)
21+
22+
# Also provides "common"
23+
FetchContent_MakeAvailable(llama)
24+
25+
# Creates and names a library, sets it as either STATIC
26+
# or SHARED, and provides the relative paths to its source code.
27+
# You can define multiple libraries, and CMake builds them for you.
28+
# Gradle automatically packages shared libraries with your APK.
29+
#
30+
# In this top level CMakeLists.txt, ${CMAKE_PROJECT_NAME} is used to define
31+
# the target library name; in the sub-module's CMakeLists.txt, ${PROJECT_NAME}
32+
# is preferred for the same purpose.
33+
#
34+
# In order to load a library into your app from Java/Kotlin, you must call
35+
# System.loadLibrary() and pass the name of the library defined here;
36+
# for GameActivity/NativeActivity derived applications, the same library name must be
37+
# used in the AndroidManifest.xml file.
38+
add_library(${CMAKE_PROJECT_NAME} SHARED
39+
# List C/C++ source files with relative paths to this CMakeLists.txt.
40+
llama-android.cpp)
41+
42+
# Specifies libraries CMake should link to your target library. You
43+
# can link libraries from various origins, such as libraries defined in this
44+
# build script, prebuilt third-party libraries, or Android system libraries.
45+
target_link_libraries(${CMAKE_PROJECT_NAME}
46+
# List libraries link to the target library
47+
llama
48+
common
49+
android
50+
log)

0 commit comments

Comments
 (0)