Skip to content

Fix non-compiling Java snippet in Android Fabric Native Component guide - #5211

Draft
dazakdev wants to merge 1 commit into
react:mainfrom
dazakdev:fix-android-fabric-webview-java
Draft

Fix non-compiling Java snippet in Android Fabric Native Component guide#5211
dazakdev wants to merge 1 commit into
react:mainfrom
dazakdev:fix-android-fabric-webview-java

Conversation

@dazakdev

@dazakdev dazakdev commented Aug 14, 2026

Copy link
Copy Markdown

1. The Java snippet does not compile

error: no suitable constructor found for LayoutParams(int,int)
    this.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
      constructor android.widget.AbsoluteLayout.LayoutParams.LayoutParams(Context,AttributeSet) is not applicable
      constructor android.widget.AbsoluteLayout.LayoutParams.LayoutParams(ViewGroup.LayoutParams) is not applicable
      constructor android.widget.AbsoluteLayout.LayoutParams.LayoutParams(int,int,int,int) is not applicable
error: cannot find symbol
    ReactContext reactContext = (ReactContext) context;
      symbol: variable context
error: cannot find symbol
    EventDispatcher eventDispatcher = UIManagerHelper.getEventDispatcherForReactTag(reactContext, getId());
      symbol: class EventDispatcher
  • WebView extends AbsoluteLayout, so the simple name LayoutParams resolves to AbsoluteLayout.LayoutParams, which has no (int, int) constructor → qualified as ViewGroup.LayoutParams + import.
  • No context variable is in scope → getContext().
  • EventDispatcher is used as a declared type but never imported. Missing from every version of this page.

Same failure on compileSdk 35, 36 and 37 — name/overload resolution, independent of AGP and React Native version. Present since #4288. The Kotlin tab is unaffected: Kotlin resolves LayoutParams(...) to ViewGroup.LayoutParams(int, int) and infers the EventDispatcher type.

2. JavaScript is enabled on iOS, disabled on Android

The iOS page uses _webView = [WKWebView new];WKWebpagePreferences.allowsContentJavaScript defaults to true. The Android WebView defaults to false and the guide never sets it, so the same component runs web content differently per platform. Not fatal for the tutorial's own URL, which renders server-side, but it silently breaks JS-dependent pages.

Added the call to both language tabs and a paragraph naming the asymmetry.

Test plan

Both snippets were copied out of the updated page into an Android library module of a React Native 0.86 app.

  • Java: compileDebugJavaWithJavac reports the three errors above before the change, BUILD SUCCESSFUL after.
  • Kotlin: compileDebugKotlin succeeds before and after — only the JavaScript line differs.
  • JavaScript, on an emulator, with sourceURL set to data:text/html,<body><h1>no-js</h1><script>document.body.textContent='js-ran'</script>: the component as documented today renders no-js, with the added line it renders js-ran.

The same three Java errors are in website/versioned_docs/version-0.77version-0.87. README says not to edit the generated versioned docs, so this PR leaves them alone; #4673 backported an equivalent fix as a separate PR, happy to do the same here.

@meta-cla

meta-cla Bot commented Aug 14, 2026

Copy link
Copy Markdown

Hi @dazakdev!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@dazakdev
dazakdev force-pushed the fix-android-fabric-webview-java branch from 5184acf to 68c0114 Compare August 14, 2026 13:21
The ReactWebView.java snippet fails to compile as written: LayoutParams
resolves to AbsoluteLayout.LayoutParams which has no (int, int)
constructor, there is no context variable in scope, and EventDispatcher
is never imported.

Also enable JavaScript, which the Android WebView disables by default
while the WKWebView used on iOS enables it, so that the component
behaves the same on both platforms.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@dazakdev
dazakdev force-pushed the fix-android-fabric-webview-java branch from 68c0114 to e517fd9 Compare August 14, 2026 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant