diff --git a/packages/flutter_tools/lib/src/cmake.dart b/packages/flutter_tools/lib/src/cmake.dart index 9ad626e52f..63b8b7a689 100644 --- a/packages/flutter_tools/lib/src/cmake.dart +++ b/packages/flutter_tools/lib/src/cmake.dart @@ -63,10 +63,10 @@ list(APPEND FLUTTER_TOOL_ENVIRONMENT "FLUTTER_ROOT=$escapedFlutterRoot" "PROJECT_DIR=$escapedProjectDir" '''); - for (final String key in environment.keys) { - final String value = _escapeBackslashes(environment[key]); - buffer.writeln(' "$key=$value"'); - } + environment.forEach((String key, String value) { + final String configValue = _escapeBackslashes(value); + buffer.writeln(' "$key=$configValue"'); + }); buffer.writeln(')'); project.generatedCmakeConfigFile diff --git a/packages/flutter_tools/lib/src/flutter_plugins.dart b/packages/flutter_tools/lib/src/flutter_plugins.dart index e805b3caee..9cc786807b 100644 --- a/packages/flutter_tools/lib/src/flutter_plugins.dart +++ b/packages/flutter_tools/lib/src/flutter_plugins.dart @@ -1107,7 +1107,8 @@ List resolvePlatformImplementation( continue; } // The plugin doesn't implement an interface, verify that it has a default implementation. - if (plugin.implementsPackage == null || plugin.implementsPackage.isEmpty) { + final String implementsPackage = plugin.implementsPackage; + if (implementsPackage == null || implementsPackage.isEmpty) { final String defaultImplementation = plugin.defaultPackagePlatforms[platform]; if (defaultImplementation == null) { if (throwOnPluginPubspecError) { @@ -1138,7 +1139,7 @@ List resolvePlatformImplementation( plugin.pluginDartClassPlatforms[platform] == 'none') { continue; } - final String resolutionKey = '$platform/${plugin.implementsPackage}'; + final String resolutionKey = '$platform/$implementsPackage'; if (directDependencyResolutions.containsKey(resolutionKey)) { final PluginInterfaceResolution currResolution = directDependencyResolutions[resolutionKey]; if (currResolution != null && currResolution.plugin.isDirectDependency) { @@ -1200,12 +1201,12 @@ Future generateMainDartWithPluginRegistrant( String currentMainUri, File newMainDart, File mainFile, { - bool throwOnPluginPubspecError, + bool throwOnPluginPubspecError = false, }) async { final List plugins = await findPlugins(rootProject); final List resolutions = resolvePlatformImplementation( plugins, - throwOnPluginPubspecError: throwOnPluginPubspecError ?? false, + throwOnPluginPubspecError: throwOnPluginPubspecError, ); final LanguageVersion entrypointVersion = determineLanguageVersion( mainFile, diff --git a/packages/flutter_tools/lib/src/project.dart b/packages/flutter_tools/lib/src/project.dart index 3dbaf395d0..064905a908 100644 --- a/packages/flutter_tools/lib/src/project.dart +++ b/packages/flutter_tools/lib/src/project.dart @@ -120,24 +120,40 @@ class FlutterProject { /// part of iOS product bundle identifier, Android application ID, or /// Gradle group ID. Future> get organizationNames async { - final List candidates = [ + final List candidates = []; + + if (ios.existsSync()) { // Don't require iOS build info, this method is only // used during create as best-effort, use the // default target bundle identifier. - if (ios.existsSync()) - await ios.productBundleIdentifier(null), - if (android.existsSync()) ...[ - android.applicationId, - android.group, - ], - if (example.android.existsSync()) - example.android.applicationId, - if (example.ios.existsSync()) - await example.ios.productBundleIdentifier(null), - ]; - return Set.of(candidates - .map(_organizationNameFromPackageName) - .where((String name) => name != null)); + final String bundleIdentifier = await ios.productBundleIdentifier(null); + if (bundleIdentifier != null) { + candidates.add(bundleIdentifier); + } + } + if (android.existsSync()) { + final String applicationId = android.applicationId; + final String group = android.group; + candidates.addAll([ + if (applicationId != null) + applicationId, + if (group != null) + group, + ]); + } + if (example.android.existsSync()) { + final String applicationId = example.android.applicationId; + if (applicationId != null) { + candidates.add(applicationId); + } + } + if (example.ios.existsSync()) { + final String bundleIdentifier = await example.ios.productBundleIdentifier(null); + if (bundleIdentifier != null) { + candidates.add(bundleIdentifier); + } + } + return Set.of(candidates.map(_organizationNameFromPackageName).whereType()); } String _organizationNameFromPackageName(String packageName) { @@ -334,10 +350,14 @@ class FlutterProject { /// Returns a json encoded string containing the [appName], [version], and [buildNumber] that is used to generate version.json String getVersionInfo() { + final String buildName = manifest.buildName; + final String buildNumber = manifest.buildNumber; final Map versionFileJson = { 'app_name': manifest.appName, - 'version': manifest.buildName, - 'build_number': manifest.buildNumber + if (buildName != null) + 'version': buildName, + if (buildNumber != null) + 'build_number': buildNumber, }; return jsonEncode(versionFileJson); } @@ -613,25 +633,33 @@ class IosProject extends FlutterProjectPlatform implements XcodeBasedProject { scheme, ); final XcodeProjectBuildContext buildContext = XcodeProjectBuildContext(environmentType: environmentType, scheme: scheme, configuration: configuration); - return _buildSettingsByBuildContext[buildContext] ??= await _xcodeProjectBuildSettings(buildContext); + if (_buildSettingsByBuildContext[buildContext] == null) { + final Map calculatedBuildSettings = await _xcodeProjectBuildSettings(buildContext); + if (calculatedBuildSettings != null) { + _buildSettingsByBuildContext[buildContext] = calculatedBuildSettings; + } + } + return _buildSettingsByBuildContext[buildContext]; } final Map> _buildSettingsByBuildContext = >{}; Future projectInfo() async { - if (!xcodeProject.existsSync() || !globals.xcodeProjectInterpreter.isInstalled) { + final XcodeProjectInterpreter xcodeProjectInterpreter = globals.xcodeProjectInterpreter; + if (!xcodeProject.existsSync() || xcodeProjectInterpreter == null || !xcodeProjectInterpreter.isInstalled) { return null; } - return _projectInfo ??= await globals.xcodeProjectInterpreter.getInfo(hostAppRoot.path); + return _projectInfo ??= await xcodeProjectInterpreter.getInfo(hostAppRoot.path); } XcodeProjectInfo _projectInfo; Future> _xcodeProjectBuildSettings(XcodeProjectBuildContext buildContext) async { - if (!globals.xcodeProjectInterpreter.isInstalled) { + final XcodeProjectInterpreter xcodeProjectInterpreter = globals.xcodeProjectInterpreter; + if (xcodeProjectInterpreter == null || !xcodeProjectInterpreter.isInstalled) { return null; } - final Map buildSettings = await globals.xcodeProjectInterpreter.getBuildSettings( + final Map buildSettings = await xcodeProjectInterpreter.getBuildSettings( xcodeProject.path, buildContext: buildContext, ); @@ -791,12 +819,13 @@ class IosProject extends FlutterProjectPlatform implements XcodeBasedProject { logger: globals.logger, templateRenderer: globals.templateRenderer, ); + final String iosBundleIdentifier = parent.manifest.iosBundleIdentifier ?? 'com.example.${parent.manifest.appName}'; template.render( target, { 'ios': true, 'projectName': parent.manifest.appName, - 'iosIdentifier': parent.manifest.iosBundleIdentifier, + 'iosIdentifier': iosBundleIdentifier, }, printStatusWhenWriting: false, overwriteExisting: true, @@ -975,12 +1004,13 @@ to migrate your project. logger: globals.logger, templateRenderer: globals.templateRenderer, ); + final String androidIdentifier = parent.manifest.androidPackage ?? 'com.example.${parent.manifest.appName}'; template.render( target, { 'android': true, 'projectName': parent.manifest.appName, - 'androidIdentifier': parent.manifest.androidPackage, + 'androidIdentifier': androidIdentifier, 'androidX': usesAndroidX, }, printStatusWhenWriting: false,