1. Download engines

1.1. View engine information

1.1.1. View the current engine version

  • Terminal command :% flutter doctor -v

1.1.2. View and switch the engine version

  • % flutter channel

  • To switch to a flutter channel, add the version type to it: Flutter Channel Master

1.1.3 Complete engine version number

  • % cat $FLUTTER/bin/internal/engine.version

1.1.4, “Science 🪜” download the Engine code

GN build file

  • generateNinjaBuild file meta-build system, and finally we use Ninja!

2.1. Find the GN file first

2.2. Build an engine for iOS devices

  • CD to the firstgnLocation folder
    • Debug version:./gn --ios --unoptimized
    • Real machine release version (daily development use, if we want to customize the engine):./gn --ios --unoptimized --runtime-mode=release
    • Simulator version:./gn --ios --simulator --unoptimized
    • Host side (Mac) build:./gn --unoptimized
  • You may encounter an error. Check your preferences to see if the program is blocked by security and privacy

2.3. The construction of each version is completed

  • inThe out directoryGenerate corresponding project

3. Ninja compiled the file (time-consuming)

  • Compile the GN build file,You can compile at the same time
    • CD to out directory and execute the following command (below is 4 kinds of simultaneous compilation)
    • ninja -C host_debug_unopt && ninja -C ios_debug_sim_unopt && ninja -C ios_debug_unopt && ninja -C ios_release_unopt
    • If you can’t find Ninja, you can install ninja:% brew install ninja
    • You may also encounter an error check to see if your program is being blocked by security and privacy
    • You need to run this command again after modifying engine code content to see the modification effect

4. Configure the project code

4.1. Add environment variables to Generated. Xcconfig

  • runFlutter fileIn theRunner.xcworkspaceFile to findGenerated.xcconfigFile to which two environment variables are added to associate the engine file
    LOCAL_ENGINE= iOS_debug_sim_unopt /engine/ SRC # LOCAL_ENGINE= iOS_debug_sim_unoptCopy the code
    • FLUTTER_ENGINE: Engine path
    • LOCAL_ENGINEGN Compiles the file

4.2 Check whether the binary contains debugging information

  • Lipo command
    $lipo XXX -thin armv7 -output armv7_xxx $lipo -create xxx.a xxx.a -output xxx.aCopy the code

4.3 LLDB Check whether debugging information is contained

$lldb --file Flutter_arm64 
(lldb) target create "Flutter_arm64" 
Current executable set to 'Flutter_arm64' (arm64). 
(lldb) script lldb.target.module['Flutter_arm64'].GetNumCompileUnits() 
1
(lldb)
Copy the code

4.4 Use Python to list the full path to all compilation units of a module

(lldb) target create "Flutter_arm64" Current executable set to 'Flutter_arm64' (arm64). (lldb) script Python Interactive  Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D. >>> m = lldb.target.module['Flutter_arm64'] >>> for i in range(m.GetNumCompileUnits()): ... cu = m.GetCompileUnitAtIndex(i).file.fullpath ... print(cu) ... None >>>Copy the code

5, the underlying implementation content

5.1, the channel

  • The channelName, message manager objectbinaryMessengerandcodec(singleton, implicit)retain
  • setMethodCallHandler:(FlutterMethodCallHandler *)

5.2 codec codec

  • It’s actually an agreement
  • internalFlutterStandardReadWriterImplement read and write methods

6. Hot overload mount

  • Run other projects through server-side execution (requires download of server-side open source)

6.1. Hot overload operation process

  • The Dart code – >Dart Server–> The Dart vm–> iOS client (communicates with rendering engine via RPC protocolFlutter.framework)

Remark:

Break points and pass to methods

  • br set -n "touchesBegan:": withtouchesBeganMethod,Across engineering, the implementation of"c"Command to proceed to the next step

Switch is more efficient than if and else when there are more than three options