-
Notifications
You must be signed in to change notification settings - Fork 26.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Add2App] provide flag for 'build ios-framework' command to build only App.xcframework #114692
Comments
Thanks for so much detail!
We need to build the third-party pod dependencies in order to build the flutter plugins that depend on them, so even if we don't include the xcframework in the output directory, I don't think you'll be able to improve build time much. Either before or after building, it's tricky to know which are Flutter plugins and which are their dependencies to avoid making the xcframework for only the former. As you already discovered in flutter/packages/flutter_tools/lib/src/commands/build_ios_framework.dart Lines 490 to 491 in 530324d
I'm curious, did you just copy those podspecs to a known directory and then |
Hi @jmagman !
Yeah, so it makes Option 1 impossible to implement. But we don't need to build the third-party pod dependencies for the
This is exactly what I did :) I have a script,
List<dynamic> flutterParseDependenciesFileForIosPlugin(file.File flutterPluginsDependenciesFile) {
final dependenciesFile = flutterPluginsDependenciesFile.readAsStringSync();
final dependenciesHash = json.decode(dependenciesFile);
return dependenciesHash['plugins']['ios'];
} This is actually a
This logic is similar to
So this is how my
This is similar to So I have the following requirement for the host apps:
# import FlutterModule functions
require_relative 'path_to_flutter_module'
target 'YourApp' do
# reference FlutterModule pods
use_flutter_modules!
post_install do |installer|
# FlutterModule postinstall script
flutter_post_install(installer)
end
end -- def custom_flutter_install_plugin_pods(relative_root_dir)
plugins_dir = File.join(relative_root_dir, 'build', 'ios', 'framework', 'plugins')
pod 'FlutterPluginRegistrant', :path => File.join(plugins_dir, 'FlutterPluginRegistrant'), :inhibit_warnings => true
# Link Flutter plugins
plugins_file = File.expand_path('flutter-plugins-dependencies', plugins_dir)
plugin_pods = flutter_parse_dependencies_file_for_ios_plugin(plugins_file)
plugin_pods.each do |plugin_hash|
# todo: just link everything from `plugins_dir` instead of parsing 'flutter-plugins-dependencies' again
plugin_name = plugin_hash['name']
has_native_build = plugin_hash.fetch('native_build', true)
if (plugin_name && has_native_build)
plugin_path = File.join(plugins_dir, plugin_name, 'ios')
pod plugin_name, :path => plugin_path, :inhibit_warnings => true
end
end
end post install script is also similar to what we already have in You can see in the script above that it parses -- |
Hi @p-mazhnik ... we are having the same problem with DataDog SDK for iOS. Do you have some update about your solution? |
My current proposal is:
|
@p-mazhnik i followed these steps. In a real device worked fine. But in the iphone simulator e received the following errors:
So our Flutter Screens are all blanks. Some tip? |
@4rthurmonteiro my guess will be that |
I've decided to create a separate issue for the root cause #130220, and left this one as a feature request, because I want to validate and discuss my proposal with the Flutter team and make it easier for developers to find the existing issue and workarounds. |
We also need this. |
…orks from the build (#129739) A lot of details are written in the feature request: #114692. tl;dr: Options B & C from the add2app iOS guide have a limitation (build error) in case the Flutter plugin and native iOS app have a shared dependency. We can use a workaround to avoid the issue, but in this case we don't need to build frameworks for plugins. Closes #114692 Part of #130220
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
Feature request: provide flag for
flutter build ios-framework
command to build onlyApp.xcframework
or to prevent building of third-party pod dependencies as frameworks
Use case
I have a Flutter module (let's say
FlutterModule
) integrated to an iOS app (IOSApp
) using frameworks. My setup is similar to Option C from the add-to-app doc for iOS (with an improvement of embedding application and plugin frameworks to XCode automatically using CocoaPods).FlutterModule
depends on third-party Flutter plugins, some of them have iOS dependencies, e.g.sentry_flutter
which depends onSentry
pod.IOSApp
also usesCocoaPods
to add third-party iOS dependencies.The problem appears when I want to add to
IOSApp
's Podfile a dependency that reference another dependency that is referenced by Flutter plugin. This can be hard to understand, so here is the schema:IOSApp
->Pod1
->Pod2
IOSApp
->flutter_plugin.xcframework
->Pod2.xcframework
So my
IOSApp
andFlutterModule
have the same transitive platform dependency.Because
Pod2
is included twice, first throughCocoaPods
and second directly as a framework, this causes multipleRedefinition of
issues in XCode.Currently
flutter build ios-framework
command produces following outputs for the build mode:App.xcframework
(desired, compiled Dart code)Flutter.xcframework
(Flutter.podspec
in my case, if--cocoapods
flag is provided. Desired)FlutterPluginRegistrant.xcframework
(desired, registration code for plugins)flutter_plugin.xcframework
(desired, each plugin is a separate framework)Pod2.xcframework
(If plugin has dependencies in itspodspec
, frameworks will be built for each of them. Undesired:Pod2
can be also included to iOS app as a dependency, causing issues)I didn't create this as an issue because obviously I can just remove the duplicated frameworks from the Flutter command output to not include them. UPD: submit an issue #130220 because this workaround is not working for some plugins, like
datadog_flutter_plugin
But this solution is not universal. Some downsides are:
FlutterModule
I have to make sure it doesn't include CocoaPods dependency that conflicts with CocoaPods dependency ofIOSApp
. (Note thatSentry
pod wasn't the only that caused issues)FlutterModule
itself as a CocoaPods dependency to be consumed by any iOS appsflutter build ios-framework
produces frameworks that will be removed right after the creation, this has a significant impact on build time. We can speed up this command by preventing the build of undesired frameworks.Proposal
Modify
build ios-framework
command to support this use case. I thought about two options:Current solution is to build every target from
.ios/Pods/Pods.xcodeproj
(see _producePlugins function). Targets include both Flutter plugins and their pod dependencies. We can try to change this, but I am not sure if it is possible to build only selected targets without building their dependencies.Another question here is how to then easily include all of the remaining pods dependencies to app. Probably we can combine this with
--cocoapods
flag and generate anotherpodspec
with all third-party pods listed.App.xcframework
All we need to do is to prevent
_producePlugins
function from running. Inclusion of the pods dependencies to the app will be developer's responsibility and not the Flutter's (unlike in Option 1, it's easy to do)I personally implemented Option 2 in my
FlutterModule
project because it was easier to include pods from Flutter plugins. I had to create a custom build command based on theBuildIOSFrameworkCommand
class to prevent the_producePlugins
function from running. As a result, onlyApp.xcframework
was generated. In order to include Flutter plugins, their dependencies andFlutterPluginRegistrant
, I combined this solution with Option A from the add-to-app doc. Basically, for eachflutter_plugin
included a podspec from.ios/.symlinks/plugins/<flutter_plugin>/ios/<flutter_plugin>.podspec
and for theFlutterPluginRegistrant
a podspec from.ios/Flutter/FlutterPluginRegistrant/FlutterPluginRegistrant.podspec
.So the main goal for me personally is to remove the custom build command (also
BuildIOSFrameworkCommand
class has a lot of private methods that I had to copy-paste to the subclass) and use a solution provided by Flutter. And I think it can be a good improvement in general. It also could help writing iOS version of flutter/website#7775 because it currently seems impossible to easily share the same transitive platform dependency between Flutter module and iOS appPlease let me know if I misunderstood something and my use case can be achieved in some existing way
The text was updated successfully, but these errors were encountered: