Title: Static binding names never match at runtime since 9.0.0 — every `extend()` falls back to runtime dex generation · Issue #2024 · NativeScript/android · GitHub
Open Graph Title: Static binding names never match at runtime since 9.0.0 — every `extend()` falls back to runtime dex generation · Issue #2024 · NativeScript/android
X Title: Static binding names never match at runtime since 9.0.0 — every `extend()` falls back to runtime dex generation · Issue #2024 · NativeScript/android
Description: Since 9.0.0, the class name the static binding generator emits and the class name the runtime asks for are different, so DexFactory.resolveClass never finds a pre-generated binding and generates a proxy dex at runtime for every anonymous...
Open Graph Description: Since 9.0.0, the class name the static binding generator emits and the class name the runtime asks for are different, so DexFactory.resolveClass never finds a pre-generated binding and generates a ...
X Description: Since 9.0.0, the class name the static binding generator emits and the class name the runtime asks for are different, so DexFactory.resolveClass never finds a pre-generated binding and generates a ...
Opengraph URL: https://github.com/NativeScript/android/issues/2024
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Static binding names never match at runtime since 9.0.0 — every `extend()` falls back to runtime dex generation","articleBody":"Since `9.0.0`, the class name the **static binding generator** emits and the class name the **runtime** asks for are different, so `DexFactory.resolveClass` never finds a pre-generated binding and generates a proxy dex at runtime for *every* anonymous `extend()` in the app — including the ~60 that `@nativescript/core` itself performs (gesture listeners, click listeners, adapters, fragments, …).\n\nIt is invisible on healthy devices (it \"only\" costs startup time), but it turns a whole class of storage/IO/concurrency failures in `DexFactory` into hard failures of the app. It also means the pre-generated bindings that ship in every APK/AAB are dead weight.\n\nTwo independent defects stack up. The first one alone is enough to break the match.\n\n---\n\n## Defect 1 — the SBG appends an MD5 the runtime never computes\n\n[#1836](https://github.com/NativeScript/android/pull/1836) (`feat: ES modules (ESM) support`, released in `9.0.0`) changed the naming in `Generator.java`:\n\n```diff\n- // name of the class: last portion of the full file name + line + column + variable name\n- String[] lastFilePathPart = dataRow.getFile().split(\"_\");\n- name += lastFilePathPart[lastFilePathPart.length - 1] + \"_\" + dataRow.getLine() + \"_\" + dataRow.getColumn() + \"_\" + dataRow.getNewClassName();\n+ // Generate a unique identifier that prevents naming collisions\n+ // especially with .mjs files and complex structures\n+ String fileIdentifier = generateUniqueFileIdentifier(dataRow.getFile());\n+ name += fileIdentifier + \"_\" + dataRow.getLine() + \"_\" + dataRow.getColumn() + \"_\" + dataRow.getNewClassName();\n```\n\n`generateUniqueFileIdentifier` returns `\u003clast up-to-3 \"_\"-segments>_\u003cfirst 3 bytes of md5(filePath) as hex>`.\n\nThe runtime side of the same name — `MetadataNode::GetExtendLocation` in `MetadataNode.cpp` — still does what the old SBG line did:\n\n```cpp\nUtil::SplitString(fullPathToFile, \"_\", pathParts);\nstd::string lastPathPart = pathParts.back();\nfullPathToFile = lastPathPart;\n```\n\nThere is no MD5 anywhere in the runtime. `#1836` did not touch `MetadataNode.cpp` (see the PR's file list), and `git log` on `test-app/runtime/src/main/cpp/MetadataNode.cpp` shows no commit between `2025-02-20` and `2026-08-03`. So from `9.0.0` on, the SBG emits `…_vendor_7c3613_…` while the runtime asks for `…_vendor_…`.\n\n## Defect 2 — the runtime strips 3 characters assuming `.js`, but bundles are `.mjs`\n\nSame function, `9.0.4` / `9.0.5`:\n\n```cpp\nint strToTakeLen = (srcFileName.length() - startIndex - 3); // 3 refers to .js at the end of file name\nfullPathToFile = srcFileName.substr(startIndex, strToTakeLen);\n\nstd::replace(fullPathToFile.begin(), fullPathToFile.end(), '/', '_');\nstd::replace(fullPathToFile.begin(), fullPathToFile.end(), '.', '_');\n…\nstd::vector\u003cstd::string> pathParts;\nUtil::SplitString(fullPathToFile, \"_\", pathParts);\nstd::string lastPathPart = pathParts.back();\n```\n\nWith `file:///data/data/\u003cpkg>/files/app/vendor.mjs`, cutting 3 chars leaves `app/vendor.` → `app_vendor_` → `SplitString` yields `[\"app\", \"vendor\", \"\"]` → `back()` is the **empty string**. So the file component is not merely different, it is empty.\n\nThis half is already fixed on `main` (commit `bce66986c7`, [#1965](https://github.com/NativeScript/android/pull/1965)) — `.mjs` is stripped and the last *non-empty* part is taken. **But that fix does not close the gap**: I checked `v9.1.0-rc.0`, where the runtime now yields `vendor` and `Generator.java` still yields `vendor_7c3613`. Defect 1 is untouched on `main`.\n\n---\n\n## Reproduction / evidence\n\nNativeScript 9 app (`@nativescript/core` 9.0.20, `@nativescript/android` 9.0.4), release AAB.\n\nThe SBG emits, and the AAB ships:\n\n```\n$ strings base/dex/*.dex | grep TapAndDoubleTapGestureListenerImpl\nLcom/tns/gen/android/view/GestureDetector_SimpleOnGestureListener_vendor_7c3613_2_1631471_TapAndDoubleTapGestureListenerImpl;\n```\n\n`sbg-bindings.txt` row (file component is `vendor`, line 2, column 1631471):\n\n```\nandroid.view.GestureDetector.SimpleOnGestureListener*vendor*2*1631471*TapAndDoubleTapGestureListenerImpl*onSingleTapUp,onDown,onLongPress,_handleSingleTap,_handleDoubleTap,DoubleTapTimeout***\n```\n\n`md5(\"vendor\") = 7c3613dba5171cb6027c67835dd3b9d4` → `7c3613`, confirming where the suffix comes from.\n\nThe runtime asks for the same line/column with an empty file component, fails, and generates the dex at runtime — here is a user-facing crash from a device where that generation failed:\n\n```\nCalling js method onCreateView failed\nError: java.lang.ClassNotFoundException: Didn't find class\n\"android.view.GestureDetector_SimpleOnGestureListener__2_1631471_TapAndDoubleTapGestureListenerImpl\"\non path: DexPathList[[zip file \"/data/user/0/\u003cpkg>/code_cache/secondary-dexes/android.view.GestureDetector_SimpleOnGestureListener__2_1631471_TapAndDoubleTapGestureListenerImpl.jar\"]]\n at com.tns.DexFactory.resolveClass(DexFactory.java:166)\n at com.tns.ClassResolver.resolveClass(ClassResolver.java:25)\n at com.tns.Runtime.resolveClass(Runtime.java:882)\n …\nSuppressed: java.io.IOException: Failed to open dex files from …/secondary-dexes/….jar\n because: Unable to open '…' : No such file or directory\n```\n\nNote `_SimpleOnGestureListener__2_1631471_` (empty) vs the shipped `_SimpleOnGestureListener_vendor_7c3613_2_1631471_`. Same base class, same line, same column — only the file identifier differs, so the pre-generated class can never be loaded.\n\nIn this app 62 of the 96 generated `com.tns.gen.**` classes carry a file/line/column component, i.e. 62 proxies are eligible to be regenerated at runtime on every fresh install, on every device.\n\n### Confirmed live on 9.0.5 / Android 16\n\nI upgraded the same app to `@nativescript/android` 9.0.5 (`TNS.Runtime: NativeScript Runtime Version 9.0.5, commit 6bc84d4`) and listed the proxy cache after a normal session:\n\n```\n$ adb shell run-as \u003cpkg> ls code_cache/secondary-dexes\nandroid.net.ConnectivityManager_NetworkCallback__69772_58_NetworkCallbackImpl.dex\nandroid.view.GestureDetector_SimpleOnGestureListener__93550_32_TapAndDoubleTapGestureListenerImpl.dex\nandroid.view.View_AccessibilityDelegate__67855_32_TNSAccessibilityDelegateImpl.dex\nandroidx.activity.OnBackPressedCallback__85603_69_.dex\nandroidx.recyclerview.widget.RecyclerView_OnScrollListener__59807_28_ListViewNativeScrollListenerImpl.dex\njava.lang.Object__59398_28_ListViewItemClickListenerImpl.dex\njava.lang.Object__79094_32_MenuItemClickListenerImpl.dex\njava.lang.Object__85639_32_TouchListenerImpl.dex\n…\n```\n\nEvery entry has the empty file component (`NetworkCallback__69772_58_`), and every one of these has a pre-compiled counterpart sitting unused in the APK. Opening two screens and tapping one list item generated twenty of them.\n\n### Quick verification, without an app\n\nFor any NativeScript 9 Android project, after a build:\n\n```bash\n# what the build produced\nls platforms/android/app/src/main/java/com/tns/gen/android/view/\n# GestureDetector_SimpleOnGestureListener_vendor_7c3613_2_1631471_TapAndDoubleTapGestureListenerImpl.java\n\n# what the SBG was told the file was called\ngrep GestureDetector platforms/android/build-tools/sbg-bindings.txt\n# android.view.GestureDetector.SimpleOnGestureListener*vendor*2*1631471*…\n\n# where the suffix comes from\nprintf 'vendor' | md5 # 7c3613dba517…\n```\n\nand then enable `DexFactory`'s logger — every one of those classes logs\n`Pre-generated class not found: …` followed by `generating proxy in place`.\n\n---\n\n## Why this matters beyond startup cost\n\nThe runtime dex path is where the recently reported failures live, and this bug routes 100% of traffic through it:\n\n- [#2019](https://github.com/NativeScript/android/issues/2019) documents unsynchronized state in exactly this code — a truncated jar being persisted **read-only** and reused on later launches, `EACCES` from the check-then-act `jarFile.exists()` / `setReadOnly()` pair, and static scratch buffers in `Dump` that can bake wrong method descriptors into a dex. The issue opens by saying [#2016](https://github.com/NativeScript/android/pull/2016) \"makes runtime proxy dex generation a routine path … instead of a rare one\" — in practice it has been the *only* path since 9.0.0.\n- [#1962](https://github.com/NativeScript/android/issues/1962) / [#1968](https://github.com/NativeScript/android/pull/1968): release builds crashed on the *first* runtime-generated proxy. With working pre-generated bindings that would have been rare; as it stands it is the first gesture on the first screen.\n- [#2016](https://github.com/NativeScript/android/pull/2016) is written on the assumption that pre-compiled classes are the normal case (\"A precompiled class is still the sturdier answer where a build step can provide one\"). That assumption does not currently hold for any app.\n\n---\n\n## Suggested fix\n\nMake the two sides compute the same string, and add a regression test that asserts it.\n\nThe lowest-risk direction is to **revert the SBG to the last-segment rule** (drop `generateUniqueFileIdentifier`) and keep the `main` runtime fix for `.mjs` + last-non-empty part, since that is the shape both sides already agreed on before `#1836`. If the collision concern behind `#1836` is real, the identifier has to be derived from information the runtime also has — the stack frame gives it only the script URL, so any hash must be computed from the normalized script path on both sides, not from the SBG's `dataRow.getFile()`.\n\nEither way it would help to fail loudly rather than silently: `DexFactory.resolveClass` currently swallows the pre-generated lookup miss and logs only when the (disabled by default) logger is on. A one-line warning on the miss would have surfaced this within a day of `9.0.0`.\n\n## Environment\n\n- `@nativescript/android` 9.0.4 and 9.0.5 (verified in source for both; `v9.1.0-rc.0` still mismatched)\n- `@nativescript/core` 9.0.20, `@nativescript/webpack` 5.0.35\n- Android app, `minSdk 21` / `target 36`; reproduced on a signed release build and on a debug build, Android 16 emulator and a user's physical device\n","author":{"url":"https://github.com/gustavotrott","@type":"Person","name":"gustavotrott"},"datePublished":"2026-08-24T11:55:11Z","url":"https://github.com/NativeScript/android/issues/2024"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:1856944c-9564-d26b-6ba7-e48bd3e60107 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A832:928E2:149A53B:1B84925:6B0130F3 |
| html-safe-nonce | d52bb2ac26945cf31b923155d00b6b6accbb2fac5238acddca2505f8a6b4d383 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBODMyOjkyOEUyOjE0OUE1M0I6MUI4NDkyNTo2QjAxMzBGMyIsInZpc2l0b3JfaWQiOiI3Nzc3MTA4NDgxMDg5Mjg2Mzg3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 3dd43c5c9b5e0c613ac7c759017e41175f35f4a5f0e1d5ac5c4130d01af59ca2 |
| hovercard-subject-tag | issue:5234413564 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/NativeScript/android/2024/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7fe37dcf5abe34485fede1dc1086f55e78c7af1ea6b770189e5df17380ca32ad/NativeScript/android/issues/2024 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7fe37dcf5abe34485fede1dc1086f55e78c7af1ea6b770189e5df17380ca32ad/NativeScript/android/issues/2024 |
| og:image:alt | Since 9.0.0, the class name the static binding generator emits and the class name the runtime asks for are different, so DexFactory.resolveClass never finds a pre-generated binding and generates a ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gustavotrott |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/NativeScript/android git https://github.com/NativeScript/android.git |
| octolytics-dimension-user_id | 7392261 |
| octolytics-dimension-user_login | NativeScript |
| octolytics-dimension-repository_id | 29137950 |
| octolytics-dimension-repository_nwo | NativeScript/android |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 29137950 |
| octolytics-dimension-repository_network_root_nwo | NativeScript/android |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width