Skip to content

preserve native classes from R8 minification and add dynamic minification to debug build - #797

Merged
andrewtavis merged 6 commits into
scribe-org:mainfrom
ashb155:fix/jni-proguard-rules
Nov 28, 2026
Merged

andrewtavis merged 6 commits into
scribe-org:mainfrom
ashb155:fix/jni-proguard-rules

Conversation

@ashb155

@ashb155 ashb155 commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator

Contributor checklist


Description

Fixes the crash (UnsatisfiedLinkError in ProximityInfo.setProximityInfoNative) occurring in closed testing release builds.

R8 code shrinking in release builds was stripping JNI classes (like BinaryDictionaryUtils), causing JNI_OnLoad in C++ to fail (-1) and abort loading libjni_latinime.so.

  • app/proguard-rules.pro: Added keep rules for be.scri.inputmethod.** and be.scri.latin.** so R8 does not strip JNI classes (BinaryDictionaryUtils, BinaryDictionary, etc.) that are registered at runtime via JNI_OnLoad.
  • app/build.gradle.kts: Added a fallback to the debug signing key if keystore.properties is absent, allowing local testing of release builds on emulators via .\gradlew installKeyboardsRelease.

Related issue

@ashb155

ashb155 commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator Author

just noting it here, .\gradlew installKeyboardsRelease can be run to test and verify the actual release build on the emulator (or switching the build variant to keyboardRelease and hitting Run) before releasing

@andrewtavis @angrezichatterbox

@angrezichatterbox

Copy link
Copy Markdown
Member

I will take look into this. I have a few suggestions so that we can prevent such issues from happening again.

@angrezichatterbox angrezichatterbox left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/ashb155/Scribe-Android/blob/87a9c3f75d86763ced969c79d13c182b875b0342/app/src/main/java/be/scri/helpers/NativeSuggestionEngine.kt#L33

Here could we have a try error to catch this error maybe. This would make sure that we the autosuggestion native modules don't cause crashes if they don't get added. We would also have to catch it at other places as well I suppose. This would make it full proof over long term.

We could also have a check on this on such cases.

The only issue with doing this we wouldn't know that the app has certain issues.

@andrewtavis is there any way we could add sentry like bug reports for open source app without invading user privacy. This could be on the longer term however just thought of bringing it up.

@andrewtavis

Copy link
Copy Markdown
Member

Just checking though that if the autosuggestion native modules aren't being added, then we might need to look into alternatives?

And re Sentry: I'm not 100% opposed to adding anything that would help the development community maintain the apps, but we'd need to discuss user privacy for sure. Sentry is at the very least GDPR compliant, but we'd definitely need a privacy policy update. Let's see if we can get through this current issue and then how the stability is after that. Then we can continue this conversation then as people see a need :)

@angrezichatterbox

Copy link
Copy Markdown
Member

Just checking though that if the autosuggestion native modules aren't being added, then we might need to look into alternatives?

They would be added now. The native files that were required where being removed from the release build unless we state not to to minify the application. The suggestion I made there was to make sure that such native required instead of crashing the app would just fall back to the db or autosuggestions not working instead of causing crash which kills the experiance a bit for users.

Comment thread CHANGELOG.md Resolved
@andrewtavis

Copy link
Copy Markdown
Member

They would be added now. The native files that were required where being removed from the release build unless we state not to to minify the application. The suggestion I made there was to make sure that such native required instead of crashing the app would just fall back to the db or autosuggestions not working instead of causing crash which kills the experiance a bit for users.

Ah yes, ok :) I guess that we should be able to get notified if things aren't working properly from an eventual user base and we want to make sure that we don't have the app breaking on people who we don't have a connection to, so could be something that we add in to make sure that we don't have random crashes killing the user experience.

@andrewtavis andrewtavis added the -next release- Included in the next release label Nov 22, 2026
@ashb155

ashb155 commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator Author

Ah yes, ok :) I guess that we should be able to get notified if things aren't working properly from an eventual user base and we want to make sure that we don't have the app breaking on people who we don't have a connection to, so could be something that we add in to make sure that we don't have random crashes killing the user experience.

one more thing we could explore down the line would be integrations using Firebase Crashlytics and BigQuery to track crash diagnostics and stack traces in detail. User details can be completely anonymized (which is what I do on the other app I maintain—the free tier covers about 60 days of retention before expiring), and it gives visibility into uncaught exceptions in production without storing personal data.

we might have to look at the privacy angle as well once!

@ashb155
ashb155 force-pushed the fix/jni-proguard-rules branch from 87a9c3f to 5be6a93 Compare November 22, 2026 17:32
@angrezichatterbox angrezichatterbox linked an issue Nov 22, 2026 that may be closed by this pull request
2 tasks done
@andrewtavis

Copy link
Copy Markdown
Member

@angrezichatterbox, feel free to merge this in once it's at a state that you're happy with it :) Sounds like you two have been discussing this a fair amount, so merge away once you both are ok with the fix 😊

@ashb155

ashb155 commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator Author

updated and added the native fallbacks that @angrezichatterbox mentioned
check for JniUtils.sHaveGestureLib (isNativeAvailable) before attempting any native operations
made dummyProximityInfo lazy and safely wrapped in a try/catch so class instantiation never fails
catch Throwable across all suggestion calls so any UnsatisfiedLinkError or linkage failures degrade gracefully and return empty suggestions instead of crashing

Comment thread CHANGELOG.md

- ProGuard keep rules were added for JNI-bound classes and methods, preventing crashes in release builds ([#796](https://github.com/scribe-org/Scribe-Android/issues/796)).
- ProGuard keep rules and defensive fallbacks in NativeSuggestionEngine were added for JNI-bound classes and methods, preventing crashes in release builds ([#796](https://github.com/scribe-org/Scribe-Android/issues/796)).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appreciate the attention to detail in adding in the space here :)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do let me know if there are any other changes required @andrewtavis

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll let @angrezichatterbox give the final word on this one, but to me this all looks great!

@ashb155 ashb155 mentioned this pull request Nov 22, 2026
2 tasks done
Comment thread app/build.gradle.kts Outdated
Comment on lines 138 to 144
signingConfig =
if (keystorePropertiesFile.exists()) {
signingConfigs.getByName("release")
} else {
signingConfigs.getByName("debug")
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ashb155 Could we have this removed.

@ashb155 ashb155 Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@angrezichatterbox, i had specifically kept this, as without this fallback installRelease fails for anyone who doesn't have the release keystore, so contributors can't test release builds

@ashb155 ashb155 Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you want me to remove it here, the dummy keystore generation would anyways need to be done in the smoke test in #800
only thing would be that contributors won't be able to test release builds locally

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we maybe look into a better way to do this. Instead of doing it with the release build. We could have minified debug builds created maybe.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally CI/CD pipelines should fail when the keystore values aren't present if we move to a proper pipeline

@angrezichatterbox angrezichatterbox Nov 23, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a debug build have a propertiy minify instead where we can pass it as a flag. How does that sound. Open to a discussion on this

@ashb155 ashb155 Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm that makes sense as well, i've implemented separate minifiedDebug build rn here and in #800 but if you want me to clean this up and implement debug with the minify flag as well i can!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you clean it up maybe so that we can just pass a flag to the debug build to get a minified version

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea will do

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have integrated dynamic minification to the debug build through the flag

now supports
./gradlew assembleKeyboardsDebug -Pminify (or -Pminify=true)
./gradlew installKeyboardsDebug -Pminify (or -Pminify=true)

@ashb155 ashb155 changed the title preserve native classes from R8 minification and add fallback signing config preserve native classes from R8 minification and add minifiedDebug build type Nov 23, 2026
@ashb155 ashb155 changed the title preserve native classes from R8 minification and add minifiedDebug build type preserve native classes from R8 minification and add dynamic minification to debug build Nov 24, 2026

@andrewtavis andrewtavis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: Thanks for the PR and quick reaction to the issue, @ashb155! Also appreciate the detailed review, @angrezichatterbox! Based on the discussion here it sounds like this is good enough to bring in. Changes have also at least been glanced at by @Roniscend as they're also in #800. Any further changes are welcome in a new PR!

@andrewtavis
andrewtavis merged commit d5cc877 into scribe-org:main Nov 28, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

-next release- Included in the next release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash in closed testing: UnsatisfiedLinkError in ProximityInfo

3 participants