flutter/packages/flutter_tools/test/general.shard/android
Andrew Kolos c22c19b6e2
have Java.version return null if java --version fails or cannot be run (#139614)
## Summary
Fixes https://github.com/flutter/flutter/issues/139180, where `flutter create` could crash if the `java` binary the tool found cannot be run.

## Context

At startup, the tool searches for a Java installation[^1]. Unless the located installation is from [an Android Studio installation](e1967ecabf/packages/flutter_tools/lib/src/android/android_studio.dart (L163)), the tool does not verify that the binary is runnable. For more, see https://github.com/flutter/flutter/issues/139613, which tracks this inconsistency in behavior. 

This means that in the scenario where

1) the user does not have Android Studio installed or the java binary found within cannot be run **and**
2) the user has a) `flutter config --jdk-dir` set, b) `JAVA_HOME` set in their environment, **or** c) `java` on their system path **and**
3) the java binary we think we found during cannot be run (or `java --version` fails), **then**

the user running `flutter create` with Android enabled will hit a tool crash.

## Change

`Java.version` should return null if version checking fails for any reason. [This is documented behavior](48f57621ad/packages/flutter_tools/lib/src/android/java.dart (L136)). Therefore, we'll update the implementation to first verify that the binary is runnable. If it isn't, it will return `null`.

[^1]: We find java by calling the static `Java.find`, see: 48187028c1/packages/flutter_tools/lib/src/context_runner.dart (L271)
[^2]: This PR doesn't change this, as this would be too dangerous to cherry-pick into stable.
2023-12-06 23:13:17 +00:00
..
adb_log_reader_test.dart Ignore spam from SurfaceSyncer (#123262) 2023-03-23 21:55:39 +00:00
android_device_discovery_test.dart Separate attached and wireless devices (#122615) 2023-03-15 16:35:05 +00:00
android_device_port_forwarder_test.dart add missing trailing commas in list/set/map literals (#102585) 2022-04-27 09:15:35 +02:00
android_device_start_test.dart Add --trace-to-file option to flutter run (#135713) 2023-10-12 13:23:52 -04:00
android_device_test.dart Make AndroidApk nullable in stopApp. (#113353) 2022-10-13 17:03:57 +00:00
android_emulator_test.dart add missing trailing commas in list/set/map literals (#102585) 2022-04-27 09:15:35 +02:00
android_gradle_builder_test.dart [Reland] Migration for the sendTiming events for package:unified_analytics (#139299) 2023-12-04 21:39:18 +00:00
android_install_test.dart [tool] Install the corresponding APK in flutter run (#113622) 2022-10-19 02:44:30 +00:00
android_project_migration_test.dart [Android] Support Android 34 (take 2) (#137967) 2023-11-09 22:40:15 +00:00
android_sdk_test.dart Enable unreachable_from_main lint - it is stable now!!1 (#129854) 2023-07-06 00:09:01 +00:00
android_studio_test.dart [flutter_tools] Fix TypeError when a FileSystemException happens during flutter doctor (#133373) 2023-09-05 18:00:07 +00:00
android_studio_validator_test.dart [tool] In flutter doctor -v, warn when Android Studio version could not be detected. (#126395) 2023-06-01 14:51:30 +00:00
android_workflow_test.dart In flutter doctor -v, when JRE is too out-of-date to run sdkmanager, print a helpful error message (#138762) 2023-11-21 23:16:08 +00:00
build_validation_test.dart
deferred_components_gen_snapshot_validator_test.dart Revert "Speed up first asset load by encoding asset manifest in binary rather than JSON (#113637)" (#116662) 2022-12-07 17:29:05 +00:00
deferred_components_prebuild_validator_test.dart Fix typos (#121171) 2023-02-23 19:43:21 +00:00
gradle_errors_test.dart [Android] Support Android 34 (take 2) (#137967) 2023-11-09 22:40:15 +00:00
gradle_find_bundle_test.dart Unified analytics events migration for BuildEvent (#137562) 2023-11-01 19:56:50 +00:00
gradle_test.dart Stop recommending android sdk root (#136296) 2023-10-11 21:04:59 +00:00
gradle_utils_test.dart Protect flutter analyze --suggestions from erroring on missing AGP value. (#137719) 2023-11-02 21:14:58 +00:00
java_test.dart have Java.version return null if java --version fails or cannot be run (#139614) 2023-12-06 23:13:17 +00:00
multidex_test.dart [flutter_tools] migrate more unit tests to null safety (#106153) 2022-06-17 21:34:27 -07:00
template_test.dart Adding 'is' to list of kotlin reserved keywords (#116299) 2023-01-06 00:10:07 +00:00