Skip to content

Commit 02877c5

Browse files
committed
Add confirmation prompt for Android SDK installation
Introduces a '--yes' CLI option to automatically confirm dependency installations and adds a user prompt before installing the Android SDK if minimal packages are not present. Refactors AndroidSDK to include a static method for checking minimal package installation.
1 parent cb47dd8 commit 02877c5

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

sdk/python/packages/flet-cli/src/flet_cli/commands/flutter_base.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from rich.console import Console, Group
1111
from rich.panel import Panel
1212
from rich.progress import Progress
13+
from rich.prompt import Confirm
1314
from rich.style import Style
1415
from rich.theme import Theme
1516

@@ -64,6 +65,8 @@ def __init__(self, parser: argparse.ArgumentParser) -> None:
6465
"android": "Android",
6566
None: "iOS/Android",
6667
}
68+
self.assume_yes = False
69+
self._android_install_confirmed = False
6770

6871
def add_arguments(self, parser: argparse.ArgumentParser) -> None:
6972
parser.add_argument(
@@ -72,6 +75,14 @@ def add_arguments(self, parser: argparse.ArgumentParser) -> None:
7275
default=False,
7376
help="Disable rich output and prefer plain text. Useful on Windows builds",
7477
)
78+
parser.add_argument(
79+
"--yes",
80+
dest="assume_yes",
81+
action="store_true",
82+
default=False,
83+
help="Answer yes to all prompts (install dependencies "
84+
"without confirmation).",
85+
)
7586
parser.add_argument(
7687
"--skip-flutter-doctor",
7788
action="store_true",
@@ -83,6 +94,7 @@ def handle(self, options: argparse.Namespace) -> None:
8394
self.options = options
8495
self.no_rich_output = self.no_rich_output or self.options.no_rich_output
8596
self.verbose = self.options.verbose
97+
self.assume_yes = getattr(self.options, "assume_yes", False)
8698

8799
def initialize_command(self):
88100
assert self.options
@@ -113,6 +125,13 @@ def initialize_command(self):
113125
console.log("Dart executable:", self.dart_exe, style=verbose2_style)
114126

115127
if self.require_android_sdk:
128+
if not self._confirm_android_sdk_installation():
129+
self.skip_flutter_doctor = True
130+
self.cleanup(
131+
1,
132+
"Android SDK installation is required. "
133+
"Re-run with --yes to install automatically.",
134+
)
116135
self.install_jdk()
117136
self.install_android_sdk()
118137

@@ -237,6 +256,35 @@ def install_android_sdk(self):
237256
if self.verbose > 0:
238257
console.log(f"Android SDK installed {self.emojis['checkmark']}")
239258

259+
def _confirm_android_sdk_installation(self) -> bool:
260+
from flet_cli.utils.android_sdk import AndroidSDK
261+
262+
if AndroidSDK.has_minimal_packages_installed():
263+
self._android_install_confirmed = True
264+
return True
265+
if self._android_install_confirmed:
266+
return True
267+
if self.assume_yes:
268+
self._android_install_confirmed = True
269+
return True
270+
271+
prompt = (
272+
"\nAndroid SDK is required. If it's missing or incomplete, "
273+
"it will be installed now. Proceed? [y/N] "
274+
)
275+
276+
if self._prompt_input(prompt):
277+
self._android_install_confirmed = True
278+
return True
279+
return False
280+
281+
def _prompt_input(self, prompt: str) -> bool:
282+
self.live.stop()
283+
try:
284+
return Confirm.ask(prompt, default=True)
285+
finally:
286+
self.live.start()
287+
240288
def find_flutter_batch(self, exe_filename: str):
241289
batch_path = shutil.which(exe_filename)
242290
if not batch_path:

sdk/python/packages/flet-cli/src/flet_cli/utils/android_sdk.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,22 @@ def sdkmanager_exe(self, home_dir):
8484
assert bin
8585
return bin / self.tool_exe("sdkmanager", ".bat")
8686

87+
@staticmethod
88+
def has_minimal_packages_installed() -> bool:
89+
home_dir = AndroidSDK.android_home_dir()
90+
if not home_dir:
91+
return False
92+
93+
sdk = AndroidSDK("", lambda *_: None)
94+
if not sdk.cmdline_tools_bin(home_dir):
95+
return False
96+
97+
for package in MINIMAL_PACKAGES:
98+
if not home_dir.joinpath(*package.split(";")).exists():
99+
return False
100+
101+
return True
102+
87103
def cmdline_tools_url(self):
88104
try:
89105
url_platform = {

0 commit comments

Comments
 (0)