Translation of this article:Flutter ‘s iOS Application Bundle

This document describes how the Build system for Flutter transforms your Flutter project (and its assets) into an iOS application package. I want to be able to describe some of the build steps and explain the purpose of generating artifacts (PS: Artifacts I think can be interpreted as intermediate files generated at build time or executable files eventually generated, etc.) so that you can integrate the same process into your own build environment.

A note about workflow: When building applications to be published, you may use the Flutter tool, which makes the build process easier. However, some developers may find that this process is not configurable or does not suit their custom build Continuous integration (CI) configuration.

If you have a custom Xcode build or Gradle setup, all the “magic” features added by the Flutter tool are optional and you can configure the build to suit your own workflow.

All information in this document applies to iOS application packages ready for distribution to the App Store. This means that the project builds Flutter’s release model. Debug or Prifile compilation uses different runtime and packaging modes to support Hot Reload and observatory.

The Flutter application renders the user interface as a single view in the native view tree (layer). The following

Application package

Applications created using the Flutter Build ios –release command (or using the Flutter IDE like Android Studio) are very similar to a typical ios application package, which contains the application executable and the frameworks and resources it references.

The Runner. App package structure generated by Flutter:

Runner. The app ├ ─ ─ AppFrameworkInfo. Plist ├ ─ ─ Assets. The car ├ ─ ─ Base. Lproj │ ├ ─ ─ LaunchScreen. Storyboardc │ └ ─ ─ ├── Frameworks, Frameworks, Frameworks, Frameworks, Frameworks# See "App Framework Bundle"│ │ ├─ ├─ Info. ├─ ├.├# See "Flutter Framework bundle"│ ├ ─ ─ Flutter │ ├ ─ ─ the Info. The plist │ └ ─ ─ icudtl. Dat ├ ─ ─ the Info. The plist ├ ─ ─ Runner └ ─ ─ flutter_assets ├ ─ ─ AssetManifest. Json ├ ─ ─ └── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ─Copy the code

Compiling the application

When compiling a released version of an application (rather than a Profile or Debug version), you need production from both the builder and the host. (For more information on building robots (part of building engines, using GN and Ninja), see Contributing to the Flutter Engine.)

The Flutter tools will be cached on your machine when you install the SDK. You can see them in the bin/cache directory of your Flutter SDK copy. If you decide to integrate any of the steps of this process into your own build system, this folder contains all the versions of the chemicals needed to process Flutter.

The following sections describe some files specific to Flutter’s iOS application package.

The Flutter engine frame package

The Flutter. Framework folder is a package packaged into the iOS framework that contains

  • The Flutter engine contains core libraries (e.g., graphics, file and network I/O, accessibility support, plug-in architecture), DartVM, and the Skia rendering engine.
  • Asset files referenced by the Flutter engine this is currently ICU data only.

The Build robot generates the Flutter engine frame package, which is then downloaded and cached on your machine by the Flutter tool.

AOT framework package

App.framework contains AOT snapshots of all user-written Dart application code as well as Dart code for the Flutter framework and plug-ins in ARMV7 and AARCH64 formats.

During build, the compiler performs a reduction of the Dart code so that only the code that is actually used appears in the bundle. The gen_snapshot tool cached on the device generates the components needed to create the App. Framework package.

AOT snapshot

The AOT snapshot contains static code compiled from Dart to the device. The snapshot library generated by gen_snapshot contains four main symbols. These symbols can be unpacked by nm commands, such as:

$ nm -gU Runner.app/Frameworks/App.framework/App
Runner.app/Frameworks/App.framework/App (for architecture armv7):
003c6f60 S _kDartIsolateSnapshotData
00007000 T _kDartIsolateSnapshotInstructions
003c16a0 S _kDartVmSnapshotData
00004000 T _kDartVmSnapshotInstructions
Runner.app/Frameworks/App.framework/App (for architecture arm64):
00000000004041a0 S _kDartIsolateSnapshotData
0000000000009000 T _kDartIsolateSnapshotInstructions
00000000003fc740 S _kDartVmSnapshotData
0000000000005000 T _kDartVmSnapshotInstructions
Copy the code

Its purpose is as follows:

  • Dart VM snapshot (kDartVmSnapshotData): represents the initial state of the Dart heap shared between isolators. This helps to jump-start Dart campaigns more quickly, but does not contain any separation-specific information. It does not contain any information about specific campaigns.

  • The Dart VM command (kDartVmSnapshotInstructions) : includes all the Dart VM isolator is Shared between the general routine of AOT instructions. This snapshot is usually very small and consists mainly of stubs.

  • Isolation snapshot (kDartIsolateSnapshotData): Represents the initial state of the Dart heap and contains isolation-specific information.

  • Separate instructions (kDartIsolateSnapshotInstructions) : contains the Dart separator of AOT code execution.

Calling gen_snapshot is simple. You point it to the Dart source code, which will output something for each of the four symbols. Xcode then packages these symbols into an iOS framework, just like a framework written in C, C ++, Objective-C, or Swift. To learn more about how to configure snapshots and engines in Flutter Engine, see the Flutter Engine Wiki.

In addition to a lot of code, the Flutter tools ensure that the assets referenced by the application (and its plug-ins) end up in the application package. It does this by reading the assets listed in the project’s pubspec.yaml file.

About the android

The process of building the Android APK package (using the ‘flutter build apk-release command or IDE) generates the following file structure:

│ ├── Exercises │ ├── ─ fonts │ ├── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── ── │ ├─ ├─ materials │ ├─ materials │ ├─ materials │ ├─ materials │ ├─ materials │ ├─ Icudtl. Dat │ ├ ─ ─ isolate_snapshot_data │ ├ ─ ─ isolate_snapshot_instr │ ├ ─ ─ vm_snapshot_data │ └ ─ ─ vm_snapshot_instr ├ ─ ─ Classes. Dex ├ ─ ─ lib │ └ ─ ─ armeabi - v7a │ └ ─ ─ libflutter. So ├ ─ ─ the output. The json ├ ─ ─ res └ ─ ─ resources. The arscCopy the code

It’s basically the same as the iOS distribution, except:

  • The Flutter engine is packaged as the ELF library (libflutter. So).
  • The four symbols detailed in the previous section are now just binary blobs in assets.

The second point, perhaps a little unexpected and in need of explanation, is that you do not need to download the NDK to build the distribution APK. This is because the Flutter tool adds the BLOB as an asset when there is no NDK on the machine. On Android, the Flutter engine marks pages as executable files. So when it detects that AOT assets are packaged as binary BLOBs, it maps those BLOBs into memory and marks the corresponding pages as executable files. If you have access to the NDK on your machine, you can specify its location and use these symbols to generate a dynamic library. In this case, the Flutter engine uses four symbols from the dynamic library.

conclusion

The key to building an iOS application pack is:

  • You can place Flutter views anywhere in the native view hierarchy. All content presented by Flutter will be synthesized into this view.

  • Dart code is compiled into native machine code and packaged as a library or framework package like other c++ /Objective/Swift libraries. This means that all crash reporting and symbolization tools work the same way with Dart AOT code.

  • You can integrate Flutter into your own custom build system without relying on the Flutter tool on your development machine (although using it will make your job easier). All of these tools can be found in the bin/cache directory of the Flutter SDK.


The author and a friend did taobao coupons public number, shopping coupons to save money, help pay attention to it.