Skip to content

fix(android): generate bindings in Android context - #5811

Closed
ashcastle wants to merge 3 commits into
wailsapp:masterfrom
ashcastle:fix/android-binding-build-context
Closed

ashcastle wants to merge 3 commits into
wailsapp:masterfrom
ashcastle:fix/android-binding-build-context

Conversation

@ashcastle

@ashcastle ashcastle commented Jul 25, 2026 •

Copy link
Copy Markdown

Description

Android builds passed the android build tag to the common binding generator
without changing its Go target from the host OS. On macOS, package loading
therefore selected both Darwin files and explicitly tagged Android files,
producing 98 analyzer warnings even though the later Android compilation
succeeded.

This change:

  • forwards GOOS and CGO_ENABLED through the common frontend/binding task;
  • generates Android bindings with GOOS=android and CGO_ENABLED=0, so this
    step still does not require the NDK;
  • adds the two Android no-CGO bridge stubs exposed by the correct target
    context;
  • removes the unused duplicate Android binding task; and
  • keeps the checked-in Android/mobile examples in sync with the template.

Fixes #5810

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Windows
  • macOS
  • Linux

Before the fix, the stock v3/examples/mobile project emitted 98 warnings:

GOWORK=off wails3 generate bindings -dry -clean=false -f "-tags android,debug"

With the fixed CLI and Android task context, the same example processed 229
packages with no analyzer warnings:

GOWORK=off GOOS=android CGO_ENABLED=0 \
  wails3 generate bindings -dry -clean=false -f "-tags android,debug"

The complete Android task path also succeeds without binding warnings:

GOWORK=off wails3 task android:build -f

Regression and full test suites:

go test ./internal/commands ./internal/generator ./pkg/application
go test ./...

Desktop binding generation was also checked with the default host context and
completed without warnings.

Test Configuration

Wails CLI: v3.0.0-dev (built from this branch)
Go: go1.26.5
OS: macOS 26.5.2 (arm64, Apple Silicon)
Android SDK: installed
Android NDK: 28.2.13676358
Java: OpenJDK 17.0.19

Checklist:

  • (v2 only) I have updated website/src/pages/changelog.mdx with details of this PR (not applicable; this is a v3 change and v3 changelog entries are added automatically)
  • My code follows the general coding style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (not applicable; this fixes build task behavior without changing the user-facing API)
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Summary by CodeRabbit

  • Bug Fixes
    • Improved Android and mobile build workflows by consistently propagating platform (GOOS) and CGO_ENABLED settings into frontend builds and binding generation.
    • Binding generation now works correctly for Android builds without CGO.
    • Added safe JNI bridge fallbacks for Android when CGO is disabled.
  • Tests
    • Added/expanded automated checks to verify generated build Taskfiles correctly include GOOS/CGO_ENABLED forwarding and that Android no-CGO package loading succeeds.

@coderabbitai

coderabbitai Bot commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 47d13391-4ae1-43dd-97b2-7d494cdd8435

📥 Commits

Reviewing files that changed from the base of the PR and between b1fdb6f and c4c10b4.

📒 Files selected for processing (1)
  • v3/internal/commands/android_taskfile_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • v3/internal/commands/android_taskfile_test.go

Walkthrough

Android binding generation now propagates GOOS and CGO_ENABLED through shared Taskfile plumbing, uses Android-specific values in Android builds, removes duplicate binding tasks, and adds no-CGO bridge stubs with validation tests.

Changes

Android binding context

Layer / File(s) Summary
Binding context plumbing
v3/internal/commands/build_assets/Taskfile.tmpl.yml, v3/examples/*/build/Taskfile.yml
Binding tasks forward GOOS and CGO_ENABLED through variables and command environments, with host-based defaults.
Android task wiring
v3/internal/commands/build_assets/android/Taskfile.yml, v3/examples/*/build/android/Taskfile.yml
Android frontend builds set GOOS: android and CGO_ENABLED: 0; duplicate Android binding tasks are removed.
No-CGO Android support and validation
v3/pkg/application/application_android_nocgo.go, v3/internal/generator/load_android_test.go, v3/internal/commands/android_taskfile_test.go
No-CGO bridge stubs are added, with tests covering Android package loading and Taskfile context forwarding.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant AndroidBuild
  participant CommonFrontend
  participant GenerateBindings
  participant GoLoader
  AndroidBuild->>CommonFrontend: set GOOS=android and CGO_ENABLED=0
  CommonFrontend->>GenerateBindings: forward binding context
  GenerateBindings->>GoLoader: load Android packages without CGO
Loading

Possibly related PRs

  • wailsapp/wails#4023: Both changes forward build-context variables through the binding-generation Taskfile pipeline.
  • wailsapp/wails#5248: Both changes modify the binding-generation Taskfile label in the shared template.

Suggested labels: templates

Suggested reviewers: leaanthony

Poem

I’m a rabbit with bindings tucked neat,
Android hops on a target-state beat.
No-CGO stubs stand calm and bright,
While Taskfiles guide the build just right.
Fewer warnings in the moonlit night!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and matches the main Android binding-context fix in the PR.
Description check ✅ Passed The description includes the issue, motivation, testing, environment, and the required template sections.
Linked Issues check ✅ Passed The PR implements the Android binding-context fix, adds the no-CGO stubs, and keeps desktop binding generation unchanged as required by #5810.
Out of Scope Changes check ✅ Passed The changes stay focused on Android binding generation and closely related taskfile, test, and example updates.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain modules listed in go.work or their selected dependencies"


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 3

🧹 Nitpick comments (1)
v3/internal/commands/android_taskfile_test.go (1)

55-63: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover the removed task and rendered environment contract.

This test checks only the internal Taskfile’s forwarding strings. It would pass while the checked-in Android example still references the deleted generate:android:bindings task, and it does not catch CGO_ENABLED rendering as empty. Add assertions for the example Taskfiles and render/execute the relevant task variables.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@v3/internal/commands/android_taskfile_test.go` around lines 55 - 63, Extend
TestAndroidTaskfileBuildUsesAndroidBindingContext to inspect the checked-in
Android example Taskfiles and assert they no longer reference the removed
generate:android:bindings task. Render or execute the relevant task variables
and assert the resulting environment includes a non-empty CGO_ENABLED value,
while preserving the existing forwarding and Android binding context assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@v3/examples/android/build/android/Taskfile.yml`:
- Around line 45-46: Remove the obsolete generate:android:bindings dependency
from both Android build task definitions:
v3/examples/android/build/android/Taskfile.yml lines 45-46 and
v3/examples/android/build/Taskfile.yml lines 39-42. Ensure each task retains
common:build:frontend as the only binding path, or references another existing
task where required.

In `@v3/internal/commands/build_assets/android/Taskfile.yml`:
- Around line 49-50: Quote the CGO_ENABLED value as the string "0" in the shared
Android Taskfile values at
v3/internal/commands/build_assets/android/Taskfile.yml:49-50,
v3/examples/android/build/android/Taskfile.yml:45-46, and
v3/examples/mobile/build/android/Taskfile.yml:45-46. Preserve the existing GOOS:
android setting so the {{.CGO_ENABLED | default "0"}} template path receives an
explicit zero and selects the no-CGO behavior.

In `@v3/internal/commands/build_assets/Taskfile.tmpl.yml`:
- Around line 95-98: Update the labels/checksums for build:frontend and
generate:bindings to include GOOS and CGO_ENABLED as platform context, ensuring
changes to either variable invalidate the shared dependencies. Apply this in
v3/internal/commands/build_assets/Taskfile.tmpl.yml,
v3/examples/android/build/Taskfile.yml lines 39-42, and
v3/examples/mobile/build/Taskfile.yml lines 39-42; preserve the existing
dependency calls and variable references.

---

Nitpick comments:
In `@v3/internal/commands/android_taskfile_test.go`:
- Around line 55-63: Extend TestAndroidTaskfileBuildUsesAndroidBindingContext to
inspect the checked-in Android example Taskfiles and assert they no longer
reference the removed generate:android:bindings task. Render or execute the
relevant task variables and assert the resulting environment includes a
non-empty CGO_ENABLED value, while preserving the existing forwarding and
Android binding context assertions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: fe78a5ae-1578-4b60-a72f-dc2146e61c20

📥 Commits

Reviewing files that changed from the base of the PR and between e63d2bd and ae89f99.

📒 Files selected for processing (9)
  • v3/examples/android/build/Taskfile.yml
  • v3/examples/android/build/android/Taskfile.yml
  • v3/examples/mobile/build/Taskfile.yml
  • v3/examples/mobile/build/android/Taskfile.yml
  • v3/internal/commands/android_taskfile_test.go
  • v3/internal/commands/build_assets/Taskfile.tmpl.yml
  • v3/internal/commands/build_assets/android/Taskfile.yml
  • v3/internal/generator/load_android_test.go
  • v3/pkg/application/application_android_nocgo.go

Comment thread v3/examples/android/build/android/Taskfile.yml Outdated
Comment thread v3/internal/commands/build_assets/android/Taskfile.yml Outdated
Comment thread v3/internal/commands/build_assets/Taskfile.tmpl.yml

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@v3/internal/commands/android_taskfile_test.go`:
- Around line 97-122: The TestAndroidExamplesUseCommonBindingContext test
currently checks frontend task settings only by substring presence, so Android
GOOS configuration can be missing or attached to the wrong task. Parse each
example’s build task and inspect its common:build:frontend dependency, asserting
that both GOOS is "android" and CGO_ENABLED is "0"; retain the existing checks
for the root build task variables.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 6c6e09c6-75f1-4214-b18f-7ea23fc934ef

📥 Commits

Reviewing files that changed from the base of the PR and between ae89f99 and b1fdb6f.

📒 Files selected for processing (7)
  • v3/examples/android/build/Taskfile.yml
  • v3/examples/android/build/android/Taskfile.yml
  • v3/examples/mobile/build/Taskfile.yml
  • v3/examples/mobile/build/android/Taskfile.yml
  • v3/internal/commands/android_taskfile_test.go
  • v3/internal/commands/build_assets/Taskfile.tmpl.yml
  • v3/internal/commands/build_assets/android/Taskfile.yml
🚧 Files skipped from review as they are similar to previous changes (4)
  • v3/internal/commands/build_assets/Taskfile.tmpl.yml
  • v3/internal/commands/build_assets/android/Taskfile.yml
  • v3/examples/mobile/build/android/Taskfile.yml
  • v3/examples/android/build/android/Taskfile.yml

Comment thread v3/internal/commands/android_taskfile_test.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

android Android platform bindings cli mobile Mobile platform work v3

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Android build generates bindings with mixed host and Android build contexts

3 participants