very_good_templates icon indicating copy to clipboard operation
very_good_templates copied to clipboard

feat: Add Flutter Target for ios app

Open ysavr opened this issue 1 year ago • 3 comments

Description

when I want to build flutter ios for example main_development.dart from xcode I have to change the path in FLUTTER_TARGET in Build Settings Xcode, how do I declare the path /Users/abstract/core_flutter/ through the brick.yaml prompt?

Requirements

  • [ ] All CI/CD checks are passing.
  • [ ] There is no drop in the test coverage percentage.

Additional Context

No response

ysavr avatar Jan 03 '25 06:01 ysavr

Hey, @ysavr 👋🏼

The FLUTTER_TARGET variable is automatically generated by the Flutter tool when the app is built (which means it is dynamically updated). Its value can be found within some of the files contained in the ios/Flutter folder.

Since this value is managed by the Flutter tool, its manipulation is not expected.

Can you describe in which context are you facing this requirement?


As a side note, it may be helpful to be aware of the fact that the FLUTTER_TARGET variable is computed with the value provided with the --target CLI option when running or building your app.

mrverdant13 avatar Jan 04 '25 01:01 mrverdant13

Screenshot 2025-01-06 at 08 08 32

When building ios from xcode i need to define dart main entry for every environment on FLUTTER_TARGET how to make it automatically refer to dart main entry for every environment (e.g development, staging and production)

ysavr avatar Jan 06 '25 01:01 ysavr

Unfortunately, the way Flutter works for iOS does not allow devs to run a project directly from Xcode.

As I mentioned before, there are some variables that are generated by the Flutter tool.

One of those generated variables are the following (Generated.xcconfig file):

// This is a generated file; do not edit or check into version control.
FLUTTER_ROOT=<absolute path to the Flutter SDK>
FLUTTER_APPLICATION_PATH=<absolute path to your app>
COCOAPODS_PARALLEL_CODE_SIGN=true
FLUTTER_TARGET=<relative path to the Flutter entry point>
FLUTTER_BUILD_DIR=build
FLUTTER_BUILD_NAME=<build name defined in your pubspec.yaml>
FLUTTER_BUILD_NUMBER=<build number defined in your pubspec.yaml>
EXCLUDED_ARCHS[sdk=iphonesimulator*]=...
EXCLUDED_ARCHS[sdk=iphoneos*]=...
DART_OBFUSCATION=false
TRACK_WIDGET_CREATION=true
TREE_SHAKE_ICONS=false
PACKAGE_CONFIG=.dart_tool/package_config.json

As you can see, several of them are computed and provided by the Flutter CLI and Flutter tool. And then they are imported in the other ~.xcconfig sibling files.

These values are generated when executing flutter pub get ... and flutter run/build ..., and each command result in quite different values.

You can test this out by your own:

  1. Run flutter pub get for your project.
  2. Open the ios/Flutter/Generated.xcconfig file, and you will see the FLUTTER_TARGET=lib/main.dart declaration.
  3. Run flutter bulid/run --target=<some other entry point>.
  4. Open the ios/Flutter/Generated.xcconfig file, and you will see the FLUTTER_TARGET=<the provided entry point> declaration.

Finally, you can enforce the definition of the FLUTTER_TARGET variable through Xcode, but that is just one single variable required for the Flutter project to build. If you run the project, you may encounter other unexpected results while launching or using the app.


What you can do, then, is to execute flutter pub get and flutter run/build ... before running your app through Xcode. A cumbersome workaround, I know, but it is necessary. You SHOULD NOT override these values, as that may lead to undesired and hard-to-track results.

You can find more details in the source code for these generation steps: https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/ios/xcode_build_settings.dart

mrverdant13 avatar Jan 09 '25 17:01 mrverdant13