Skip to content

Android: preserve fbjni internals in minified apps - #22174

Open
cdeil wants to merge 2 commits into
pytorch:mainfrom
cdeil:fix-fbjni-r8-consumer-rules
Open

Android: preserve fbjni internals in minified apps#22174
cdeil wants to merge 2 commits into
pytorch:mainfrom
cdeil:fix-fbjni-r8-consumer-rules

Conversation

@cdeil

@cdeil cdeil commented Aug 26, 2026

Copy link
Copy Markdown

Summary

  • preserve fbjni classes and members according to fbjni's own @DoNotStrip and @DoNotStripAny annotations
  • scope the rules to com.facebook.jni.** so they do not affect unrelated annotated dependencies
  • suppress the warning for fbjni's compile-time-only javax.annotation.Nullable reference

This is a follow-up to #19169. That PR protects ExecuTorch's annotated classes, but a minified consumer can still remove fbjni internals that ExecuTorch's native bindings need.

Motivation

In a standalone release app with R8 enabled, both the 1.4.0 Maven AAR and the 1.4.1 release AAR abort in Module.initHybrid() with SIGABRT and abort message ptr. The R8 mapping contains com.facebook.jni.HybridData, but not its annotated HybridData$Destructor class.

Keeping all org.pytorch.executorch.** classes is not sufficient. Applying the scoped fbjni annotation rules preserves HybridData$Destructor and lets the same model execute successfully.

Test plan

Standalone Android consumer using AGP 9.1.1, Gradle 9.5, minifyEnabled = true, and a one-element add-one PTE model on an arm64 Android tablet:

AAR Stock consumer rules With this patch
1.4.0 aborts in Module.initHybrid() PASS: output=2.0
1.4.1 aborts in Module.initHybrid() PASS: output=2.0

The unminified build passes as a control. The fixed R8 mapping retains com.facebook.jni.HybridData$Destructor; the stock mapping does not.

The current Android project builds the AAR but does not contain a minified standalone consumer target, so this red/green test was run in a separate minimal consumer app.

  • git diff --check origin/main...HEAD

Copilot AI lite review requested due to automatic review settings August 26, 2026 12:21
@pytorch-bot

pytorch-bot Bot commented Aug 26, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22174

Note: Links to docs will display an error until the docs builds have been completed.

⚠️ 15 Awaiting Approval

As of commit b04b5b2 with merge base 6ce2715 (image):

AWAITING APPROVAL - The following workflows need approval before CI can run:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 26, 2026
@linux-foundation-easycla

linux-foundation-easycla Bot commented Aug 26, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: cdeil / name: Christoph Deil (3de5770)

@cdeil

cdeil commented Aug 26, 2026

Copy link
Copy Markdown
Author

@pytorchbot label "release notes: build"

@pytorch-bot pytorch-bot Bot added the release notes: build Changes related to build, including dependency upgrades, build flags, optimizations, etc. label Aug 26, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the ExecuTorch Android AAR’s consumer R8/ProGuard configuration to prevent minified consumer apps from stripping fbjni internals that ExecuTorch’s JNI bindings rely on at runtime.

Changes:

  • Add scoped keep rules for com.facebook.jni.** based on fbjni’s @DoNotStrip / @DoNotStripAny annotations.
  • Suppress R8 warnings for fbjni’s compile-time-only javax.annotation.Nullable reference.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread extension/android/executorch_android/consumer-proguard-rules.pro Outdated
Copilot AI review requested due to automatic review settings August 26, 2026 12:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. release notes: build Changes related to build, including dependency upgrades, build flags, optimizations, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants