Skip to content

build(ndk): strip unnamed MethodParameters for older R8 - #2266

Merged
bitsandfoxes merged 2 commits into
masterfrom
fix/ndk-javac-parameters
Oct 29, 2026
Merged

bitsandfoxes merged 2 commits into
masterfrom
fix/ndk-javac-parameters

Conversation

@bitsandfoxes

@bitsandfoxes bitsandfoxes commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Strip MethodParameters entries without a name from the ndk module's classes after JavaCompile, the same way sentry-java does in getsentry/sentry-java#6356.

Since JDK 21, javac writes MethodParameters entries without a name for mandated and synthetic parameters (JDK-8292275), even with --release 8 / -source 8 -target 8. Here that's the enum io.sentry.ndk.NdkHandlerStrategy (valueOf and its constructor). D8/R8 older than 8.1 (AGP 8.0 and older) crash on those entries while minifying:

ERROR: .../jetified-sentry-native-ndk-release-runtime.jar: R8: java.lang.NullPointerException
Compilation failed to complete, origin: ...:io/sentry/ndk/NdkHandlerStrategy.class

The new StripMethodParameters action in ndk/lib/build.gradle.kts drops the attribute only from methods that have an unnamed entry, using the ASM that AGP already brings. Classes without such entries aren't rewritten. -parameters would also work, but sentry-java opted out of it because of the added size and possible binary incompatibilities, so this mirrors their fix instead.

Our CI and releases build with JDK 17, so the published sentry-native-ndk doesn't have the problem today, and the action is a no-op there. It shows up when the module is built from source with JDK 21+: sentry-unity does that since sentry-java 8.61.1 requires JDK 21 (getsentry/sentry-java#6242), and Unity 2021.3 ships AGP 7.4.2 (R8 4.0.48), so its Android player builds fail.

Verified:

  • JDK 21: ./gradlew :sentry-native-ndk:assembleRelease :sentry-native-ndk:testDebugUnitTest spotlessCheck passes. The AAR's classes go from 4 unnamed entries to 0. Compared with javap -v -p -c against an unpatched build, the only difference is the two MethodParameters blocks of NdkHandlerStrategy.
  • JDK 17: same build and tests pass, and the output has no unnamed entries.
  • R8 4.0.48 over the module (and all Android artifacts sentry-unity ships): fails unpatched, dexes patched.
  • A Unity 2021.3.45f2 Android player build (minified) with the patched AAR succeeds; unpatched fails as above.

#skip-changelog: no change to the published artifact, which is built with JDK 17.

🤖 Generated with Claude Code

@bitsandfoxes
bitsandfoxes requested a review from markushi October 28, 2026 14:27
@bitsandfoxes
bitsandfoxes marked this pull request as ready for review October 28, 2026 14:27
@codecov

codecov Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.67%. Comparing base (b99f526) to head (bca5fe1).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2266      +/-   ##
==========================================
- Coverage   75.71%   75.67%   -0.04%     
==========================================
  Files         103      103              
  Lines       28316    28316              
  Branches     5208     5208              
==========================================
- Hits        21439    21428      -11     
- Misses       5529     5549      +20     
+ Partials     1348     1339       -9     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bitsandfoxes bitsandfoxes changed the title build(ndk): compile with -parameters for older R8 build(ndk): strip unnamed MethodParameters for older R8 Oct 28, 2026
@bitsandfoxes
bitsandfoxes merged commit 83ee8d4 into master Oct 29, 2026
70 of 71 checks passed
@bitsandfoxes
bitsandfoxes deleted the fix/ndk-javac-parameters branch October 29, 2026 09:24
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.

2 participants