Repository navigation
Commit 9d0f24e
Fix Android license detection for cmdline-tools 23.0+ (flutter#191554)
## Description
Fixes flutter#191487
Android SDK cmdline-tools 23.0 deprecated `sdkmanager --licenses` in
favor of the new `android` CLI. Running `sdkmanager --licenses` now only
prints a deprecation warning instead of the parseable license summary
Flutter previously relied on:
```
WARNING: The SDK Manager CLI tool (sdkmanager) is deprecated. Android CLI will be used instead.
The 'android' binary can also be found in the cmdline-tools directory, and 'android sdk' is the replacement for 'sdkmanager'.
To learn more about the Android CLI and how to use it, see the documentation (https://d.android.com/tools/agents/android-cli)
Warning: The --licenses option is no longer needed.
```
None of the existing regexes in `licensesAccepted` match this output, so
`flutter doctor` incorrectly reports `Android license status unknown`
even when licenses are actually accepted.
## Approach
I initially considered treating the new deprecation message as
`LicensesAccepted.all`, but testing against a real cmdline-tools 23.0
install showed this message prints identically whether or not the
licenses directory exists — so it can't be trusted as a signal of actual
license state. I verified this by temporarily renaming my
`<sdk>/licenses` directory and re-running `sdkmanager --licenses`; the
output was byte-for-byte identical either way.
I also checked the new `android` CLI's `--help` output (`sdk`, `sdk
install`, `info`) — there's no license-status subcommand or flag exposed
in this version, so there's no better structured signal to query
instead.
Since the SDK's actual license acceptance state is still tracked on disk
under `<sdk>/licenses/` (this is presumably what Gradle checks directly,
since Gradle builds still succeed after this cmdline-tools update), this
PR adds a narrow, additive fallback:
- When `sdkmanager`'s output matches the specific new-CLI deprecation
message (and only then — not for arbitrary unparseable/garbage output),
`licensesAccepted` checks the `licenses/` directory on disk directly
instead of trusting stdout.
- All existing regex-based parsing for older `sdkmanager` versions is
untouched.
## Known limitation
This fallback can only distinguish "some license files are present and
non-empty" (→ `all`) from "no license files at all" (→ `none`). It
cannot reproduce the previous `LicensesAccepted.some` state for the new
CLI, since that information is no longer exposed by the tool in any form
I could find. Happy to adjust the approach if maintainers have a
preference here.
## Tests
Added two regression tests reproducing the exact real-world output
captured from a Windows machine running cmdline-tools 23.0:
- `licensesAccepted falls back to the licenses directory when sdkmanager
output is unparseable (new Android CLI, licenses present)`
- `licensesAccepted falls back to none when sdkmanager output is
unparseable and no licenses are present (new Android CLI, licenses
missing)`
All existing tests in `android_workflow_test.dart` continue to pass
(35/35).
Also manually verified end-to-end: `flutter doctor -v` on the affected
machine now correctly reports `All Android licenses accepted.` instead
of `Android license status unknown.`
---------
Co-authored-by: Gray Mackall <[email protected]>1 parent 625c5c9 commit 9d0f24e
2 files changed
Lines changed: 138 additions & 1 deletion
File tree
- packages/flutter_tools
- lib/src/android
- test/general.shard/android
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
36 | 40 | | |
37 | 41 | | |
38 | 42 | | |
| |||
446 | 450 | | |
447 | 451 | | |
448 | 452 | | |
| 453 | + | |
449 | 454 | | |
450 | 455 | | |
451 | 456 | | |
| |||
462 | 467 | | |
463 | 468 | | |
464 | 469 | | |
| 470 | + | |
| 471 | + | |
465 | 472 | | |
466 | 473 | | |
467 | 474 | | |
| |||
488 | 495 | | |
489 | 496 | | |
490 | 497 | | |
491 | | - | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
492 | 505 | | |
493 | 506 | | |
494 | 507 | | |
495 | 508 | | |
496 | 509 | | |
497 | 510 | | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
498 | 529 | | |
499 | 530 | | |
500 | 531 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
307 | 307 | | |
308 | 308 | | |
309 | 309 | | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
310 | 416 | | |
311 | 417 | | |
312 | 418 | | |
| |||
0 commit comments