Skip to content

fix(builder): properly resolve user-defines for android_home on Windows - #38

Merged
rainyl merged 4 commits into
mainfrom
fix-issue-37
Jul 21, 2026
Merged

fix(builder): properly resolve user-defines for android_home on Windows#38
rainyl merged 4 commits into
mainfrom
fix-issue-37

Conversation

@rainyl

@rainyl rainyl commented Jul 20, 2026

Copy link
Copy Markdown
Owner

fixes: #37

rainyl added 4 commits July 20, 2026 22:06
…ws (#37)

Two related bugs conspired to make android_home silently ignored on
Windows when configured via pubspec.yaml user_defines:

1. package:glob treats \ as an escape character, not a path
   separator. Windows paths from Platform.environment['ANDROID_HOME'],
   env files, or Directory.absolute.path were interpolated into glob
   patterns verbatim, so Glob('C:\\Users\\...\\Sdk/ndk/*/') matched
   nothing (or threw an 'expected more input' parser error).

2. input.json['user_defines'] is wrapped as
   {workspace_pubspec: {base_path: ..., defines: {...}}} by
   package:hooks, but 
un() forwarded the whole envelope to
   parseFromUserDefines, which reads keys off the top level — so
   �ndroid_home, cmake_version, etc. were never observed.

Fixes:

- UserConfig.androidHome is now normalised at construction time
  (backslashes -> forward slashes, trailing slash stripped, empty
  collapses to null). The three ad-hoc 
eplaceAll(r'\', '/') sites
  in android_ndk.dart / cmake.dart / ninja.dart are removed; the
  glob patterns now consume the already-normalised value directly.
  	ool_resolver.dart::tryResolvePath is left untouched so the
  intentional \(x86\) escape in msvc.dart keeps working.

- runStandalone peels workspace_pubspec.defines before parsing;
  both flat (direct callers / tests) and enveloped (hooks_runner /
  flutter build) shapes are accepted. Wrong-typed values are
  logged at WARNING and ignored instead of throwing TypeError.

- Priority chain for android_home is now explicit:
    user_defines.android.android_home
    -> env_file ANDROID_HOME (only when above is null)
    -> Platform.environment['ANDROID_HOME'] (last resort).

Tests:
- New test/builder/user_config_test.dart covers parseFromUserDefines,
  per-OS overrides, type-tolerance, env-var non-leak, path
  normalisation, and the workspace_pubspec unwrap helper.
- New test/native_toolchain/ndk_test.dart::issue-37-windows-backslash
  builds a fake on-disk SDK tree and asserts the resolver finds it
  through the normalised androidHome path.
@rainyl
rainyl merged commit af6ee6f into main Jul 21, 2026
20 of 21 checks passed
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.

Windows: NDK discovery fails when ANDROID_HOME contains backslashes

1 participant