Skip to content

[Android] Fix AAB not including libapp.so #187699

Draft
mboetger wants to merge 5 commits into
flutter:masterfrom
mboetger:triage-issue-186810
Draft

[Android] Fix AAB not including libapp.so #187699
mboetger wants to merge 5 commits into
flutter:masterfrom
mboetger:triage-issue-186810

Conversation

@mboetger

@mboetger mboetger commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

The Bug

In FlutterPlugin.kt , we register the directory containing Flutter's intermediate JNI libraries (like libapp.so ) to the Android source set so Gradle knows to package them:

val jniLibsDir: Provider<Directory> = ...                                                                                                                                                                
sourceSet.jniLibs.srcDir(jniLibsDir.get().asFile) // <-- The Bug                                                                                                                                         
  1. Eager Evaluation: Calling .get().asFile on jniLibsDir (which is a lazy Gradle Provider ) forces Gradle to resolve the path immediately during the Configuration Phase. At this point, it resolves
    to the default path (e.g., build/intermediates/flutter/... ).
  2. Delayed Customization: If the project (or a plugin) customizes the build directory later in the configuration (e.g., layout.buildDirectory.set("custom_build_dir") ), Gradle updates the layout.
    buildDirectory property.
  3. The Mismatch:
    • Writing: The Flutter task that copies libapp.so uses the lazy jniLibsDir provider, so it correctly resolves the path at Execution Phase and writes the library to the custom directory (
    custom_build_dir/intermediates/... ).
    • Reading: The Android packaging task reads from the source set we registered earlier. Because we passed a static File resolved eagerly, it looks in the default directory ( build/intermediates/...
    ), which is empty.
    • As a result, libapp.so is silently left out of the final APK/AAB.

──────

The Fix

The fix changes the registration to pass the lazy Provider directly:

-            sourceSet.jniLibs.srcDir(jniLibsDir.get().asFile)                                                                                                                                           
+            sourceSet.jniLibs.srcDir(jniLibsDir)                                                                                                                                                        
  1. Lazy Evaluation: Gradle's srcDir() API natively accepts Provider objects. By passing jniLibsDir directly without calling .get() , we keep it lazy.
  2. Deferred Resolution: Gradle now defers resolving the actual path until the Execution Phase (when it actually needs to read the files).
  3. Alignment: Both the task that writes libapp.so and the packaging task that reads it now resolve the jniLibsDir provider at the same time, ensuring they both point to the customized
    custom_build_dir path.

Fixes: #186810

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • I followed the [breaking change policy] and added [Data Driven Fixes] where supported.
  • All existing and new tests are passing.

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Jun 8, 2026
@github-actions github-actions Bot added platform-android Android applications specifically tool Affects the "flutter" command-line tool. See also t: labels. team-android Owned by Android platform team labels Jun 8, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 8, 2026
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Jun 8, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 8, 2026
@mboetger mboetger added the CICD Run CI/CD label Jun 8, 2026

@gmackall gmackall left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

the idea of this change lgtm, if we can find a syntax that works here (not resolving immediately but letting it act as a provider as it should)

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

Labels

CICD Run CI/CD l:backlog LLM created PR addressing a backlog issue. platform-android Android applications specifically team-android Owned by Android platform team tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flutter 3.44.0: appbundle release fails with "Release app bundle failed to strip debug symbols from native libraries"

2 participants