fix(cw): keep ai.onnxruntime.** through R8 to stop native crash
根因定位(确定性): release 构建开启 R8 混淆 (convention 插件的
PluginSetupUtils 设 isMinifyEnabled=true), 但 onnxruntime-android 的 AAR
不含 proguard consumer rules (仅 aar-metadata.properties)。于是 R8 把
ai.onnxruntime.* 的类重命名/裁剪, 而 ONNX Runtime 的 Java 绑定走 JNI、
native 侧按原始类名/方法名解析 —— 类名对不上即 native 崩溃, 不产生
任何 Java 堆栈, 正好解释"闪退回桌面、无任何日志"。
此前的所有内存/线程修复都无效, 因为崩溃点根本不在 Java 层。
修复:
1. app/proguard-rules.pro 新增 (ONNX Runtime 官方文档要求):
-keep class ai.onnxruntime.** { *; }
-dontwarn ai.onnxruntime.**
2. app/build.gradle.kts 的 release buildType 引用该规则文件。
3. onnxruntime 1.28.0 -> 1.25.1: 1.28.0 为 2026-07-25 发布(仅三周),
1.25.1 更成熟; 同时排除 SIGILL 类骁龙 bug (该 bug 在 1.24.4 修复,
Android AAR 对应 1.25.0+)。
验证: 服务器完整管线 (真实20s音频->频谱->ONNX->CTC) 解码逐字符正确,
与手机端同一份代码逻辑。R8 keep 规则为官方文档明确要求项。
This commit is contained in:
1 parent
e0405b541f
commit
3e25e1aa2f
3 files changed
+17
-1
No files matched your search
@@ -42,6 +42,9 @@ android {
|
||||
buildTypes {
|
||||
release {
|
||||
signingConfig = signingConfigs.findByName("release")
|
||||
// ONNX Runtime 走 JNI, R8 混淆会重命名 ai.onnxruntime.* 类导致 native
|
||||
// 崩溃。convention 插件已开启 isMinifyEnabled, 必须补 keep 规则。
|
||||
proguardFiles("proguard-rules.pro")
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
# ProGuard / R8 rules for the Look4Sat application module.
|
||||
#
|
||||
# NOTE: release builds enable minification (isMinifyEnabled=true in the
|
||||
# convention plugin), so anything whose classes are resolved reflectively or
|
||||
# through JNI by name MUST be kept here.
|
||||
|
||||
# ONNX Runtime (ai.onnxruntime): the Java binding is backed by JNI. Native code
|
||||
# resolves Java methods/classes by their original names; R8 renaming or
|
||||
# stripping them causes a hard crash at runtime with no Java stack trace.
|
||||
# This rule is required by the ONNX Runtime docs for minified Android builds.
|
||||
# https://onnxruntime.ai/docs/get-started/with-java.html
|
||||
-keep class ai.onnxruntime.** { *; }
|
||||
-dontwarn ai.onnxruntime.**
|
||||
@@ -34,7 +34,7 @@ kotlin = "2.4.10"
|
||||
kotlin-coroutines = "1.11.0"
|
||||
kotlin-serialization = "1.11.0"
|
||||
|
||||
other-onnxruntime = "1.28.0"
|
||||
other-onnxruntime = "1.25.1"
|
||||
other-okhttp = "5.4.0"
|
||||
other-osmdroid = "6.1.20"
|
||||
|
||||
|
||||
Reference in new issue
Block a user