Skip to content

change(android): use webview asset loader 🍒 🏠 - #16628

Merged
mcdurdin merged 14 commits into
stable-18.0from
change/android/cherrypick/use-webview-asset-loader
Sep 22, 2026
Merged

mcdurdin merged 14 commits into
stable-18.0from
change/android/cherrypick/use-webview-asset-loader

Conversation

@jahorton

@jahorton jahorton commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Cherry-pick-of: #16146
Cherry-pick-of: #16188
Cherry-pick-of: #16184
Relates-to: #13862
Follows: #16604
Fixes: KEYMAN-WEB-RB
Fixes: KEYMAN-WEB-Z8
Fixes: KEYMAN-WEB-MD
Fixes: KEYMAN-WEB-YV
Fixes: KEYMAN-WEB-YW
Fixes: KEYMAN-WEB-YX

Use WebViewAssetLoader in order to stop using file:// URLs for loading all assets in the keyboard WebView. In this case, for lexical models, as an attempt to resolve (sample) error: Error occurred when attempting to load dictionary NetworkError: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at 'file:///data/user/0/com.tavultesoft.kmapro/app_data/models/nrc.en.mtnt/nrc.en.mtnt.model.js' failed to load.

While we originally made the change to using WebViewAssetLoader in order to support use of the window.fetch() API for keyboard loading in version 19, we hope that the same solution will address the crash report when loading of predictive-text models on Android in Chrome 152.0 and later versions. This error was sporadically happening with earlier versions of Chrome (20 per month or so) but is frequent now -- we've been getting nearly 10,000 error reports daily.

Per MDN reference, NetworkError is received when an incorrect MIME type is used. While this error does not seem to be happening on our test devices or any device we have access to, we theorize that there could be some environmental cause for file:/// based URLs (for lexical models) being labelled with incorrect MIME-type info (another app with bogus registered MIME type for .js? something like that?).

Using an asset-loader scheme would provide an https://-like URL and a "server" that would provide proper MIME-info, resolving what we now hope to be the underlying cause of the frequent error report. It's hard to know for sure at present due to our current inability to reproduce the issue.

Build-bot: skip release:android

User Testing

TEST_SMOKE: Verify that the Android app loads properly and that it properly swaps among installed keyboards and lexical models without issue. If a keyboard that should have an associated model does not display predictive text, FAIL this test. Verify that the correct font is used in the OSK and the input area in the Keyman app (e.g. try with the 'Lakeside' keyboard).

TEST_FIRSTVOICES: install FirstVoices Keyboards for Android apk. Try different keyboards, verify that the OSK and displayed text look correct. For SENCOTEN, verify that predictive text is working.

ermshiperete and others added 9 commits September 21, 2026 10:04
This change moves to using `WebViewAssetLoader` for loading files from
the device instead of using file:// URLs. This fixes the blank keyboard
problem reported in #16096 for Android.

Also make `KMKeyboard.getKeyboardRoot()` private, and rename public
`Keyboard.getKeyboardPath()` to private `Keyboard.getKeyboardUrl()`.

Part-of: #16096
Co-authored-by: Marc Durdin <marc@durdin.net>
Also fix `assertEquals` in that test file - the parameter ordering is
`expected, actual` but we had it the other way round which gives a
confusing message if the test fails.
On Windows the tests failed because the AppData directory doesn't yet
exist under an allowed app internal storage path. This change creates
the directory first when running tests.
Fixes: FV-ANDROID-20E
Build-bot: release:android
The default fonts (DejaVueSans.ttf and keymanweb-osk.ttf) are located in
the root directory, not the package directory. This fixes the
KeyboardHarness test app.

Also some improvements with variable and function names to better match
what they do.
Cherry-pick-of: #16146

We use SIL EuroLatin as fallback keyboard. If that is not installed,
previously we output an error which showed up as a toast for the user.
This change now outputs a warning instead of the error for the default
keyboard.

Also changed the KeyboardHarness test app to set a different keyoard as
default.
@github-project-automation github-project-automation Bot moved this to Todo in Keyman Sep 21, 2026
@keymanapp-test-bot keymanapp-test-bot Bot added the user-test-required User tests have not been completed label Sep 21, 2026
@keymanapp-test-bot

keymanapp-test-bot Bot commented Sep 21, 2026

Copy link
Copy Markdown

User Test Results

Test specification and instructions

Test Artifacts

@keymanapp-test-bot keymanapp-test-bot Bot changed the title change(android): use webview asset loader 🍒 change(android): use webview asset loader 🍒 🏠 Sep 21, 2026
@keymanapp-test-bot keymanapp-test-bot Bot added this to the B19S2 milestone Sep 21, 2026
@github-actions github-actions Bot added change Minor change in functionality, but not new cherry-pick Change already merged into another (stable) branch stable labels Sep 21, 2026
mcdurdin and others added 5 commits September 22, 2026 06:08
PR #16146 introduced a problem with selecting a different font as
display font so that we always ended up with not setting the font.
This was caused by the font filenames now being a URL (which is necessary
because they get processed by the web engine). However, the Android code
checks for the existence of the font in order to create the typeface,
which only works for local paths.

This PR modifies and simplifies `KMKeyboard.getFontFilename` to return the
full path, renames `KMKeyboard.txtFont` and `KMKeyboard.oskFont` to make
it clearer that they contain a path and not a URL.

Also initialize `KMKeyboard.oskFontPath` with empty string instead of
`null`. This makes it consistent with` txtFontPath` and with the
documented behavior of `KMManager.getKeyboardOskFontFilename()` (which
returns `KMKeyboard.oskFontPath`).

Follows: #16146
Fixes: #16187
Build-bot: release:android
Co-authored-by: Marc Durdin <marc@durdin.net>
Co-authored-by: Eberhard Beilharz <ermshiperete@users.noreply.github.com>
Co-authored-by: Marc Durdin <marc@durdin.net>
@mcdurdin

Copy link
Copy Markdown
Member

Test Results

  • TEST_SMOKE (PASS): Installed app, tested in-app and system keyboard, sil_euro_latin, khmer_angkor, and luo_lakeside. Predictive text worked no problems with sil_euro_latin and khmer_angkor. Fonts loaded correctly for all three keyboards - in OSK and text area in Keyman app. Connected to DevTools, verified no errors, appassets.androidplatform.net domain. Everything looks good.
  • TEST_FIRSTVOICES (PASS): Installed app, tested system keyboard, sil_euro_latin, fv_sencoten. Predictive text worked correctly for both keyboards. All looks correct. Connected to DevTools, verified no errors, appassets.androidplatform.net domain. No errors encountered.

@keymanapp-test-bot keymanapp-test-bot Bot removed the user-test-required User tests have not been completed label Sep 22, 2026
@Meng-Heng

Meng-Heng commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Test Specs

  1. Keyman device: OPPO A60 Android v16
  2. FirstVoices device: Android Studio: Pixel 6a API 33

Test Results

  • TEST_SMOKE (PASSED):
  1. Keyman launch with EuroLatin (SIL) keyboard with predictive text -> Dismiss Get Started instructions
  2. Go to Settings -> Click 'Install Keyboard or Dictionary' -> Search Khmer -> Install Khmer Angkor
  3. VERIFIED: Khmer Angkor keyboard loads with predictive text
  4. Switching keyboards work as expected
  5. Go to Settings -> Install Keyboard or Dictionary -> Search Lakeside -> Install Lakeside
  6. Lakeside keyboard loads with Keyman banner
  7. Type qwe (positional keys on the keyboard) with the Lakeside keyboard
  8. Switch to Khmer Angkor and EuroLatin (SIL) keyboard
  9. VERIFIED:
    • The correct font applied to OSK and Input area for Lakeside keyboard
    • Switching keyboards with the predictive text rendered accordingly.
  • TEST_FIRSTVOICES (PASSED):
  1. FirstVoices launch -> Select keyboards -> Atlantic: Mi'gmawi'simg + BC Coast: SENCOTEN
  2. Follow all of the 3 setup requirements in FirstVoices app
  3. Open Chrome -> Start Typing
  4. VERIFIED: Predictive text work as expected; predict words according to the typed text. OSK and displayed text look correct.

@mcdurdin
mcdurdin merged commit 7930e15 into stable-18.0 Sep 22, 2026
6 checks passed
@mcdurdin
mcdurdin deleted the change/android/cherrypick/use-webview-asset-loader branch September 22, 2026 07:42
@github-project-automation github-project-automation Bot moved this from Todo to Done in Keyman Sep 22, 2026
@keyman-server

Copy link
Copy Markdown
Collaborator

Changes in this pull request will be available for download in Keyman version 18.0.252

@mcdurdin

Copy link
Copy Markdown
Member

One event received in 18.0.252 last night, which appears unrelated but was bundled under the same issue in Sentry:

Error:  Error occurred when attempting to load dictionary
SyntaxError: Invalid or unexpected token
{
  configReport: {
    embeddingApp: AndroidMobile,
      hostDevice: {
        browser: native,
        formFactor: phone,
        OS: android,
        touchable: true
      },
    initialized: true,
    keymanEngine: app/webview
  },

  keyboard: {
    id: sil_euro_latin::sil_euro_latin,
    langId: en,
    version: 2.0.4
  },

  model: {
    id: nrc.en.mtnt
  },

  osk: {
    banner: suggestion,
    layer: shift
  }
}

Unclear if the error is arising from nrc.en.mtnt or from another model they have installed on their device (the error message could list the model name!)

pull Bot pushed a commit to soitun/keyman that referenced this pull request Sep 24, 2026
Some error messages do not include the URL, so it can be hard to
disambiguate them. Will not back-port to 18.0, because the errors are
currently rare.

See-also: keymanapp#16628
Test-bot: skip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants