flet-cli 1.1.0.dev2__py3-none-any.whl → 1.1.0.dev4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,7 @@ import argparse
2
2
  import base64
3
3
  import contextlib
4
4
  import copy
5
+ import datetime
5
6
  import glob
6
7
  import hashlib
7
8
  import json
@@ -53,6 +54,9 @@ from flet_cli.utils.android import (
53
54
  android_resource_files,
54
55
  android_resources_keep_xml,
55
56
  excluded_android_abis,
57
+ normalize_android_activity,
58
+ normalize_android_application_attributes,
59
+ normalize_android_queries,
56
60
  normalize_android_receivers,
57
61
  normalize_android_services,
58
62
  )
@@ -103,6 +107,90 @@ DEFAULT_ANDROID_COMPILE_OPTIONS = {
103
107
  # real offenders here as they are found.
104
108
  ANDROID_DEFAULT_EXTRACT_PACKAGES: list[str] = []
105
109
 
110
+ CROSS_PLATFORM_PERMISSIONS = {
111
+ "location": {
112
+ "ios_info_plist": {
113
+ "NSLocationWhenInUseUsageDescription": "This app uses location service when in use.", # noqa: E501
114
+ "NSLocationAlwaysAndWhenInUseUsageDescription": "This app uses location service.", # noqa: E501
115
+ },
116
+ "macos_info_plist": {
117
+ "NSLocationUsageDescription": "This app needs access to your location.", # noqa: E501
118
+ },
119
+ "macos_entitlements": {
120
+ "com.apple.security.personal-information.location": True
121
+ },
122
+ "android_permissions": {
123
+ "android.permission.ACCESS_FINE_LOCATION": True,
124
+ "android.permission.ACCESS_COARSE_LOCATION": True,
125
+ "android.permission.ACCESS_BACKGROUND_LOCATION": True,
126
+ },
127
+ "android_features": {
128
+ "android.hardware.location.network": False,
129
+ "android.hardware.location.gps": False,
130
+ },
131
+ },
132
+ "camera": {
133
+ "ios_info_plist": {
134
+ "NSCameraUsageDescription": "This app uses the camera to capture photos and videos." # noqa: E501
135
+ },
136
+ "macos_info_plist": {
137
+ "NSCameraUsageDescription": "This app uses the camera to capture photos and videos." # noqa: E501
138
+ },
139
+ "macos_entitlements": {"com.apple.security.device.camera": True},
140
+ "android_permissions": {"android.permission.CAMERA": True},
141
+ "android_features": {
142
+ "android.hardware.camera": False,
143
+ "android.hardware.camera.any": False,
144
+ "android.hardware.camera.front": False,
145
+ "android.hardware.camera.external": False,
146
+ "android.hardware.camera.autofocus": False,
147
+ },
148
+ },
149
+ "microphone": {
150
+ "ios_info_plist": {
151
+ "NSMicrophoneUsageDescription": "This app uses microphone to record sounds.", # noqa: E501
152
+ },
153
+ "macos_info_plist": {
154
+ "NSMicrophoneUsageDescription": "This app uses microphone to record sounds.", # noqa: E501
155
+ },
156
+ "macos_entitlements": {"com.apple.security.device.audio-input": True},
157
+ # Recording itself only needs RECORD_AUDIO: recordings are written
158
+ # to app-scoped storage, which requires no permission. Do not add
159
+ # READ/WRITE_EXTERNAL_STORAGE here — Google Play's Photo and Video
160
+ # Permissions policy rejects apps that request broad media/storage
161
+ # access without a qualifying use case, and this group is opt-in
162
+ # for the microphone, not for the user's media library.
163
+ "android_permissions": {"android.permission.RECORD_AUDIO": True},
164
+ "android_features": {},
165
+ },
166
+ "photo_library": {
167
+ "ios_info_plist": {
168
+ "NSPhotoLibraryUsageDescription": "This app saves photos and videos to the photo library." # noqa: E501
169
+ },
170
+ "macos_info_plist": {
171
+ "NSPhotoLibraryUsageDescription": "This app saves photos and videos to the photo library." # noqa: E501
172
+ },
173
+ "macos_entitlements": {
174
+ "com.apple.security.personal-information.photos-library": True
175
+ },
176
+ "android_permissions": {
177
+ "android.permission.READ_MEDIA_VISUAL_USER_SELECTED": True
178
+ },
179
+ "android_features": {},
180
+ },
181
+ "biometric": {
182
+ "ios_info_plist": {
183
+ "NSFaceIDUsageDescription": "This app uses biometrics to authenticate you." # noqa: E501
184
+ },
185
+ "macos_info_plist": {
186
+ "NSFaceIDUsageDescription": "This app uses biometrics to authenticate you." # noqa: E501
187
+ },
188
+ "macos_entitlements": {},
189
+ "android_permissions": {},
190
+ "android_features": {},
191
+ },
192
+ }
193
+
106
194
  # Bumped whenever a change to flet-platform-assets alters the pixels it
107
195
  # produces. Both stamps hash it, so upgrading flet-cli regenerates rather
108
196
  # than leaving a user with output from the previous implementation. Nothing
@@ -253,90 +341,6 @@ class BaseBuildCommand(BaseFlutterCommand):
253
341
  },
254
342
  }
255
343
 
256
- self.cross_platform_permissions = {
257
- "location": {
258
- "ios_info_plist": {
259
- "NSLocationWhenInUseUsageDescription": "This app uses location service when in use.", # noqa: E501
260
- "NSLocationAlwaysAndWhenInUseUsageDescription": "This app uses location service.", # noqa: E501
261
- },
262
- "macos_info_plist": {
263
- "NSLocationUsageDescription": "This app needs access to your location.", # noqa: E501
264
- },
265
- "macos_entitlements": {
266
- "com.apple.security.personal-information.location": True
267
- },
268
- "android_permissions": {
269
- "android.permission.ACCESS_FINE_LOCATION": True,
270
- "android.permission.ACCESS_COARSE_LOCATION": True,
271
- "android.permission.ACCESS_BACKGROUND_LOCATION": True,
272
- },
273
- "android_features": {
274
- "android.hardware.location.network": False,
275
- "android.hardware.location.gps": False,
276
- },
277
- },
278
- "camera": {
279
- "ios_info_plist": {
280
- "NSCameraUsageDescription": "This app uses the camera to capture photos and videos." # noqa: E501
281
- },
282
- "macos_info_plist": {
283
- "NSCameraUsageDescription": "This app uses the camera to capture photos and videos." # noqa: E501
284
- },
285
- "macos_entitlements": {"com.apple.security.device.camera": True},
286
- "android_permissions": {"android.permission.CAMERA": True},
287
- "android_features": {
288
- "android.hardware.camera": False,
289
- "android.hardware.camera.any": False,
290
- "android.hardware.camera.front": False,
291
- "android.hardware.camera.external": False,
292
- "android.hardware.camera.autofocus": False,
293
- },
294
- },
295
- "microphone": {
296
- "ios_info_plist": {
297
- "NSMicrophoneUsageDescription": "This app uses microphone to record sounds.", # noqa: E501
298
- },
299
- "macos_info_plist": {
300
- "NSMicrophoneUsageDescription": "This app uses microphone to record sounds.", # noqa: E501
301
- },
302
- "macos_entitlements": {"com.apple.security.device.audio-input": True},
303
- # Recording itself only needs RECORD_AUDIO: recordings are written
304
- # to app-scoped storage, which requires no permission. Do not add
305
- # READ/WRITE_EXTERNAL_STORAGE here — Google Play's Photo and Video
306
- # Permissions policy rejects apps that request broad media/storage
307
- # access without a qualifying use case, and this group is opt-in
308
- # for the microphone, not for the user's media library.
309
- "android_permissions": {"android.permission.RECORD_AUDIO": True},
310
- "android_features": {},
311
- },
312
- "photo_library": {
313
- "ios_info_plist": {
314
- "NSPhotoLibraryUsageDescription": "This app saves photos and videos to the photo library." # noqa: E501
315
- },
316
- "macos_info_plist": {
317
- "NSPhotoLibraryUsageDescription": "This app saves photos and videos to the photo library." # noqa: E501
318
- },
319
- "macos_entitlements": {
320
- "com.apple.security.personal-information.photos-library": True
321
- },
322
- "android_permissions": {
323
- "android.permission.READ_MEDIA_VISUAL_USER_SELECTED": True
324
- },
325
- "android_features": {},
326
- },
327
- "biometric": {
328
- "ios_info_plist": {
329
- "NSFaceIDUsageDescription": "This app uses biometrics to authenticate you." # noqa: E501
330
- },
331
- "macos_info_plist": {
332
- "NSFaceIDUsageDescription": "This app uses biometrics to authenticate you." # noqa: E501
333
- },
334
- "macos_entitlements": {},
335
- "android_permissions": {},
336
- "android_features": {},
337
- },
338
- }
339
-
340
344
  # create and display build-platform-matrix table
341
345
  self.platform_matrix_table = Table(
342
346
  Column("Command", style="cyan", justify="left"),
@@ -779,7 +783,7 @@ class BaseBuildCommand(BaseFlutterCommand):
779
783
  action="extend",
780
784
  nargs="+",
781
785
  default=[],
782
- choices=["location", "camera", "microphone", "photo_library"],
786
+ choices=list(CROSS_PLATFORM_PERMISSIONS),
783
787
  help="The list of pre-defined cross-platform permissions for iOS, Android "
784
788
  "and macOS builds",
785
789
  )
@@ -787,12 +791,13 @@ class BaseBuildCommand(BaseFlutterCommand):
787
791
  "--deep-linking-scheme",
788
792
  dest="deep_linking_scheme",
789
793
  help="Deep linking URL scheme to configure for iOS and Android builds, "
790
- "i.g. `https` or `myapp`",
794
+ "e.g. `myapp` or `https`",
791
795
  )
792
796
  parser.add_argument(
793
797
  "--deep-linking-host",
794
798
  dest="deep_linking_host",
795
- help="Deep linking URL host for iOS and Android builds",
799
+ help="Deep linking URL host for iOS and Android builds; optional except "
800
+ "for `http` and `https` schemes. Requires --deep-linking-scheme",
796
801
  )
797
802
  parser.add_argument(
798
803
  "--android-signing-key-store",
@@ -1033,6 +1038,29 @@ class BaseBuildCommand(BaseFlutterCommand):
1033
1038
  f"[magenta]{self.current_platform}[/]."
1034
1039
  self.cleanup(1, message)
1035
1040
 
1041
+ def validate_artifact_name(self, artifact_name: Any):
1042
+ """
1043
+ Stop the build if the artifact name can't name a file on the target platform.
1044
+
1045
+ A Windows app's artifact name names its `.exe` file, which can't contain
1046
+ any of `< > : " / \\ | ? *`.
1047
+
1048
+ Args:
1049
+ artifact_name: The resolved artifact name.
1050
+ """
1051
+ if self.config_platform != "windows":
1052
+ return
1053
+ invalid = sorted(set(str(artifact_name)) & set('<>:"/\\|?*'))
1054
+ if invalid:
1055
+ self.skip_flutter_doctor = True
1056
+ self.cleanup(
1057
+ 1,
1058
+ f"Artifact name {escape(repr(str(artifact_name)))} can't be used on "
1059
+ f"Windows, where a file name can't contain {' '.join(invalid)}. "
1060
+ "Set a different name with --artifact or "
1061
+ f"{escape('`artifact` in [tool.flet]')}.",
1062
+ )
1063
+
1036
1064
  def validate_entry_point(self):
1037
1065
  """
1038
1066
  Resolve app entry-point module and ensure corresponding Python file exists.
@@ -1097,8 +1125,7 @@ class BaseBuildCommand(BaseFlutterCommand):
1097
1125
  )
1098
1126
  artifact_name = (
1099
1127
  self.options.artifact_name
1100
- or self.get_pyproject(f"tool.flet.{self.config_platform}.artifact")
1101
- or self.get_pyproject("tool.flet.artifact")
1128
+ or self.get_platform_setting("artifact")
1102
1129
  or self.default_artifact_name(
1103
1130
  self.config_platform, product_name, project_name_raw
1104
1131
  )
@@ -1110,6 +1137,7 @@ class BaseBuildCommand(BaseFlutterCommand):
1110
1137
  # test host can't find the binary. Pin them equal in test mode.
1111
1138
  if getattr(self, "test_mode", False):
1112
1139
  artifact_name = project_name
1140
+ self.validate_artifact_name(artifact_name)
1113
1141
 
1114
1142
  split_per_abi = (
1115
1143
  self.options.split_per_abi
@@ -1142,433 +1170,94 @@ class BaseBuildCommand(BaseFlutterCommand):
1142
1170
  title="Impeller",
1143
1171
  )
1144
1172
 
1145
- # Explicit `[tool.flet.macos.info]` or `--info-plist` entries override
1146
- # this key.
1147
- info_plist = (
1148
- {"FLTEnableImpeller": False}
1149
- if self.package_platform == "Darwin" and not impeller
1150
- else {}
1151
- )
1152
- macos_entitlements = {
1153
- "com.apple.security.app-sandbox": False,
1154
- "com.apple.security.cs.allow-jit": True,
1155
- "com.apple.security.cs.allow-unsigned-executable-memory": True,
1156
- "com.apple.security.network.client": True,
1157
- "com.apple.security.network.server": True,
1158
- "com.apple.security.files.user-selected.read-write": True,
1159
- }
1160
- android_permissions = {"android.permission.INTERNET": True}
1161
- android_features = {
1162
- "android.software.leanback": False,
1163
- "android.hardware.touchscreen": False,
1164
- }
1165
- # Explicit `[tool.flet.android.meta_data]` or `--android-meta-data`
1166
- # entries override this key.
1167
- android_meta_data = (
1168
- {"io.flutter.embedding.android.EnableImpeller": "false"}
1169
- if not impeller
1170
- else {}
1171
- )
1172
- android_providers = {}
1173
- # Gradle properties for the generated Android project. These were
1174
- # hardcoded in the template; the defaults below reproduce them exactly,
1175
- # and `[tool.flet.android.gradle_properties]` can override any entry or
1176
- # add new ones. The memory settings in particular are too large for some
1177
- # CI runners (a standard GitHub-hosted runner has ~7 GB of RAM, less
1178
- # than -Xmx8G alone), which previously could not be changed at all.
1179
- android_gradle_properties = {
1180
- "org.gradle.jvmargs": (
1181
- "-Xmx8G -XX:MaxMetaspaceSize=4G "
1182
- "-XX:ReservedCodeCacheSize=512m -XX:+HeapDumpOnOutOfMemoryError"
1183
- ),
1184
- "android.useAndroidX": "true",
1185
- # Kotlin's incremental compiler stores plugin sources relative to
1186
- # the Android project and fails the build when they sit on another
1187
- # Windows drive, e.g. the pub cache on C: and the app on D:.
1188
- "kotlin.incremental": "false",
1189
- }
1190
- # ProGuard/R8 rules for the generated Android project. Like
1191
- # gradle_properties above, these were a fixed template file and the
1192
- # defaults reproduce it exactly. R8 renames classes in release builds
1193
- # while pyjnius resolves them by name, so an app that reaches into a
1194
- # bundled AAR needs a keep rule and had no way to add one.
1195
- #
1196
- # `proguard_rules` appends, since R8 has no directive that undoes a
1197
- # keep. Removing a default therefore needs its own switch:
1198
- # `proguard_default_rules = false` drops them, which is the only way to
1199
- # shed `-keepnames class * { *; }`. Keeping the two separate stops
1200
- # users pasting today's defaults into pyproject.toml and silently
1201
- # holding them after the defaults change.
1202
- keep_defaults = (
1203
- self.get_pyproject("tool.flet.android.proguard_default_rules") is not False
1204
- )
1205
- android_proguard_rules = (
1206
- [
1207
- "-keep class com.flet.serious_python_android.** { *; }",
1208
- "-keepnames class * { *; }",
1209
- ]
1210
- if keep_defaults
1211
- else []
1212
- )
1173
+ android_permissions = self.get_android_permissions()
1174
+ android_features = self.get_android_features()
1175
+ android_meta_data = self.get_android_meta_data(impeller)
1176
+ android_providers = self.get_android_providers()
1177
+ android_gradle_properties = self.get_android_gradle_properties()
1178
+ android_proguard_rules = self.get_android_proguard_rules()
1213
1179
 
1214
- # merge values from "--permissions" arg:
1215
- for p in self.resolve_permissions():
1216
- if p in self.cross_platform_permissions:
1217
- permission_config = self.cross_platform_permissions[p]
1218
- info_plist.update(
1219
- permission_config.get(f"{self.config_platform}_info_plist", {})
1220
- or permission_config.get("info_plist", {})
1221
- )
1222
- macos_entitlements.update(
1223
- self.cross_platform_permissions[p]["macos_entitlements"]
1224
- )
1225
- android_permissions.update(
1226
- self.cross_platform_permissions[p]["android_permissions"]
1227
- )
1228
- android_features.update(
1229
- self.cross_platform_permissions[p]["android_features"]
1230
- )
1180
+ deep_linking = self.get_deep_linking()
1231
1181
 
1232
- info_plist = merge_dict(
1233
- info_plist,
1234
- (
1235
- self.get_pyproject("tool.flet.macos.info")
1236
- if self.package_platform == "Darwin"
1237
- else self.get_pyproject("tool.flet.ios.info")
1238
- )
1239
- or {},
1182
+ target_arch = self.options.target_arch or self.get_platform_setting(
1183
+ "target_arch"
1240
1184
  )
1241
-
1242
- # parse --info-plist
1243
- for p in self.options.info_plist:
1244
- i = p.find("=")
1245
- if i > -1:
1246
- k = p[:i]
1247
- v = p[i + 1 :]
1248
- info_plist[k] = parse_cli_plist_value(v)
1249
- else:
1250
- self.cleanup(1, f"Invalid Info.plist option: {p}")
1251
-
1252
- for key, value in info_plist.items():
1253
- if not is_supported_plist_value(value):
1185
+ target_arch = (
1186
+ target_arch
1187
+ if isinstance(target_arch, list)
1188
+ else [target_arch]
1189
+ if isinstance(target_arch, str)
1190
+ else []
1191
+ )
1192
+ if self.package_platform == "Android":
1193
+ invalid_archs = [
1194
+ arch
1195
+ for arch in target_arch
1196
+ if arch not in ANDROID_ARCH_TO_FLUTTER_TARGET_PLATFORM
1197
+ ]
1198
+ if invalid_archs:
1254
1199
  self.cleanup(
1255
1200
  1,
1256
- "Unsupported Info.plist value type for "
1257
- f"{key}: {type(value).__name__}. Supported types are "
1258
- "string, boolean, integer, float, dictionary, and arrays "
1259
- "containing those values.",
1201
+ f"Invalid Android architecture(s): {', '.join(invalid_archs)}.\n"
1202
+ f"Supported: "
1203
+ f"{', '.join(ANDROID_ARCH_TO_FLUTTER_TARGET_PLATFORM)}.\n"
1204
+ f"Docs: https://flet.dev/docs/publish/android#supported-target-architectures",
1260
1205
  )
1261
-
1262
- macos_entitlements = merge_dict(
1263
- macos_entitlements,
1264
- self.get_pyproject("tool.flet.macos.entitlement") or {},
1265
- )
1266
-
1267
- # parse --macos-entitlements
1268
- for p in self.options.macos_entitlements:
1269
- i = p.find("=")
1270
- if i > -1:
1271
- macos_entitlements[p[:i]] = parse_cli_plist_value(p[i + 1 :])
1272
- else:
1273
- self.cleanup(1, f"Invalid macOS entitlement option: {p}")
1274
-
1275
- for key, value in macos_entitlements.items():
1276
- if not is_supported_plist_value(value):
1206
+ python_abis = list(self.python_release.android_abis)
1207
+ unsupported_archs = [a for a in target_arch if a not in python_abis]
1208
+ if unsupported_archs:
1277
1209
  self.cleanup(
1278
1210
  1,
1279
- "Unsupported macOS entitlement value type for "
1280
- f"{key}: {type(value).__name__}. Supported types are "
1281
- "string, boolean, integer, float, dictionary, and arrays "
1282
- "containing those values.",
1211
+ f"Architecture(s) not supported by Python "
1212
+ f"{self.python_release.short}: {', '.join(unsupported_archs)}.\n"
1213
+ f"Supported: {', '.join(python_abis)}.\n"
1214
+ f"Docs: https://flet.dev/docs/publish/android#supported-target-architectures",
1283
1215
  )
1216
+ if not target_arch:
1217
+ # Build only for the ABIs the bundled Python supports.
1218
+ target_arch = python_abis
1284
1219
 
1285
- android_permissions = merge_dict(
1286
- android_permissions,
1287
- self.get_pyproject("tool.flet.android.permission") or {},
1288
- )
1289
-
1290
- android_gradle_properties = merge_dict(
1291
- android_gradle_properties,
1292
- self.get_pyproject("tool.flet.android.gradle_properties") or {},
1293
- )
1294
-
1295
- android_proguard_rules = android_proguard_rules + [
1296
- str(rule)
1297
- for rule in (self.get_pyproject("tool.flet.android.proguard_rules") or [])
1298
- ]
1299
-
1300
- # parse --android-permissions
1301
- for p in self.options.android_permissions:
1302
- i = p.find("=")
1303
- if i > -1:
1304
- try:
1305
- android_permissions[p[:i]] = parse_cli_bool_value(p[i + 1 :])
1306
- except ValueError:
1307
- self.cleanup(
1308
- 1,
1309
- f"Invalid Android permission option value for {p[:i]}: "
1310
- f"{p[i + 1 :]}. Expected true or false.",
1311
- )
1312
- else:
1313
- self.cleanup(1, f"Invalid Android permission option: {p}")
1220
+ ios_signing = self.get_ios_signing()
1314
1221
 
1315
- for key, value in android_permissions.items():
1316
- if isinstance(value, bool):
1317
- continue
1318
- if isinstance(value, dict):
1319
- for ak, av in value.items():
1320
- if not isinstance(av, (str, bool, int, float)):
1321
- self.cleanup(
1322
- 1,
1323
- f"Invalid Android permission attribute value for "
1324
- f"{key}.{ak}: {type(av).__name__}. "
1325
- "Expected string, boolean, or number.",
1326
- )
1327
- continue
1328
- self.cleanup(
1329
- 1,
1330
- f"Invalid Android permission value for {key}: "
1331
- f"{type(value).__name__}. Expected boolean or inline table.",
1222
+ if (
1223
+ self.target_platform in ["ipa"]
1224
+ and not ios_signing["provisioning_profile"]
1225
+ and not self.debug_platform
1226
+ and not getattr(self, "test_mode", False)
1227
+ ):
1228
+ self.warn(
1229
+ "This build will generate an .xcarchive (Xcode Archive). "
1230
+ "To produce an .ipa (iOS App Package), please specify "
1231
+ "a Provisioning Profile.",
1232
+ title="iOS signing",
1233
+ panel=True,
1332
1234
  )
1333
1235
 
1334
- android_features = merge_dict(
1335
- android_features,
1336
- self.get_pyproject("tool.flet.android.feature") or {},
1337
- )
1338
-
1339
- # parse --android-features
1340
- for p in self.options.android_features:
1341
- i = p.find("=")
1342
- if i > -1:
1343
- try:
1344
- android_features[p[:i]] = parse_cli_bool_value(p[i + 1 :])
1345
- except ValueError:
1346
- self.cleanup(
1347
- 1,
1348
- f"Invalid Android feature option value for {p[:i]}: "
1349
- f"{p[i + 1 :]}. Expected true or false.",
1350
- )
1351
- else:
1352
- self.cleanup(1, f"Invalid Android feature option: {p}")
1353
-
1354
- android_meta_data = merge_dict(
1355
- android_meta_data,
1356
- self.get_pyproject("tool.flet.android.meta_data") or {},
1236
+ assert self.flutter_dir
1237
+ project_description = (
1238
+ self.options.description
1239
+ or self.get_pyproject("project.description")
1240
+ or self.get_pyproject("tool.poetry.description")
1241
+ or ""
1357
1242
  )
1358
-
1359
- # parse --android-meta-data
1360
- for p in self.options.android_meta_data:
1361
- i = p.find("=")
1362
- if i > -1:
1363
- android_meta_data[p[:i]] = p[i + 1 :]
1364
- else:
1365
- self.cleanup(1, f"Invalid Android meta-data option: {p}")
1366
-
1367
- android_providers = merge_dict(
1368
- android_providers,
1369
- self.get_pyproject("tool.flet.android.provider") or {},
1370
- )
1371
-
1372
- def _xml_attr_value(v):
1373
- # Android XML expects lowercase booleans.
1374
- if isinstance(v, bool):
1375
- return "true" if v else "false"
1376
- return v
1377
-
1378
- normalized_providers = {}
1379
- for key, value in android_providers.items():
1380
- if value is False or value == {}:
1381
- continue
1382
- if value is True:
1383
- self.cleanup(
1384
- 1,
1385
- f"Invalid Android provider value for {key}: 'true' is not "
1386
- "supported. Use an inline table of attributes, or 'false' "
1387
- "to skip.",
1388
- )
1389
- if not isinstance(value, dict):
1390
- self.cleanup(
1391
- 1,
1392
- f"Invalid Android provider value for {key}: "
1393
- f"{type(value).__name__}. Expected boolean or inline table.",
1394
- )
1395
- normalized = {}
1396
- for ak, av in value.items():
1397
- if ak == "name":
1398
- self.cleanup(
1399
- 1,
1400
- f"Invalid Android provider attribute for {key}: "
1401
- "'name' is reserved and is taken from the table key.",
1402
- )
1403
- if ak == "meta_data":
1404
- if not isinstance(av, dict):
1405
- self.cleanup(
1406
- 1,
1407
- f"Invalid Android provider meta_data for {key}: "
1408
- f"{type(av).__name__}. Expected inline table.",
1409
- )
1410
- normalized_meta = {}
1411
- for mk, mv in av.items():
1412
- if isinstance(mv, (str, bool, int, float)):
1413
- normalized_meta[mk] = _xml_attr_value(mv)
1414
- continue
1415
- if isinstance(mv, dict):
1416
- normalized_attrs = {}
1417
- for attr_key, attr_value in mv.items():
1418
- if not isinstance(attr_value, (str, bool, int, float)):
1419
- self.cleanup(
1420
- 1,
1421
- f"Invalid Android provider meta-data "
1422
- f"attribute value for "
1423
- f"{key}.meta_data.{mk}.{attr_key}: "
1424
- f"{type(attr_value).__name__}. "
1425
- "Expected string, boolean, or number.",
1426
- )
1427
- normalized_attrs[attr_key] = _xml_attr_value(attr_value)
1428
- normalized_meta[mk] = normalized_attrs
1429
- continue
1430
- self.cleanup(
1431
- 1,
1432
- f"Invalid Android provider meta-data value for "
1433
- f"{key}.meta_data.{mk}: {type(mv).__name__}. "
1434
- "Expected string, boolean, number, or inline table.",
1435
- )
1436
- normalized["meta_data"] = normalized_meta
1437
- continue
1438
- if not isinstance(av, (str, bool, int, float)):
1439
- self.cleanup(
1440
- 1,
1441
- f"Invalid Android provider attribute value for "
1442
- f"{key}.{ak}: {type(av).__name__}. "
1443
- "Expected string, boolean, or number.",
1444
- )
1445
- normalized[ak] = _xml_attr_value(av)
1446
- normalized_providers[key] = normalized
1447
- android_providers = normalized_providers
1448
-
1449
- deep_linking_scheme = self.get_deep_linking_setting("scheme")
1450
- deep_linking_host = self.get_deep_linking_setting("host")
1451
-
1452
- if self.options.deep_linking_scheme and self.options.deep_linking_host:
1453
- deep_linking_scheme = self.options.deep_linking_scheme
1454
- deep_linking_host = self.options.deep_linking_host
1455
-
1456
- target_arch = self.options.target_arch or self.get_platform_setting(
1457
- "target_arch"
1458
- )
1459
- target_arch = (
1460
- target_arch
1461
- if isinstance(target_arch, list)
1462
- else [target_arch]
1463
- if isinstance(target_arch, str)
1464
- else []
1465
- )
1466
- if self.package_platform == "Android":
1467
- invalid_archs = [
1468
- arch
1469
- for arch in target_arch
1470
- if arch not in ANDROID_ARCH_TO_FLUTTER_TARGET_PLATFORM
1471
- ]
1472
- if invalid_archs:
1473
- self.cleanup(
1474
- 1,
1475
- f"Invalid Android architecture(s): {', '.join(invalid_archs)}.\n"
1476
- f"Supported: "
1477
- f"{', '.join(ANDROID_ARCH_TO_FLUTTER_TARGET_PLATFORM)}.\n"
1478
- f"Docs: https://flet.dev/docs/publish/android#supported-target-architectures",
1479
- )
1480
- python_abis = list(self.python_release.android_abis)
1481
- unsupported_archs = [a for a in target_arch if a not in python_abis]
1482
- if unsupported_archs:
1483
- self.cleanup(
1484
- 1,
1485
- f"Architecture(s) not supported by Python "
1486
- f"{self.python_release.short}: {', '.join(unsupported_archs)}.\n"
1487
- f"Supported: {', '.join(python_abis)}.\n"
1488
- f"Docs: https://flet.dev/docs/publish/android#supported-target-architectures",
1489
- )
1490
- if not target_arch:
1491
- # Build only for the ABIs the bundled Python supports.
1492
- target_arch = python_abis
1493
-
1494
- ios_export_method = (
1495
- self.options.ios_export_method
1496
- or self.get_pyproject("tool.flet.ios.export_method")
1497
- or "debugging"
1498
- )
1499
-
1500
- ios_export_method_opts = (
1501
- self.get_pyproject("tool.flet.ios.export_methods").get(ios_export_method)
1502
- if self.get_pyproject("tool.flet.ios.export_methods")
1503
- else {}
1504
- ) or {}
1505
-
1506
- ios_provisioning_profile = (
1507
- self.options.ios_provisioning_profile
1508
- or ios_export_method_opts.get("provisioning_profile")
1509
- or self.get_pyproject("tool.flet.ios.provisioning_profile")
1510
- )
1511
-
1512
- ios_signing_certificate = (
1513
- self.options.ios_signing_certificate
1514
- or ios_export_method_opts.get("signing_certificate")
1515
- or self.get_pyproject("tool.flet.ios.signing_certificate")
1516
- )
1517
-
1518
- ios_export_options = (
1519
- ios_export_method_opts.get("export_options")
1520
- or self.get_pyproject("tool.flet.ios.export_options")
1521
- or {}
1522
- )
1523
-
1524
- ios_team_id = (
1525
- self.options.ios_team_id
1526
- or ios_export_method_opts.get("team_id")
1527
- or self.get_pyproject("tool.flet.ios.team_id")
1528
- )
1529
-
1530
- if (
1531
- self.target_platform in ["ipa"]
1532
- and not ios_provisioning_profile
1533
- and not self.debug_platform
1534
- and not getattr(self, "test_mode", False)
1535
- ):
1536
- self.warn(
1537
- "This build will generate an .xcarchive (Xcode Archive). "
1538
- "To produce an .ipa (iOS App Package), please specify "
1539
- "a Provisioning Profile.",
1540
- title="iOS signing",
1541
- panel=True,
1542
- )
1543
-
1544
- assert self.flutter_dir
1545
- project_description = (
1546
- self.options.description
1547
- or self.get_pyproject("project.description")
1548
- or self.get_pyproject("tool.poetry.description")
1549
- or ""
1550
- )
1551
- linux_categories = self.escape_linux_desktop_categories(["Utility"])
1552
- if self.target_platform == "linux":
1553
- try:
1554
- # Desktop entry values are escaped here rather than in the template:
1555
- # the rules differ per key and getting them wrong yields an entry the
1556
- # desktop environment silently discards.
1557
- linux_categories = self.escape_linux_desktop_categories(
1558
- self.options.linux_categories
1559
- or self.get_pyproject("tool.flet.linux.categories")
1560
- or ["Utility"]
1561
- )
1562
- except ValueError as e:
1563
- self.cleanup(1, f"Invalid tool.flet.linux.categories: {e}")
1564
- # Resolved before the context, because the PWA background falls
1565
- # through to it.
1566
- splash = self._resolve_splash()
1567
- org_name = (
1568
- self.options.org_name
1569
- or self.get_pyproject(f"tool.flet.{self.config_platform}.org")
1570
- or self.get_pyproject("tool.flet.org")
1571
- or "com.flet"
1243
+ linux_categories = self.escape_linux_desktop_categories(["Utility"])
1244
+ if self.target_platform == "linux":
1245
+ try:
1246
+ # Desktop entry values are escaped here rather than in the template:
1247
+ # the rules differ per key and getting them wrong yields an entry the
1248
+ # desktop environment silently discards.
1249
+ linux_categories = self.escape_linux_desktop_categories(
1250
+ self.options.linux_categories
1251
+ or self.get_pyproject("tool.flet.linux.categories")
1252
+ or ["Utility"]
1253
+ )
1254
+ except ValueError as e:
1255
+ self.cleanup(1, f"Invalid tool.flet.linux.categories: {e}")
1256
+ # Resolved before the context, because the PWA background falls
1257
+ # through to it.
1258
+ splash = self._resolve_splash()
1259
+ org_name = (
1260
+ self.options.org_name or self.get_platform_setting("org") or "com.flet"
1572
1261
  )
1573
1262
 
1574
1263
  self.template_data = {
@@ -1649,19 +1338,16 @@ class BaseBuildCommand(BaseFlutterCommand):
1649
1338
  # The template derives nothing from these: the build names files
1650
1339
  # after the bundle ID too, such as the app's Linux icons.
1651
1340
  "bundle_id": self.options.bundle_id
1652
- or self.get_pyproject(f"tool.flet.{self.config_platform}.bundle_id")
1653
- or self.get_pyproject("tool.flet.bundle_id")
1341
+ or self.get_platform_setting("bundle_id")
1654
1342
  or f"{org_name}.{project_name_slug}",
1655
1343
  "company_name": (
1656
1344
  self.options.company_name or self.get_pyproject("tool.flet.company")
1657
1345
  ),
1658
- "copyright": self.options.copyright
1659
- or self.get_pyproject("tool.flet.copyright"),
1660
- "ios_export_method": ios_export_method,
1661
- "ios_provisioning_profile": ios_provisioning_profile,
1662
- "ios_signing_certificate": ios_signing_certificate,
1663
- "ios_export_options": ios_export_options,
1664
- "ios_team_id": ios_team_id,
1346
+ "copyright": self.get_copyright(),
1347
+ "ios_export_method": ios_signing["export_method"],
1348
+ "ios_provisioning_profile": ios_signing["provisioning_profile"],
1349
+ "ios_signing_certificate": ios_signing["signing_certificate"],
1350
+ "ios_team_id": ios_signing["team_id"],
1665
1351
  # `_` makes `_options` and `_pyproject` private cookiecutter
1666
1352
  # variables, which reach the template unchanged. Cookiecutter
1667
1353
  # renders other values as Jinja and turns them into strings.
@@ -1675,9 +1361,10 @@ class BaseBuildCommand(BaseFlutterCommand):
1675
1361
  if self.package_platform == "Android"
1676
1362
  else []
1677
1363
  ),
1678
- "info_plist": info_plist,
1679
- "macos_entitlements": macos_entitlements,
1364
+ "info_plist": self.get_info_plist(impeller),
1365
+ "macos_entitlements": self.get_macos_entitlements(),
1680
1366
  "ios_entitlements": self.get_ios_entitlements(),
1367
+ "ios_export_options": ios_signing["export_options"],
1681
1368
  "android_permissions": android_permissions,
1682
1369
  "android_features": android_features,
1683
1370
  "android_meta_data": android_meta_data,
@@ -1686,12 +1373,14 @@ class BaseBuildCommand(BaseFlutterCommand):
1686
1373
  "android_gradle_dependencies": self.get_android_gradle_dependencies(),
1687
1374
  "android_proguard_rules": android_proguard_rules,
1688
1375
  "android_providers": android_providers,
1376
+ "android_application_attributes": (
1377
+ self.get_android_application_attributes(product_name)
1378
+ ),
1379
+ "android_activity": self.get_android_activity(),
1380
+ "android_queries": self.get_android_queries(),
1689
1381
  "android_receivers": self.get_android_receivers(),
1690
1382
  "android_services": self.get_android_services(),
1691
- "deep_linking": {
1692
- "scheme": deep_linking_scheme,
1693
- "host": deep_linking_host,
1694
- },
1383
+ "deep_linking": deep_linking,
1695
1384
  "android_signing": bool(
1696
1385
  self.options.android_signing_key_store
1697
1386
  or self.get_pyproject("tool.flet.android.signing.key_store")
@@ -1759,10 +1448,11 @@ class BaseBuildCommand(BaseFlutterCommand):
1759
1448
  """
1760
1449
  One splash setting, platform-specific over global.
1761
1450
 
1762
- The same precedence the splash colours use, so every key under
1763
- `[tool.flet.splash]` can be overridden per platform without each one
1764
- spelling the lookup out again. A key that was renamed is read under
1765
- its former name too, so existing configuration keeps working.
1451
+ Uses the precedence of `get_platform_setting`, so every key under
1452
+ `[tool.flet.splash]` can be overridden per platform, even with an empty
1453
+ value, without each one spelling the lookup out again. A key that was
1454
+ renamed is read under its former name too, so existing configuration
1455
+ keeps working.
1766
1456
 
1767
1457
  Args:
1768
1458
  key: Setting name below the `splash` table.
@@ -1771,14 +1461,10 @@ class BaseBuildCommand(BaseFlutterCommand):
1771
1461
  The configured value, or `None`.
1772
1462
  """
1773
1463
 
1774
- assert self.get_pyproject
1775
-
1776
1464
  for name in (key, SPLASH_KEY_ALIASES.get(key)):
1777
1465
  if name is None:
1778
1466
  continue
1779
- value = self.get_pyproject(
1780
- f"tool.flet.{self.config_platform}.splash.{name}"
1781
- ) or self.get_pyproject(f"tool.flet.splash.{name}")
1467
+ value = self.get_platform_setting(f"splash.{name}")
1782
1468
  if value is not None:
1783
1469
  return value
1784
1470
  return None
@@ -1867,6 +1553,22 @@ class BaseBuildCommand(BaseFlutterCommand):
1867
1553
  ),
1868
1554
  }
1869
1555
 
1556
+ def _clear_dart_tool_on_flutter_change(self):
1557
+ """
1558
+ Delete `.dart_tool` from the Flutter project when the required Flutter
1559
+ version differs from the one the project was last built with.
1560
+
1561
+ `dart run` reuses the build hook binaries in `.dart_tool`, and a Dart SDK
1562
+ can't load binaries compiled by a version with a different kernel format.
1563
+ A project with no recorded version counts as changed.
1564
+ """
1565
+
1566
+ hash = HashStamp(self.build_dir / ".hash" / "flutter")
1567
+ hash.update(self.required_flutter_version)
1568
+ if hash.has_changed():
1569
+ shutil.rmtree(self.flutter_dir / ".dart_tool", ignore_errors=True)
1570
+ hash.commit()
1571
+
1870
1572
  def create_flutter_project(self, second_pass=False):
1871
1573
  """
1872
1574
  Render Flutter bootstrap project from template if template inputs changed.
@@ -1886,6 +1588,16 @@ class BaseBuildCommand(BaseFlutterCommand):
1886
1588
  assert self.build_dir
1887
1589
  assert self.pubspec_path
1888
1590
 
1591
+ # A deleted extension in build/flutter-packages would make this build
1592
+ # fail before it could reinstall it: start over with a fresh project,
1593
+ # fresh packages, and regenerated icons and splash images.
1594
+ if not second_pass and self._flutter_packages_missing():
1595
+ for stamp in ("template-1", "template-2", "package", "icons", "splashes"):
1596
+ (self.build_dir / ".hash" / stamp).unlink(missing_ok=True)
1597
+
1598
+ if not second_pass:
1599
+ self._clear_dart_tool_on_flutter_change()
1600
+
1889
1601
  hash = HashStamp(
1890
1602
  self.build_dir / ".hash" / f"template-{'2' if second_pass else '1'}"
1891
1603
  )
@@ -2320,11 +2032,7 @@ class BaseBuildCommand(BaseFlutterCommand):
2320
2032
  The colour string, or `None` when nothing is configured.
2321
2033
  """
2322
2034
 
2323
- assert self.get_pyproject
2324
-
2325
- return self.get_pyproject(
2326
- f"tool.flet.{platform}.icon_background"
2327
- ) or self.get_pyproject("tool.flet.icon_background")
2035
+ return self.get_platform_setting("icon_background", platform=platform)
2328
2036
 
2329
2037
  def _resolve_icon_background(self) -> tuple[int, int, int]:
2330
2038
  """
@@ -2399,6 +2107,38 @@ class BaseBuildCommand(BaseFlutterCommand):
2399
2107
  return AssetSpec(ico_sizes=sizes)
2400
2108
  return None
2401
2109
 
2110
+ def _flutter_packages_missing(self) -> bool:
2111
+ """
2112
+ Whether the Flutter project depends on an extension that is gone.
2113
+
2114
+ The previous build's `pubspec.yaml` lists the Flutter packages of the
2115
+ app's extensions by their path in `build/flutter-packages`. If one of
2116
+ them was deleted since, resolving that `pubspec.yaml` fails, and it is
2117
+ resolved before the packages could be installed again, so the build
2118
+ can't recover on its own. The build then starts over: the Flutter
2119
+ project is rendered again, which also restores the template's icons
2120
+ and splash images, so those are generated again too.
2121
+
2122
+ Returns:
2123
+ `True` when a dependency's path is inside `build/flutter-packages`
2124
+ and has no `pubspec.yaml`.
2125
+ """
2126
+
2127
+ assert self.pubspec_path
2128
+ assert self.build_dir
2129
+
2130
+ if not os.path.exists(self.pubspec_path):
2131
+ return False
2132
+ pubspec = self.load_yaml(self.pubspec_path) or {}
2133
+ packages_dir = (self.build_dir / "flutter-packages").resolve()
2134
+ for dependency in (pubspec.get("dependencies") or {}).values():
2135
+ if not isinstance(dependency, dict) or "path" not in dependency:
2136
+ continue
2137
+ path = (Path(self.pubspec_path).parent / dependency["path"]).resolve()
2138
+ if packages_dir in path.parents and not (path / "pubspec.yaml").exists():
2139
+ return True
2140
+ return False
2141
+
2402
2142
  def _site_packages_missing(self) -> bool:
2403
2143
  """
2404
2144
  Whether any required platform package directory has no package files.
@@ -2866,17 +2606,11 @@ class BaseBuildCommand(BaseFlutterCommand):
2866
2606
  # (CLI / pyproject) is merged on top. Consumed by the serious_python_android
2867
2607
  # Gradle split during `flutter build`, so the env var is set on build_env
2868
2608
  # (see _run_flutter_command), not on the package step.
2869
- self.android_extract_packages: list[str] = []
2870
- if self.package_platform == "Android":
2871
- user_extract_packages = (
2872
- self.options.android_extract_packages
2873
- or self.get_platform_setting("extract_packages", [])
2874
- )
2875
- self.android_extract_packages = list(
2876
- dict.fromkeys(
2877
- ANDROID_DEFAULT_EXTRACT_PACKAGES + user_extract_packages
2878
- )
2879
- )
2609
+ self.android_extract_packages: list[str] = (
2610
+ self.get_android_extract_packages()
2611
+ if self.package_platform == "Android"
2612
+ else []
2613
+ )
2880
2614
 
2881
2615
  if self.get_bool_setting(self.options.compile_app, "compile.app", True):
2882
2616
  package_args.append("--compile-app")
@@ -2947,17 +2681,17 @@ class BaseBuildCommand(BaseFlutterCommand):
2947
2681
  for arg in package_args:
2948
2682
  hash.update(arg)
2949
2683
 
2950
- if not dev_packages_configured:
2951
- if not hash.has_changed() and not self._site_packages_missing():
2952
- package_args.append("--skip-site-packages")
2953
- # serious_python skips copying Flutter packages to the temp dir
2954
- # under --skip-site-packages, so register_flutter_extensions must
2955
- # keep (not wipe) the permanent flutter-packages copy from the
2956
- # previous build.
2957
- self.site_packages_skipped = True
2958
- else:
2959
- if self.flutter_packages_dir.exists():
2960
- shutil.rmtree(self.flutter_packages_dir, ignore_errors=True)
2684
+ if (
2685
+ not dev_packages_configured
2686
+ and not hash.has_changed()
2687
+ and not self._site_packages_missing()
2688
+ ):
2689
+ package_args.append("--skip-site-packages")
2690
+ # serious_python skips copying Flutter packages to the temp dir
2691
+ # under --skip-site-packages, so register_flutter_extensions must
2692
+ # keep (not wipe) the permanent flutter-packages copy from the
2693
+ # previous build.
2694
+ self.site_packages_skipped = True
2961
2695
 
2962
2696
  package_result = self.run(
2963
2697
  package_args,
@@ -3064,69 +2798,307 @@ class BaseBuildCommand(BaseFlutterCommand):
3064
2798
  else self.get_platform_setting(pyproj_setting, default_value)
3065
2799
  )
3066
2800
 
3067
- def get_deep_linking_setting(self, key: str):
2801
+ def get_deep_linking(self) -> dict:
3068
2802
  """
3069
- Resolve a deep-linking setting (`scheme` or `host`).
3070
-
3071
- On Android and iOS `[tool.flet.<platform>.deep_linking]` overrides
3072
- `[tool.flet.deep_linking]`, which is the fallback; other platforms
3073
- read only the common table. Resolved per key, so a platform table
3074
- may override just one of them.
2803
+ Resolve the deep-linking scheme and optional host.
3075
2804
 
3076
- Args:
3077
- key: `scheme` or `host`.
2805
+ The CLI options replace the project settings when a scheme is passed.
2806
+ Otherwise, on Android and iOS the platform's own deep-linking table
2807
+ overrides the common one per key, so it may set just one of them;
2808
+ other platforms read only the common table. On Android and iOS a host
2809
+ needs a scheme, and `http` and `https` need a host: without one, the
2810
+ Android app would offer to open every web link.
3078
2811
 
3079
2812
  Returns:
3080
- The configured value, or `None`.
2813
+ A table with `scheme` and `host`, each `None` when not set.
3081
2814
  """
3082
2815
 
3083
2816
  assert self.get_pyproject
2817
+ if self.options.deep_linking_host and not self.options.deep_linking_scheme:
2818
+ self.cleanup(
2819
+ 1, "--deep-linking-host needs --deep-linking-scheme to be set too."
2820
+ )
3084
2821
  platform = {"Android": "android", "iOS": "ios"}.get(self.package_platform)
2822
+ values = {}
2823
+ for key in ("scheme", "host"):
2824
+ if self.options.deep_linking_scheme:
2825
+ value = getattr(self.options, f"deep_linking_{key}")
2826
+ else:
2827
+ value = None
2828
+ if platform:
2829
+ value = self.get_pyproject(
2830
+ f"tool.flet.{platform}.deep_linking.{key}"
2831
+ )
2832
+ if value is None:
2833
+ value = self.get_pyproject(f"tool.flet.deep_linking.{key}")
2834
+ if value is not None and not isinstance(value, str):
2835
+ self.cleanup(
2836
+ 1, f"Invalid deep linking {key}: expected a string, got {value!r}."
2837
+ )
2838
+ values[key] = (value.strip() or None) if value else None
2839
+
3085
2840
  if platform:
3086
- value = self.get_pyproject(f"tool.flet.{platform}.deep_linking.{key}")
3087
- if value is not None:
3088
- return value
3089
- return self.get_pyproject(f"tool.flet.deep_linking.{key}")
2841
+ if values["host"] and not values["scheme"]:
2842
+ self.cleanup(
2843
+ 1,
2844
+ f"Deep linking host {values['host']!r} needs a scheme, "
2845
+ 'such as "myapp" or "https".',
2846
+ )
2847
+ scheme = (values["scheme"] or "").lower()
2848
+ if scheme in ("http", "https") and not values["host"]:
2849
+ self.cleanup(
2850
+ 1,
2851
+ f"Deep linking scheme {values['scheme']!r} needs a host: "
2852
+ "without one, the app would open every web link.",
2853
+ )
2854
+ return values
3090
2855
 
3091
- def get_ios_entitlements(self) -> dict:
2856
+ def get_copyright(self) -> Optional[str]:
3092
2857
  """
3093
- Resolve the iOS app's entitlements.
2858
+ Resolve the app's copyright text.
3094
2859
 
3095
- Entries of `--ios-entitlements` override those of `[tool.flet.ios.entitlement]`.
3096
- Values are written to `Runner.entitlements` with their plist types.
2860
+ Comes from `--copyright`, else `[tool.flet].copyright`.
2861
+ An explicitly empty value leaves the copyright blank.
2862
+ Without either, it's generated from the company set with
2863
+ `--company` or `[tool.flet].company`.
2864
+
2865
+ Returns:
2866
+ The copyright text, or `None` to use the build template's default.
3097
2867
  """
3098
2868
  assert self.get_pyproject
3099
2869
  assert self.options
3100
- ios_entitlements = dict(self.get_pyproject("tool.flet.ios.entitlement") or {})
2870
+ if self.options.copyright is not None:
2871
+ return self.options.copyright
2872
+ copyright = self.get_pyproject("tool.flet.copyright")
2873
+ if copyright is not None:
2874
+ return copyright
2875
+ company = self.options.company_name or self.get_pyproject("tool.flet.company")
2876
+ return (
2877
+ f"Copyright © {datetime.date.today().year} {company}" if company else None
2878
+ )
3101
2879
 
3102
- # parse --ios-entitlements
3103
- for p in self.options.ios_entitlements:
3104
- i = p.find("=")
3105
- if i > -1:
3106
- ios_entitlements[p[:i]] = parse_cli_plist_value(p[i + 1 :])
3107
- else:
3108
- self.cleanup(1, f"Invalid iOS entitlement option: {p}")
2880
+ def get_info_plist(self, impeller: bool) -> dict:
2881
+ """
2882
+ Resolve the entries added to the iOS or macOS app's `Info.plist`.
3109
2883
 
3110
- for key, value in ios_entitlements.items():
3111
- if not is_supported_plist_value(value):
3112
- self.cleanup(
3113
- 1,
3114
- "Unsupported iOS entitlement value type for "
3115
- f"{key}: {type(value).__name__}. Supported types are "
3116
- "string, boolean, integer, float, dictionary, and arrays "
3117
- "containing those values.",
3118
- )
3119
- return ios_entitlements
2884
+ Entries of `--info-plist` override those of `[tool.flet.ios.info]` or
2885
+ `[tool.flet.macos.info]`, which override those of the permission bundles.
3120
2886
 
3121
- def get_android_compile_options(self) -> dict[str, str]:
3122
- """Merge Android compiler expressions over installed extensions' and
3123
- Flet's Java 17 defaults.
2887
+ Args:
2888
+ impeller: Whether the app uses Impeller. When it doesn't, macOS apps
2889
+ get `FLTEnableImpeller = false`; iOS has no such switch.
3124
2890
 
3125
- Keys are Gradle property identifiers; values are Kotlin expressions
3126
- rendered verbatim inside `android.compileOptions`.
2891
+ Returns:
2892
+ The entries, with their plist value types.
3127
2893
  """
3128
2894
  assert self.get_pyproject
3129
- setting = "tool.flet.android.compile_options"
2895
+ assert self.options
2896
+ info_plist = (
2897
+ {"FLTEnableImpeller": False}
2898
+ if self.package_platform == "Darwin" and not impeller
2899
+ else {}
2900
+ )
2901
+
2902
+ # merge values from "--permissions" arg:
2903
+ for p in self.resolve_permissions():
2904
+ if p in CROSS_PLATFORM_PERMISSIONS:
2905
+ permission_config = CROSS_PLATFORM_PERMISSIONS[p]
2906
+ info_plist.update(
2907
+ permission_config.get(f"{self.config_platform}_info_plist", {})
2908
+ or permission_config.get("info_plist", {})
2909
+ )
2910
+
2911
+ info_plist = merge_dict(
2912
+ info_plist,
2913
+ (
2914
+ self.get_pyproject("tool.flet.macos.info")
2915
+ if self.package_platform == "Darwin"
2916
+ else self.get_pyproject("tool.flet.ios.info")
2917
+ )
2918
+ or {},
2919
+ )
2920
+
2921
+ # parse --info-plist
2922
+ for p in self.options.info_plist:
2923
+ i = p.find("=")
2924
+ if i > -1:
2925
+ k = p[:i]
2926
+ v = p[i + 1 :]
2927
+ info_plist[k] = parse_cli_plist_value(v)
2928
+ else:
2929
+ self.cleanup(1, f"Invalid Info.plist option: {p}")
2930
+
2931
+ for key, value in info_plist.items():
2932
+ if not is_supported_plist_value(value):
2933
+ self.cleanup(
2934
+ 1,
2935
+ "Unsupported Info.plist value type for "
2936
+ f"{key}: {type(value).__name__}. Supported types are "
2937
+ "string, boolean, integer, float, dictionary, and arrays "
2938
+ "containing those values.",
2939
+ )
2940
+ return info_plist
2941
+
2942
+ def get_macos_entitlements(self) -> dict:
2943
+ """
2944
+ Resolve the macOS app's entitlements.
2945
+
2946
+ Entries of `--macos-entitlements` override those of
2947
+ `[tool.flet.macos.entitlement]`, which override those of the permission
2948
+ bundles and Flet's defaults.
2949
+
2950
+ Returns:
2951
+ The entitlements, with their plist value types.
2952
+ """
2953
+ assert self.get_pyproject
2954
+ assert self.options
2955
+ macos_entitlements = {
2956
+ "com.apple.security.app-sandbox": False,
2957
+ "com.apple.security.cs.allow-jit": True,
2958
+ "com.apple.security.cs.allow-unsigned-executable-memory": True,
2959
+ "com.apple.security.network.client": True,
2960
+ "com.apple.security.network.server": True,
2961
+ "com.apple.security.files.user-selected.read-write": True,
2962
+ }
2963
+
2964
+ # merge values from "--permissions" arg:
2965
+ for p in self.resolve_permissions():
2966
+ if p in CROSS_PLATFORM_PERMISSIONS:
2967
+ macos_entitlements.update(
2968
+ CROSS_PLATFORM_PERMISSIONS[p]["macos_entitlements"]
2969
+ )
2970
+
2971
+ macos_entitlements = merge_dict(
2972
+ macos_entitlements,
2973
+ self.get_pyproject("tool.flet.macos.entitlement") or {},
2974
+ )
2975
+
2976
+ # parse --macos-entitlements
2977
+ for p in self.options.macos_entitlements:
2978
+ i = p.find("=")
2979
+ if i > -1:
2980
+ macos_entitlements[p[:i]] = parse_cli_plist_value(p[i + 1 :])
2981
+ else:
2982
+ self.cleanup(1, f"Invalid macOS entitlement option: {p}")
2983
+
2984
+ for key, value in macos_entitlements.items():
2985
+ if not is_supported_plist_value(value):
2986
+ self.cleanup(
2987
+ 1,
2988
+ "Unsupported macOS entitlement value type for "
2989
+ f"{key}: {type(value).__name__}. Supported types are "
2990
+ "string, boolean, integer, float, dictionary, and arrays "
2991
+ "containing those values.",
2992
+ )
2993
+ return macos_entitlements
2994
+
2995
+ def get_ios_signing(self) -> dict:
2996
+ """
2997
+ Resolve how the iOS app is signed and exported.
2998
+
2999
+ The export method comes from `--ios-export-method`, else
3000
+ `[tool.flet.ios].export_method`, else `debugging`. Each other setting comes
3001
+ from its CLI option if it has one, else the table of that export method
3002
+ under `[tool.flet.ios.export_methods]`, else `[tool.flet.ios]`.
3003
+
3004
+ Returns:
3005
+ A table with `export_method`, `provisioning_profile`,
3006
+ `signing_certificate`, `team_id` and `export_options`.
3007
+ """
3008
+ assert self.get_pyproject
3009
+ assert self.options
3010
+ export_method = (
3011
+ self.options.ios_export_method
3012
+ or self.get_pyproject("tool.flet.ios.export_method")
3013
+ or "debugging"
3014
+ )
3015
+
3016
+ export_method_opts = (
3017
+ self.get_pyproject("tool.flet.ios.export_methods").get(export_method)
3018
+ if self.get_pyproject("tool.flet.ios.export_methods")
3019
+ else {}
3020
+ ) or {}
3021
+
3022
+ export_options = (
3023
+ export_method_opts.get("export_options")
3024
+ or self.get_pyproject("tool.flet.ios.export_options")
3025
+ or {}
3026
+ )
3027
+ if not isinstance(export_options, dict):
3028
+ self.cleanup(
3029
+ 1,
3030
+ "Invalid iOS export options: expected a table, "
3031
+ f"got {export_options!r}.",
3032
+ )
3033
+ for key, value in export_options.items():
3034
+ if not is_supported_plist_value(value):
3035
+ self.cleanup(
3036
+ 1,
3037
+ "Unsupported iOS export option value type for "
3038
+ f"{key}: {type(value).__name__}. Supported types are "
3039
+ "string, boolean, integer, float, dictionary, and arrays "
3040
+ "containing those values.",
3041
+ )
3042
+
3043
+ return {
3044
+ "export_method": export_method,
3045
+ "provisioning_profile": (
3046
+ self.options.ios_provisioning_profile
3047
+ or export_method_opts.get("provisioning_profile")
3048
+ or self.get_pyproject("tool.flet.ios.provisioning_profile")
3049
+ ),
3050
+ "signing_certificate": (
3051
+ self.options.ios_signing_certificate
3052
+ or export_method_opts.get("signing_certificate")
3053
+ or self.get_pyproject("tool.flet.ios.signing_certificate")
3054
+ ),
3055
+ "team_id": (
3056
+ self.options.ios_team_id
3057
+ or export_method_opts.get("team_id")
3058
+ or self.get_pyproject("tool.flet.ios.team_id")
3059
+ ),
3060
+ "export_options": export_options,
3061
+ }
3062
+
3063
+ def get_ios_entitlements(self) -> dict:
3064
+ """
3065
+ Resolve the iOS app's entitlements.
3066
+
3067
+ Entries of `--ios-entitlements` override those of `[tool.flet.ios.entitlement]`.
3068
+ Values are written to `Runner.entitlements` with their plist types.
3069
+ """
3070
+ assert self.get_pyproject
3071
+ assert self.options
3072
+ ios_entitlements = dict(self.get_pyproject("tool.flet.ios.entitlement") or {})
3073
+
3074
+ # parse --ios-entitlements
3075
+ for p in self.options.ios_entitlements:
3076
+ i = p.find("=")
3077
+ if i > -1:
3078
+ ios_entitlements[p[:i]] = parse_cli_plist_value(p[i + 1 :])
3079
+ else:
3080
+ self.cleanup(1, f"Invalid iOS entitlement option: {p}")
3081
+
3082
+ for key, value in ios_entitlements.items():
3083
+ if not is_supported_plist_value(value):
3084
+ self.cleanup(
3085
+ 1,
3086
+ "Unsupported iOS entitlement value type for "
3087
+ f"{key}: {type(value).__name__}. Supported types are "
3088
+ "string, boolean, integer, float, dictionary, and arrays "
3089
+ "containing those values.",
3090
+ )
3091
+ return ios_entitlements
3092
+
3093
+ def get_android_compile_options(self) -> dict[str, str]:
3094
+ """Merge Android compiler expressions over installed extensions' and
3095
+ Flet's Java 17 defaults.
3096
+
3097
+ Keys are Gradle property identifiers; values are Kotlin expressions
3098
+ rendered verbatim inside `android.compileOptions`.
3099
+ """
3100
+ assert self.get_pyproject
3101
+ setting = "tool.flet.android.compile_options"
3130
3102
  try:
3131
3103
  configured = merge_compile_options(
3132
3104
  self.get_pyproject(setting), self.extensions
@@ -3174,6 +3146,405 @@ class BaseBuildCommand(BaseFlutterCommand):
3174
3146
  )
3175
3147
  return textwrap.dedent(configured).strip()
3176
3148
 
3149
+ def get_android_application_attributes(self, product_name: str) -> dict:
3150
+ """Resolve the manifest's `<application>` attributes: Flet's defaults with
3151
+ the app's own attributes on top."""
3152
+ assert self.get_pyproject
3153
+ try:
3154
+ return normalize_android_application_attributes(
3155
+ self.get_pyproject("tool.flet.android.manifest_application"),
3156
+ product_name,
3157
+ )
3158
+ except ValueError as exc:
3159
+ self.cleanup(1, str(exc))
3160
+
3161
+ def get_android_permissions(self) -> dict:
3162
+ """
3163
+ Resolve the app's `<uses-permission>` entries.
3164
+
3165
+ `INTERNET` is on by default. The cross-platform permission bundles,
3166
+ the project settings and then the CLI options are applied on top; a
3167
+ value of `False` removes the permission, even one a plugin adds.
3168
+
3169
+ Returns:
3170
+ Permission names mapped to `True`, `False`, or a table of extra
3171
+ attributes.
3172
+ """
3173
+
3174
+ assert self.get_pyproject
3175
+ android_permissions = {"android.permission.INTERNET": True}
3176
+ for p in self.resolve_permissions():
3177
+ if p in CROSS_PLATFORM_PERMISSIONS:
3178
+ android_permissions.update(
3179
+ CROSS_PLATFORM_PERMISSIONS[p]["android_permissions"]
3180
+ )
3181
+ android_permissions = merge_dict(
3182
+ android_permissions,
3183
+ self.get_pyproject("tool.flet.android.permission") or {},
3184
+ )
3185
+
3186
+ # parse --android-permissions
3187
+ for p in self.options.android_permissions:
3188
+ i = p.find("=")
3189
+ if i > -1:
3190
+ try:
3191
+ android_permissions[p[:i]] = parse_cli_bool_value(p[i + 1 :])
3192
+ except ValueError:
3193
+ self.cleanup(
3194
+ 1,
3195
+ f"Invalid Android permission option value for {p[:i]}: "
3196
+ f"{p[i + 1 :]}. Expected true or false.",
3197
+ )
3198
+ else:
3199
+ self.cleanup(1, f"Invalid Android permission option: {p}")
3200
+
3201
+ for key, value in android_permissions.items():
3202
+ if isinstance(value, bool):
3203
+ continue
3204
+ if isinstance(value, dict):
3205
+ for ak, av in value.items():
3206
+ if not isinstance(av, (str, bool, int, float)):
3207
+ self.cleanup(
3208
+ 1,
3209
+ f"Invalid Android permission attribute value for "
3210
+ f"{key}.{ak}: {type(av).__name__}. "
3211
+ "Expected string, boolean, or number.",
3212
+ )
3213
+ continue
3214
+ self.cleanup(
3215
+ 1,
3216
+ f"Invalid Android permission value for {key}: "
3217
+ f"{type(value).__name__}. Expected boolean or inline table.",
3218
+ )
3219
+ return android_permissions
3220
+
3221
+ def get_android_features(self) -> dict:
3222
+ """
3223
+ Resolve the app's `<uses-feature>` entries.
3224
+
3225
+ Leanback and touchscreen are declared as not required by default, so
3226
+ the app installs on TVs and devices without a touchscreen. The
3227
+ cross-platform permission bundles, the project settings and then the
3228
+ CLI options are applied on top.
3229
+
3230
+ Returns:
3231
+ Feature names mapped to whether the feature is required.
3232
+ """
3233
+
3234
+ assert self.get_pyproject
3235
+ android_features = {
3236
+ "android.software.leanback": False,
3237
+ "android.hardware.touchscreen": False,
3238
+ }
3239
+ for p in self.resolve_permissions():
3240
+ if p in CROSS_PLATFORM_PERMISSIONS:
3241
+ android_features.update(
3242
+ CROSS_PLATFORM_PERMISSIONS[p]["android_features"]
3243
+ )
3244
+ android_features = merge_dict(
3245
+ android_features,
3246
+ self.get_pyproject("tool.flet.android.feature") or {},
3247
+ )
3248
+
3249
+ # parse --android-features
3250
+ for p in self.options.android_features:
3251
+ i = p.find("=")
3252
+ if i > -1:
3253
+ try:
3254
+ android_features[p[:i]] = parse_cli_bool_value(p[i + 1 :])
3255
+ except ValueError:
3256
+ self.cleanup(
3257
+ 1,
3258
+ f"Invalid Android feature option value for {p[:i]}: "
3259
+ f"{p[i + 1 :]}. Expected true or false.",
3260
+ )
3261
+ else:
3262
+ self.cleanup(1, f"Invalid Android feature option: {p}")
3263
+ return android_features
3264
+
3265
+ def get_android_meta_data(self, impeller: bool) -> dict:
3266
+ """
3267
+ Resolve the `<meta-data>` entries of the app's `<application>`.
3268
+
3269
+ Without Impeller, `io.flutter.embedding.android.EnableImpeller` is set
3270
+ to `"false"`; the project settings and then the CLI options are
3271
+ applied on top and may override it.
3272
+
3273
+ Args:
3274
+ impeller: Whether the app is built with the Impeller renderer.
3275
+
3276
+ Returns:
3277
+ Meta-data names mapped to their values.
3278
+ """
3279
+
3280
+ assert self.get_pyproject
3281
+ android_meta_data = (
3282
+ {"io.flutter.embedding.android.EnableImpeller": "false"}
3283
+ if not impeller
3284
+ else {}
3285
+ )
3286
+ android_meta_data = merge_dict(
3287
+ android_meta_data,
3288
+ self.get_pyproject("tool.flet.android.meta_data") or {},
3289
+ )
3290
+
3291
+ # parse --android-meta-data
3292
+ for p in self.options.android_meta_data:
3293
+ i = p.find("=")
3294
+ if i > -1:
3295
+ android_meta_data[p[:i]] = p[i + 1 :]
3296
+ else:
3297
+ self.cleanup(1, f"Invalid Android meta-data option: {p}")
3298
+ return android_meta_data
3299
+
3300
+ def get_android_providers(self) -> dict:
3301
+ """
3302
+ Resolve the app's own `<provider>` entries from project settings.
3303
+
3304
+ A provider set to `False` or an empty table is skipped. Booleans are
3305
+ written as lowercase `true` or `false`.
3306
+
3307
+ Returns:
3308
+ Provider class names mapped to their attributes, with an optional
3309
+ `meta_data` table.
3310
+ """
3311
+
3312
+ assert self.get_pyproject
3313
+ android_providers = merge_dict(
3314
+ {}, self.get_pyproject("tool.flet.android.provider") or {}
3315
+ )
3316
+
3317
+ def _xml_attr_value(v):
3318
+ # Android XML expects lowercase booleans.
3319
+ if isinstance(v, bool):
3320
+ return "true" if v else "false"
3321
+ return v
3322
+
3323
+ normalized_providers = {}
3324
+ for key, value in android_providers.items():
3325
+ if value is False or value == {}:
3326
+ continue
3327
+ if value is True:
3328
+ self.cleanup(
3329
+ 1,
3330
+ f"Invalid Android provider value for {key}: 'true' is not "
3331
+ "supported. Use an inline table of attributes, or 'false' "
3332
+ "to skip.",
3333
+ )
3334
+ if not isinstance(value, dict):
3335
+ self.cleanup(
3336
+ 1,
3337
+ f"Invalid Android provider value for {key}: "
3338
+ f"{type(value).__name__}. Expected boolean or inline table.",
3339
+ )
3340
+ normalized = {}
3341
+ for ak, av in value.items():
3342
+ if ak == "name":
3343
+ self.cleanup(
3344
+ 1,
3345
+ f"Invalid Android provider attribute for {key}: "
3346
+ "'name' is reserved and is taken from the table key.",
3347
+ )
3348
+ if ak == "meta_data":
3349
+ if not isinstance(av, dict):
3350
+ self.cleanup(
3351
+ 1,
3352
+ f"Invalid Android provider meta_data for {key}: "
3353
+ f"{type(av).__name__}. Expected inline table.",
3354
+ )
3355
+ normalized_meta = {}
3356
+ for mk, mv in av.items():
3357
+ if isinstance(mv, (str, bool, int, float)):
3358
+ normalized_meta[mk] = _xml_attr_value(mv)
3359
+ continue
3360
+ if isinstance(mv, dict):
3361
+ normalized_attrs = {}
3362
+ for attr_key, attr_value in mv.items():
3363
+ if not isinstance(attr_value, (str, bool, int, float)):
3364
+ self.cleanup(
3365
+ 1,
3366
+ f"Invalid Android provider meta-data "
3367
+ f"attribute value for "
3368
+ f"{key}.meta_data.{mk}.{attr_key}: "
3369
+ f"{type(attr_value).__name__}. "
3370
+ "Expected string, boolean, or number.",
3371
+ )
3372
+ normalized_attrs[attr_key] = _xml_attr_value(attr_value)
3373
+ normalized_meta[mk] = normalized_attrs
3374
+ continue
3375
+ self.cleanup(
3376
+ 1,
3377
+ f"Invalid Android provider meta-data value for "
3378
+ f"{key}.meta_data.{mk}: {type(mv).__name__}. "
3379
+ "Expected string, boolean, number, or inline table.",
3380
+ )
3381
+ normalized["meta_data"] = normalized_meta
3382
+ continue
3383
+ if not isinstance(av, (str, bool, int, float)):
3384
+ self.cleanup(
3385
+ 1,
3386
+ f"Invalid Android provider attribute value for "
3387
+ f"{key}.{ak}: {type(av).__name__}. "
3388
+ "Expected string, boolean, or number.",
3389
+ )
3390
+ normalized[ak] = _xml_attr_value(av)
3391
+ normalized_providers[key] = normalized
3392
+ return normalized_providers
3393
+
3394
+ def get_android_gradle_properties(self) -> dict:
3395
+ """
3396
+ Resolve the generated Android project's `gradle.properties`.
3397
+
3398
+ The defaults reproduce the file the template used to hardcode; project
3399
+ settings override any entry or add new ones. The memory settings in
3400
+ particular are too large for some CI runners (a standard GitHub-hosted
3401
+ runner has about 7 GB of RAM, less than `-Xmx8G` alone).
3402
+ `kotlin.incremental` is off because Kotlin's incremental compiler
3403
+ stores plugin sources relative to the Android project and fails the
3404
+ build when they sit on another Windows drive, e.g. the pub cache on
3405
+ `C:` and the app on `D:`.
3406
+
3407
+ Returns:
3408
+ Property names mapped to their values.
3409
+ """
3410
+
3411
+ assert self.get_pyproject
3412
+ return merge_dict(
3413
+ {
3414
+ "org.gradle.jvmargs": (
3415
+ "-Xmx8G -XX:MaxMetaspaceSize=4G "
3416
+ "-XX:ReservedCodeCacheSize=512m -XX:+HeapDumpOnOutOfMemoryError"
3417
+ ),
3418
+ "android.useAndroidX": "true",
3419
+ "kotlin.incremental": "false",
3420
+ },
3421
+ self.get_pyproject("tool.flet.android.gradle_properties") or {},
3422
+ )
3423
+
3424
+ def get_android_proguard_rules(self) -> list[str]:
3425
+ """
3426
+ Resolve the generated Android project's ProGuard/R8 rules.
3427
+
3428
+ R8 renames classes in release builds while pyjnius resolves them by
3429
+ name, so an app that reaches into a bundled AAR needs keep rules. The
3430
+ project's rules are appended to the defaults, since R8 has no directive
3431
+ that undoes a keep; `proguard_default_rules = false` drops the
3432
+ defaults, the only way to shed `-keepnames class * { *; }`. Keeping
3433
+ the two settings separate stops users from copying today's defaults
3434
+ into `pyproject.toml` and silently keeping them after they change.
3435
+
3436
+ Returns:
3437
+ The rules, one per line of `proguard-rules.pro`.
3438
+ """
3439
+
3440
+ assert self.get_pyproject
3441
+ keep_defaults = (
3442
+ self.get_pyproject("tool.flet.android.proguard_default_rules") is not False
3443
+ )
3444
+ defaults = (
3445
+ [
3446
+ "-keep class com.flet.serious_python_android.** { *; }",
3447
+ "-keepnames class * { *; }",
3448
+ ]
3449
+ if keep_defaults
3450
+ else []
3451
+ )
3452
+ return defaults + [
3453
+ str(rule)
3454
+ for rule in (self.get_pyproject("tool.flet.android.proguard_rules") or [])
3455
+ ]
3456
+
3457
+ def get_android_signing_env(self) -> dict:
3458
+ """
3459
+ Resolve the environment variables that sign the Android build.
3460
+
3461
+ The key store comes from the CLI option, the project settings or the
3462
+ `FLET_ANDROID_SIGNING_KEY_STORE` environment variable. The passwords
3463
+ come from the CLI options or their environment variables only, never
3464
+ from `pyproject.toml`; when just one of them is given, it is used for
3465
+ both. The key alias, `upload` by default, is set only with a key store.
3466
+
3467
+ Returns:
3468
+ The `FLET_ANDROID_SIGNING_*` variables to pass to the build.
3469
+ """
3470
+
3471
+ assert self.get_pyproject
3472
+ env = {}
3473
+ key_store = (
3474
+ self.options.android_signing_key_store
3475
+ or self.get_pyproject("tool.flet.android.signing.key_store")
3476
+ or os.getenv("FLET_ANDROID_SIGNING_KEY_STORE")
3477
+ )
3478
+ if key_store:
3479
+ env["FLET_ANDROID_SIGNING_KEY_STORE"] = key_store
3480
+
3481
+ key_store_password = (
3482
+ self.options.android_signing_key_store_password
3483
+ or os.getenv("FLET_ANDROID_SIGNING_KEY_STORE_PASSWORD")
3484
+ )
3485
+ key_password = self.options.android_signing_key_password or os.getenv(
3486
+ "FLET_ANDROID_SIGNING_KEY_PASSWORD"
3487
+ )
3488
+ if key_store_password or key_password:
3489
+ env["FLET_ANDROID_SIGNING_KEY_STORE_PASSWORD"] = (
3490
+ key_store_password if key_store_password else key_password
3491
+ )
3492
+ env["FLET_ANDROID_SIGNING_KEY_PASSWORD"] = (
3493
+ key_password if key_password else key_store_password
3494
+ )
3495
+
3496
+ if key_store:
3497
+ env["FLET_ANDROID_SIGNING_KEY_ALIAS"] = (
3498
+ self.options.android_signing_key_alias
3499
+ or self.get_pyproject("tool.flet.android.signing.key_alias")
3500
+ or os.getenv("FLET_ANDROID_SIGNING_KEY_ALIAS")
3501
+ or "upload"
3502
+ )
3503
+ return env
3504
+
3505
+ def get_android_extract_packages(self) -> list[str]:
3506
+ """
3507
+ Resolve the Python packages shipped extracted to disk on Android
3508
+ instead of in the zip Python imports from, for packages that read
3509
+ their data through a real file path.
3510
+
3511
+ Flet's defaults come first, followed by the CLI option or else the
3512
+ project settings; duplicates are dropped.
3513
+
3514
+ Returns:
3515
+ Package names, in order.
3516
+ """
3517
+
3518
+ user_extract_packages = (
3519
+ self.options.android_extract_packages
3520
+ or self.get_platform_setting("extract_packages", [])
3521
+ )
3522
+ return list(
3523
+ dict.fromkeys(ANDROID_DEFAULT_EXTRACT_PACKAGES + user_extract_packages)
3524
+ )
3525
+
3526
+ def get_android_activity(self) -> dict:
3527
+ """Resolve what the app adds to its main activity, such as intent
3528
+ filters, from project settings."""
3529
+ assert self.get_pyproject
3530
+ try:
3531
+ return normalize_android_activity(
3532
+ self.get_pyproject("tool.flet.android.activity")
3533
+ )
3534
+ except ValueError as exc:
3535
+ self.cleanup(1, str(exc))
3536
+
3537
+ def get_android_queries(self) -> dict:
3538
+ """Resolve the apps, intents, and providers declared in the manifest's
3539
+ `<queries>` from project settings."""
3540
+ assert self.get_pyproject
3541
+ try:
3542
+ return normalize_android_queries(
3543
+ self.get_pyproject("tool.flet.android.queries")
3544
+ )
3545
+ except ValueError as exc:
3546
+ self.cleanup(1, str(exc))
3547
+
3177
3548
  def get_android_receivers(self) -> dict:
3178
3549
  """Resolve Android manifest receiver declarations from project settings."""
3179
3550
  assert self.get_pyproject
@@ -3287,18 +3658,20 @@ class BaseBuildCommand(BaseFlutterCommand):
3287
3658
  self.options.permissions or self.get_platform_setting("permissions") or []
3288
3659
  )
3289
3660
 
3290
- def get_platform_setting(self, pyproj_setting, default_value=None):
3661
+ def get_platform_setting(self, pyproj_setting, default_value=None, platform=None):
3291
3662
  """
3292
3663
  Resolve a pyproject setting with precedence: platform, global, default.
3293
3664
 
3294
- The platform value wins whenever it is set, even when it is empty, so
3295
- `[]` or `{}` under `tool.flet.<platform>.` clears a global list or table
3296
- for that platform.
3665
+ The platform value wins whenever it is set, even when it is empty or
3666
+ false, so `[]`, `{}` or `""` under `tool.flet.<platform>.` clears a
3667
+ global value for that platform.
3297
3668
 
3298
3669
  Args:
3299
3670
  pyproj_setting: Relative key under `tool.flet.<platform>.` and
3300
3671
  `tool.flet.`.
3301
3672
  default_value: Fallback value when neither key is defined.
3673
+ platform: Platform whose table overrides the global one. Defaults
3674
+ to the platform being built.
3302
3675
 
3303
3676
  Returns:
3304
3677
  Resolved setting value.
@@ -3306,7 +3679,7 @@ class BaseBuildCommand(BaseFlutterCommand):
3306
3679
 
3307
3680
  assert self.get_pyproject
3308
3681
  for key in (
3309
- f"tool.flet.{self.config_platform}.{pyproj_setting}",
3682
+ f"tool.flet.{platform or self.config_platform}.{pyproj_setting}",
3310
3683
  f"tool.flet.{pyproj_setting}",
3311
3684
  ):
3312
3685
  value = self.get_pyproject(key)
@@ -3423,37 +3796,7 @@ class BaseBuildCommand(BaseFlutterCommand):
3423
3796
  if self.package_platform == "Emscripten" and self.build_wasm():
3424
3797
  build_args.append("--wasm")
3425
3798
 
3426
- android_signing_key_store = (
3427
- self.options.android_signing_key_store
3428
- or self.get_pyproject("tool.flet.android.signing.key_store")
3429
- or os.getenv("FLET_ANDROID_SIGNING_KEY_STORE")
3430
- )
3431
- if android_signing_key_store:
3432
- build_env["FLET_ANDROID_SIGNING_KEY_STORE"] = android_signing_key_store
3433
-
3434
- key_store_password = (
3435
- self.options.android_signing_key_store_password
3436
- or os.getenv("FLET_ANDROID_SIGNING_KEY_STORE_PASSWORD")
3437
- )
3438
- key_password = self.options.android_signing_key_password or os.getenv(
3439
- "FLET_ANDROID_SIGNING_KEY_PASSWORD"
3440
- )
3441
- if key_store_password or key_password:
3442
- build_env["FLET_ANDROID_SIGNING_KEY_STORE_PASSWORD"] = (
3443
- key_store_password if key_store_password else key_password
3444
- )
3445
- build_env["FLET_ANDROID_SIGNING_KEY_PASSWORD"] = (
3446
- key_password if key_password else key_store_password
3447
- )
3448
-
3449
- if android_signing_key_store:
3450
- android_signing_key_alias = (
3451
- self.options.android_signing_key_alias
3452
- or self.get_pyproject("tool.flet.android.signing.key_alias")
3453
- or os.getenv("FLET_ANDROID_SIGNING_KEY_ALIAS")
3454
- or "upload"
3455
- )
3456
- build_env["FLET_ANDROID_SIGNING_KEY_ALIAS"] = android_signing_key_alias
3799
+ build_env.update(self.get_android_signing_env())
3457
3800
 
3458
3801
  flutter_build_args = (
3459
3802
  self.options.flutter_build_args