Skip to content

Commit f9f5318

Browse files
committed
Add Android Kotlin CI example
1 parent 1e46915 commit f9f5318

9 files changed

Lines changed: 167 additions & 0 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Android Kotlin
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: "0 8 * * 1"
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
build-android-kotlin-app:
13+
name: Build Android Kotlin app
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- uses: actions/setup-java@v4
19+
with:
20+
distribution: temurin
21+
java-version: "21"
22+
23+
- uses: android-actions/setup-android@v3
24+
25+
- name: Install Android SDK packages
26+
run: sdkmanager "platforms;android-36" "build-tools;36.0.0"
27+
28+
- name: Build Ladybug Java jar
29+
env:
30+
SKIP_CMAKE_BUILD: "true"
31+
run: |
32+
./gradlew jar
33+
echo "LBUG_JAR=$(ls "$GITHUB_WORKSPACE"/build/libs/lbug-*.jar | head -n 1)" >> "$GITHUB_ENV"
34+
35+
- name: Build Android Kotlin example
36+
run: ./gradlew -p examples/android-kotlin :app:assembleDebug -PlbugJar="$LBUG_JAR"
37+
38+
- name: Test Android Kotlin example on emulator
39+
uses: ReactiveCircus/android-emulator-runner@v2
40+
with:
41+
api-level: 35
42+
target: google_apis
43+
arch: x86_64
44+
profile: pixel_6
45+
script: ./gradlew -p examples/android-kotlin :app:connectedDebugAndroidTest -PlbugJar="$LBUG_JAR"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
plugins {
2+
id 'com.android.application'
3+
}
4+
5+
android {
6+
namespace 'com.ladybugdb.example'
7+
compileSdk 36
8+
9+
defaultConfig {
10+
applicationId 'com.ladybugdb.example'
11+
minSdk 26
12+
targetSdk 36
13+
versionCode 1
14+
versionName '1.0'
15+
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
16+
}
17+
}
18+
19+
dependencies {
20+
def lbugJar = providers.gradleProperty('lbugJar')
21+
if (!lbugJar.isPresent()) {
22+
throw new GradleException('Pass -PlbugJar=/path/to/lbug.jar')
23+
}
24+
implementation files(lbugJar.get())
25+
androidTestImplementation 'androidx.test:core-ktx:1.6.1'
26+
androidTestImplementation 'androidx.test.ext:junit-ktx:1.2.1'
27+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.ladybugdb.example
2+
3+
import androidx.test.core.app.ActivityScenario
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
import org.junit.Assert.assertEquals
6+
import org.junit.Assert.assertNotNull
7+
import org.junit.Test
8+
import org.junit.runner.RunWith
9+
10+
@RunWith(AndroidJUnit4::class)
11+
class MainActivityInstrumentedTest {
12+
@Test
13+
fun kotlinApiCanCreateConfigOnAndroid() {
14+
val config = exampleConfig()
15+
16+
assertEquals(2, config.maxNumThreads)
17+
assertEquals(true, config.enableDefaultHashIndex)
18+
}
19+
20+
@Test
21+
fun activityLaunchesOnAndroid() {
22+
ActivityScenario.launch(MainActivity::class.java).use { scenario ->
23+
scenario.onActivity { activity ->
24+
assertNotNull(activity.window.decorView)
25+
}
26+
}
27+
}
28+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
<application
3+
android:theme="@style/AppTheme"
4+
android:label="@string/app_name"
5+
android:allowBackup="false"
6+
android:supportsRtl="true">
7+
<activity
8+
android:name=".MainActivity"
9+
android:exported="true">
10+
<intent-filter>
11+
<action android:name="android.intent.action.MAIN" />
12+
<category android:name="android.intent.category.LAUNCHER" />
13+
</intent-filter>
14+
</activity>
15+
</application>
16+
</manifest>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.ladybugdb.example
2+
3+
import android.app.Activity
4+
import android.os.Bundle
5+
import android.widget.TextView
6+
import com.ladybugdb.Database
7+
import com.ladybugdb.SystemConfig
8+
9+
class MainActivity : Activity() {
10+
override fun onCreate(savedInstanceState: Bundle?) {
11+
super.onCreate(savedInstanceState)
12+
val config = exampleConfig()
13+
setContentView(TextView(this).apply {
14+
text = "LadybugDB Kotlin example: ${config.maxNumThreads} threads"
15+
})
16+
}
17+
}
18+
19+
fun exampleConfig(): SystemConfig = SystemConfig().apply {
20+
maxNumThreads = 2
21+
enableDefaultHashIndex = true
22+
}
23+
24+
fun openDatabase(path: String, config: SystemConfig): Database = Database(path, config)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<resources>
2+
<string name="app_name">LadybugDB Kotlin</string>
3+
</resources>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<resources>
2+
<style name="AppTheme" parent="android:style/Theme.Material.Light.NoActionBar" />
3+
</resources>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
plugins {
2+
id 'com.android.application' version '9.0.0' apply false
3+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
pluginManagement {
2+
repositories {
3+
google()
4+
mavenCentral()
5+
gradlePluginPortal()
6+
}
7+
}
8+
9+
dependencyResolutionManagement {
10+
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
11+
repositories {
12+
google()
13+
mavenCentral()
14+
}
15+
}
16+
17+
rootProject.name = 'ladybug-android-kotlin-example'
18+
include ':app'

0 commit comments

Comments
 (0)