René's URL Explorer Experiment


Title: DexFactory parent class loader injection (#1951) crashes release builds with "Attempt to register dex file ... with multiple class loaders" · Issue #1962 · NativeScript/android · GitHub

Open Graph Title: DexFactory parent class loader injection (#1951) crashes release builds with "Attempt to register dex file ... with multiple class loaders" · Issue #1962 · NativeScript/android

X Title: DexFactory parent class loader injection (#1951) crashes release builds with "Attempt to register dex file ... with multiple class loaders" · Issue #1962 · NativeScript/android

Description: Summary On release (non debuggable) builds, the first time the runtime generates a proxy class on the main thread, the app crashes with: java.lang.InternalError: Attempt to register dex file /data/user/0//code_cache/secondary-dexes/...

Open Graph Description: Summary On release (non debuggable) builds, the first time the runtime generates a proxy class on the main thread, the app crashes with: java.lang.InternalError: Attempt to register dex file /data/...

X Description: Summary On release (non debuggable) builds, the first time the runtime generates a proxy class on the main thread, the app crashes with: java.lang.InternalError: Attempt to register dex file /data/...

Opengraph URL: https://github.com/NativeScript/android/issues/1962

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"DexFactory parent class loader injection (#1951) crashes release builds with \"Attempt to register dex file ... with multiple class loaders\"","articleBody":"## Summary\n\nOn release (non debuggable) builds, the first time the runtime generates a proxy class on the main thread, the app crashes with:\n\n```\njava.lang.InternalError: Attempt to register dex file\n  /data/user/0/\u003capp\u003e/code_cache/secondary-dexes/\u003cproxy\u003e.jar with multiple class loaders\n```\n\nThis was introduced by [#1951](https://github.com/NativeScript/android/pull/1951) (commit [`c9d41e62`](https://github.com/NativeScript/android/commit/c9d41e620b3413a67c1bd766e3f68e534a082814), currently on `main`). Debug builds are not affected, so it passes normal development and only appears once an app ships a release build. The runtime reports version 9.0.4 (the commit sits a few commits past the 9.0.4 tag).\n\n## What triggers it\n\nAny JavaScript that implements or extends a native type whose proxy is produced at runtime, on the main thread (worker id 0). For example:\n\n```js\n// Main thread. JS implements a native interface, so the runtime must\n// generate a Java proxy class for it and load it through DexFactory.\nconst runnable = new java.lang.Runnable({\n  run() {\n    console.log(\"invoked from Java\");\n  }\n});\n\nnew android.os.Handler(android.os.Looper.getMainLooper()).post(runnable);\n```\n\nStatically bound proxies are not affected, because `resolveClass` finds the pre-generated class and returns before reaching the new code path. If the static binding generator covers the example above, force the runtime path (for example by building the implementation dynamically) so that `DexFactory.resolveClass` actually performs generation. You can confirm the path is taken by logging inside `injectDexIntoClassLoader`.\n\n## Background: the class loader hierarchy\n\nAndroid resolves classes through a chain of class loaders. Each one delegates to its parent before trying itself:\n\n```\nBootClassLoader     framework classes (android.*, java.*)\n   ^ parent\nPathClassLoader     the app's own classes, from the APK dex files\n   ^ parent\nDexClassLoader      a dex or jar loaded on demand from an arbitrary path\n```\n\n`PathClassLoader` is the app's primary loader, created by the system when the process starts. `DexClassLoader` is created by code at runtime to load a dex or jar from a chosen path. NativeScript uses it to load proxy classes it generates at runtime, with the `PathClassLoader` as the parent so the proxy can resolve the app and framework types it references.\n\nTwo runtime rules are relevant:\n\n1. A class's identity is the pair (name, defining class loader). The same bytecode loaded by two loaders produces two distinct types.\n2. A given dex file may be registered with only one class loader. ART enforces this and throws `InternalError: Attempt to register dex file ... with multiple class loaders` when a dex is claimed by a second loader.\n\n## Root cause\n\nBefore #1951, `resolveClass` loaded each runtime generated proxy through [its own `DexClassLoader`](https://github.com/NativeScript/android/blob/c9d41e620b3413a67c1bd766e3f68e534a082814/test-app/runtime/src/main/java/com/tns/DexFactory.java#L176): one dex, one owner.\n\n#1951 added `injectIntoParentClassLoader`, enabled for the main thread runtime in [`Runtime.init`](https://github.com/NativeScript/android/blob/c9d41e620b3413a67c1bd766e3f68e534a082814/test-app/runtime/src/main/java/com/tns/Runtime.java#L768-L769). When enabled, [`resolveClass`](https://github.com/NativeScript/android/blob/c9d41e620b3413a67c1bd766e3f68e534a082814/test-app/runtime/src/main/java/com/tns/DexFactory.java#L172-L178) calls [`injectDexIntoClassLoader`](https://github.com/NativeScript/android/blob/c9d41e620b3413a67c1bd766e3f68e534a082814/test-app/runtime/src/main/java/com/tns/DexFactory.java#L393-L427), which:\n\n1. creates a [temporary `DexClassLoader`](https://github.com/NativeScript/android/blob/c9d41e620b3413a67c1bd766e3f68e534a082814/test-app/runtime/src/main/java/com/tns/DexFactory.java#L396) over the proxy jar, then\n2. [splices the dex element](https://github.com/NativeScript/android/blob/c9d41e620b3413a67c1bd766e3f68e534a082814/test-app/runtime/src/main/java/com/tns/DexFactory.java#L420) into the app's `PathClassLoader` and [loads the proxy through the `PathClassLoader`](https://github.com/NativeScript/android/blob/c9d41e620b3413a67c1bd766e3f68e534a082814/test-app/runtime/src/main/java/com/tns/DexFactory.java#L174).\n\nBoth the temporary `DexClassLoader` and the app `PathClassLoader` now reference the same `DexFile` object (through the spliced element). Registering one `DexFile` against a second class loader is what ART rejects: the check is keyed on `DexFile` identity and is unconditional. `ClassLinker::RegisterDexFile` throws `ThrowDexFileAlreadyRegisteredError` with no `android:debuggable` guard. Whether a second registration actually happens depends on the build type, which is why only release crashes (see below).\n\n## Why debug builds are not affected\n\nThe single-owner rule is enforced identically in both modes; the throw is not gated on `android:debuggable`. Both loaders reference one `DexFile` (the spliced element), so the only build-dependent question is whether the temporary loader also registers it:\n\n- **Release:** the temporary loader ends up registering the proxy `DexFile` (a non-debuggable runtime verifies, and may AOT-compile, the dex in-process). The later load through the app `PathClassLoader` then registers the same `DexFile` against a second loader, and ART throws.\n- **Debug:** a debuggable runtime is interpret-only and does not use AOT code ([`class_linker.cc`](https://android.googlesource.com/platform/art/+/refs/heads/main/runtime/class_linker.cc): \"For debuggable runtimes we don't use AOT code\"), and the temporary loader never claims the dex, so it is registered exactly once through the app loader and nothing throws.\n\nThe exact ART step that registers the dex against the temporary loader in release is not instrumented here; what is certain is that two loaders share one `DexFile` and that `ClassLinker::RegisterDexFile` is identity-keyed and unconditional, so the second registration throws. The release-only crash is consistent with the interpret-only vs verify/AOT split. (The `odexDir` passed as the `DexClassLoader` `optimizedDirectory` has [no effect since API 26](https://developer.android.com/reference/dalvik/system/DexClassLoader), so it is not the relevant factor.)\n\n## Expected behavior\n\nRuntime generated proxies load without crashing in release, as they did before #1951.\n\n## Suggested direction\n\nThe goal of #1951 is to make generated proxies discoverable through the app's `PathClassLoader` (for example for `Class.forName`). The current implementation opens the dex with a separate loader first, which is what creates the second owner. Two options:\n\n1. Register the dex with the `PathClassLoader` as its only owner, for example by building the dex element through the `PathClassLoader`'s own `DexPathList` instead of through a temporary `DexClassLoader`. The dex is then registered exactly once.\n2. Make the injection opt in and keep the previous isolated `DexClassLoader` path as the default, so apps that do not need `Class.forName` discovery are unaffected.\n\n## Environment\n\n- NativeScript Android runtime: `main` at commit `c9d41e62` (reports version 9.0.4)\n- Introduced by: #1951\n- Build type: release (`android:debuggable=false`). Debug builds do not reproduce.\n","author":{"url":"https://github.com/adrian-niculescu","@type":"Person","name":"adrian-niculescu"},"datePublished":"2026-06-05T10:16:00.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/1962/android/issues/1962"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:45a6af6a-285a-1c85-b70c-74d1d9d8f1c6
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id93F0:119F46:122A407:1A1B5BC:6A6340B8
html-safe-noncee4614a0f54cc36f77b69180b4145406aa78500e5e37b99c860d61f58aa69beae
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5M0YwOjExOUY0NjoxMjJBNDA3OjFBMUI1QkM6NkE2MzQwQjgiLCJ2aXNpdG9yX2lkIjoiNjQxNjUyMDY4MjAzMDcxMDk2OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac37e8ed9127655346b1a2dfa72e0110bb38fb97d055e0392e8df51f884f13d403
hovercard-subject-tagissue:4596124463
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/NativeScript/android/1962/issue_layout
twitter:imagehttps://opengraph.githubassets.com/cbab86a9d0292957ad5f52b29316f770ab901319503eb3586ceca56b92dcbe63/NativeScript/android/issues/1962
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/cbab86a9d0292957ad5f52b29316f770ab901319503eb3586ceca56b92dcbe63/NativeScript/android/issues/1962
og:image:altSummary On release (non debuggable) builds, the first time the runtime generates a proxy class on the main thread, the app crashes with: java.lang.InternalError: Attempt to register dex file /data/...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameadrian-niculescu
hostnamegithub.com
expected-hostnamegithub.com
None59e55daad7174ca59d63c6974d58276ccb5477442e550bebb3c035e1bef11c94
turbo-cache-controlno-preview
go-importgithub.com/NativeScript/android git https://github.com/NativeScript/android.git
octolytics-dimension-user_id7392261
octolytics-dimension-user_loginNativeScript
octolytics-dimension-repository_id29137950
octolytics-dimension-repository_nwoNativeScript/android
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id29137950
octolytics-dimension-repository_network_root_nwoNativeScript/android
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release990295d92a4cc7b63fbbd83a046217cd7d77d49c
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/NativeScript/android/issues/1962#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FNativeScript%2Fandroid%2Fissues%2F1962
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
Code QualityEnforce quality at mergehttps://github.com/features/code-quality
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FNativeScript%2Fandroid%2Fissues%2F1962
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=NativeScript%2Fandroid
Reloadhttps://github.com/NativeScript/android/issues/1962
Reloadhttps://github.com/NativeScript/android/issues/1962
Reloadhttps://github.com/NativeScript/android/issues/1962
Please reload this pagehttps://github.com/NativeScript/android/issues/1962
NativeScript https://github.com/NativeScript
androidhttps://github.com/NativeScript/android
Please reload this pagehttps://github.com/NativeScript/android/issues/1962
Notifications https://github.com/login?return_to=%2FNativeScript%2Fandroid
Fork 144 https://github.com/login?return_to=%2FNativeScript%2Fandroid
Star 562 https://github.com/login?return_to=%2FNativeScript%2Fandroid
Code https://github.com/NativeScript/android
Issues 98 https://github.com/NativeScript/android/issues
Pull requests 13 https://github.com/NativeScript/android/pulls
Actions https://github.com/NativeScript/android/actions
Projects https://github.com/NativeScript/android/projects
Wiki https://github.com/NativeScript/android/wiki
Security and quality 0 https://github.com/NativeScript/android/security
Insights https://github.com/NativeScript/android/pulse
Code https://github.com/NativeScript/android
Issues https://github.com/NativeScript/android/issues
Pull requests https://github.com/NativeScript/android/pulls
Actions https://github.com/NativeScript/android/actions
Projects https://github.com/NativeScript/android/projects
Wiki https://github.com/NativeScript/android/wiki
Security and quality https://github.com/NativeScript/android/security
Insights https://github.com/NativeScript/android/pulse
#1968https://github.com/NativeScript/android/pull/1968
DexFactory parent class loader injection (#1951) crashes release builds with "Attempt to register dex file ... with multiple class loaders"https://github.com/NativeScript/android/issues/1962#top
#1968https://github.com/NativeScript/android/pull/1968
https://github.com/NathanWalker
https://github.com/adrian-niculescu
adrian-niculescuhttps://github.com/adrian-niculescu
on Jun 5, 2026https://github.com/NativeScript/android/issues/1962#issue-4596124463
#1951https://github.com/NativeScript/android/pull/1951
c9d41e62https://github.com/NativeScript/android/commit/c9d41e620b3413a67c1bd766e3f68e534a082814
#1951https://github.com/NativeScript/android/pull/1951
its own DexClassLoaderhttps://github.com/NativeScript/android/blob/c9d41e620b3413a67c1bd766e3f68e534a082814/test-app/runtime/src/main/java/com/tns/DexFactory.java#L176
#1951https://github.com/NativeScript/android/pull/1951
Runtime.inithttps://github.com/NativeScript/android/blob/c9d41e620b3413a67c1bd766e3f68e534a082814/test-app/runtime/src/main/java/com/tns/Runtime.java#L768-L769
resolveClasshttps://github.com/NativeScript/android/blob/c9d41e620b3413a67c1bd766e3f68e534a082814/test-app/runtime/src/main/java/com/tns/DexFactory.java#L172-L178
injectDexIntoClassLoaderhttps://github.com/NativeScript/android/blob/c9d41e620b3413a67c1bd766e3f68e534a082814/test-app/runtime/src/main/java/com/tns/DexFactory.java#L393-L427
temporary DexClassLoaderhttps://github.com/NativeScript/android/blob/c9d41e620b3413a67c1bd766e3f68e534a082814/test-app/runtime/src/main/java/com/tns/DexFactory.java#L396
splices the dex elementhttps://github.com/NativeScript/android/blob/c9d41e620b3413a67c1bd766e3f68e534a082814/test-app/runtime/src/main/java/com/tns/DexFactory.java#L420
loads the proxy through the PathClassLoaderhttps://github.com/NativeScript/android/blob/c9d41e620b3413a67c1bd766e3f68e534a082814/test-app/runtime/src/main/java/com/tns/DexFactory.java#L174
class_linker.cchttps://android.googlesource.com/platform/art/+/refs/heads/main/runtime/class_linker.cc
no effect since API 26https://developer.android.com/reference/dalvik/system/DexClassLoader
#1951https://github.com/NativeScript/android/pull/1951
#1951https://github.com/NativeScript/android/pull/1951
fix(DexFactory): add support for injecting DEX into parent class loader #1951https://github.com/NativeScript/android/pull/1951
NathanWalkerhttps://github.com/NathanWalker
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.