diff --git a/app/build.gradle.kts b/app/build.gradle.kts index b6e78cc4..a2116122 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -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") } } } diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 00000000..a9c3aafe --- /dev/null +++ b/app/proguard-rules.pro @@ -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.** diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 1747733f..82beb8ef 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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"