Skip to content

Commit 1d43b7b

Browse files
committed
feat(android): migrate app to Kotlin, Compose, and Gradle Kotlin DSL
Rewrite the demo app in Kotlin with a Material3 Compose UI, convert Gradle scripts to .kts, raise minSdk to API 30, and remove leftover View-based scaffolding (XML layouts, placeholder tests, appcompat dependencies).
1 parent 32e6bf9 commit 1d43b7b

35 files changed

Lines changed: 360 additions & 546 deletions

.github/workflows/android.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- name: Setup Android SDK
3737
uses: android-actions/setup-android@v3
3838
with:
39-
packages: 'platforms;android-34 build-tools;34.0.0'
39+
packages: 'platforms;android-36 build-tools;36.0.0'
4040

4141
# sdkmanager has no bare "ndk" package — must install "ndk;X.Y.Z". Pick the
4242
# newest side-by-side NDK from the package list.
@@ -79,13 +79,13 @@ jobs:
7979
python -m tn --language zh --overwrite_cache --cache_dir "$assets"
8080
python -m itn --language zh --overwrite_cache --cache_dir "$assets"
8181
82-
- name: Build APK
82+
- name: Build release APK
8383
working-directory: runtime/android
84-
run: ./gradlew :app:assembleDebug -PabiFilters=arm64-v8a --no-daemon
84+
run: ./gradlew :app:assembleRelease -PabiFilters=arm64-v8a --no-daemon
8585

86-
- name: Upload APK
86+
- name: Upload release APK
8787
uses: actions/upload-artifact@v4
8888
with:
89-
name: app-debug-arm64-v8a
90-
path: runtime/android/app/build/outputs/apk/debug/app-debug.apk
89+
name: app-release-arm64-v8a
90+
path: runtime/android/app/build/outputs/apk/release/app-release.apk
9191
if-no-files-found: error

runtime/CMakePresets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"generator": "Ninja",
2020
"cacheVariables": {
2121
"CMAKE_TOOLCHAIN_FILE": "$env{ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake",
22-
"ANDROID_PLATFORM": "android-21",
22+
"ANDROID_PLATFORM": "android-30",
2323
"CMAKE_BUILD_TYPE": "Release"
2424
}
2525
},

runtime/android/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
*.iml
22
.gradle
3+
.kotlin/
34
/local.properties
45
/.idea/caches
56
/.idea/libraries

runtime/android/app/build.gradle

Lines changed: 0 additions & 68 deletions
This file was deleted.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
plugins {
2+
// AGP 9 has built-in Kotlin support (it bundles KGP and enables it by default),
3+
// so the org.jetbrains.kotlin.android plugin must NOT be applied here.
4+
alias(libs.plugins.android.application)
5+
// Compose compiler plugin (required since Kotlin 2.0+).
6+
alias(libs.plugins.compose.compiler)
7+
}
8+
9+
fun nativeAbis(): List<String> =
10+
(project.findProperty("abiFilters") as String? ?: "armeabi-v7a,arm64-v8a,x86,x86_64")
11+
.split(",").map { it.trim() }.filter { it.isNotEmpty() }
12+
13+
android {
14+
namespace = "com.wenet.WeTextProcessing"
15+
lint {
16+
abortOnError = false
17+
}
18+
signingConfigs {
19+
create("release") {
20+
storeFile = file("wenet.keystore")
21+
storePassword = "123456"
22+
keyAlias = "wenet"
23+
keyPassword = "123456"
24+
}
25+
}
26+
compileSdk = 36
27+
28+
defaultConfig {
29+
applicationId = "com.wenet.WeTextProcessing"
30+
minSdk = 30
31+
targetSdk = 36
32+
versionCode = 1
33+
versionName = "1.0"
34+
35+
ndk {
36+
abiFilters.addAll(nativeAbis())
37+
}
38+
}
39+
40+
buildTypes {
41+
release {
42+
isMinifyEnabled = false
43+
signingConfig = signingConfigs.getByName("release")
44+
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
45+
}
46+
}
47+
compileOptions {
48+
sourceCompatibility = JavaVersion.VERSION_17
49+
targetCompatibility = JavaVersion.VERSION_17
50+
}
51+
// Built-in Kotlin defaults jvmTarget to compileOptions.targetCompatibility (17).
52+
buildFeatures {
53+
compose = true
54+
}
55+
}
56+
57+
dependencies {
58+
implementation(platform(libs.androidx.compose.bom))
59+
60+
implementation(libs.androidx.activity.compose)
61+
implementation(libs.androidx.compose.ui)
62+
implementation(libs.androidx.compose.ui.graphics)
63+
implementation(libs.androidx.compose.ui.tooling.preview)
64+
implementation(libs.androidx.compose.material3)
65+
debugImplementation(libs.androidx.compose.ui.tooling)
66+
}
67+
68+
// Native libs are NOT built by Gradle. Build them beforehand with CMake presets
69+
// (from repo root) so the .so files exist in app/src/main/jniLibs/<abi>/:
70+
// export ANDROID_NDK_HOME=$ANDROID_HOME/ndk/<version>
71+
// cd runtime
72+
// cmake --preset android-arm64-v8a
73+
// cmake --build --preset android-arm64-v8a
74+
// cmake --install build/aarch64-linux-android --component jni
75+
// Gradle only packages whatever is already present under jniLibs.

runtime/android/app/src/androidTest/java/com/wenet/WeTextProcessing/ExampleInstrumentedTest.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

runtime/android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
<?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">
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
43
<application
54
android:allowBackup="true"
65
android:icon="@mipmap/ic_launcher"
76
android:label="@string/app_name"
87
android:roundIcon="@mipmap/ic_launcher_round"
98
android:supportsRtl="true"
10-
tools:replace="android:theme"
119
android:theme="@style/Theme.Wenet">
1210
<activity
1311
android:name=".MainActivity"

runtime/android/app/src/main/assets/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Android model assets
22

3-
The app loads four FST models at runtime (see `MainActivity.java` and
3+
The app loads four FST models at runtime (see `MainActivity.kt` and
44
`wetextprocessing.cc`). They are **not** checked into git and must be placed in
55
this directory before building the APK:
66

runtime/android/app/src/main/java/com/wenet/WeTextProcessing/MainActivity.java

Lines changed: 0 additions & 78 deletions
This file was deleted.

0 commit comments

Comments
 (0)