An overview,

Recently, the test machine was upgraded to iOS14, and the online APP developed with Flutter was tested. No problem was found, but in the scenario of installing the APP with Xcode, the APP failed after disconnecting Xcode and running again.

The company’s APP test results are as follows:

Source of APP Whether the flash back model
online no release
The dandelion is debug
Xcode Is (disconnectXcodeBefore you open theAPP debug

1. Cause

The reason for the flash is that the Flutter SDK, the official Flutter update, is also fast, and has a description for iOS14: the explanatory link on the Flutter website

If we install the flutter application in debug mode on a real machine with iOS14, we will not be able to open the application from the desktop after disconnecting the compile installation connection.

2. Solutions

  1. And again, useXcodeflutter runTo run.
  2. Set up theFlutterThe compilation mode of module isprofilerelease

3. Supplementary explanation

  1. This flashback only happens on the real machine, and while the simulator is running,FlutterThe compilation mode of the module should bedebug, if setreleaseThe compiler will report an error.
  2. Officials say if it isPure Flutter projectYou can use it directlymaster channelFlutter versionBut there is no explanation for mixed development, plus we are using idle fishflutter_boostImplementation of mixed development, limitedFlutterSo I didn’t try to see if it would work for us

Second, try to solve

Based on my actual situation, I chose the second solution above.

1, configuration,

Open the project with Xcode, find user-defined at the bottom of Build Settings, click the + button, and add a configuration with the key FLUTTER_BUILD_MODE and the value of release.

2, run,

Run it on the real machine again, disconnect Xcode and run it without crashing

3, problem,

The real machine problem seems to be solved, but there will be problems

Problem 1: In release or profile mode, Flutter uses AOT. Some functions such as code breakpoint debugging and hot overload are not available

Problem 2: As mentioned above, the emulator can only run in debug mode, and we cannot avoid switching between the real machine and the emulator repeatedly. Each switch requires manually adjusting the value of FLUTTER_BUILD_MODE, which is very troublesome

What are some good ways to solve the above problems?

Third, optimization scheme

In fact, the APP on the real machine cannot run after disconnecting from Xcode, which is not a problem for us developers. The problem is that the package on the dandelion must be able to be opened when it is given to the testers, so in order to save these unnecessary time, We needed a script to help us switch the compilation mode of our Flutter.

When changing the value of FLUTTER_BUILD_MODE, I found from git that I actually modified the project. Xcodeproj, so what tools are available to help us modify the xcodeproj file?

Here I found mod-PBxProj, the installation and use of the library is clearly written on the wiki, so I won’t go into detail here, just go to the code

import getopt
import sys
from pbxproj import XcodeProject

if __name__ == "__main__":
    argv = sys.argv[1:]
    # processing flutter_build_mode
    flutter_build_mode = (False."release")
    # the name of the target
    target_name = None

    try:
        opts, args = getopt.getopt(argv, "p:m:t:"["path=, mode=, target="])
    except getopt.GetoptError:
        print('switch_flutter_build_mode. Py - p "file path" -m "mode (release | debug)" -t "target name"')
        sys.exit(1)

    for opt, arg in opts:
        if opt in ["-p"."--path"]:
            project_path = arg
            if len(project_path) == 0:
                print('Please enter the address of the item')
                sys.exit(2)
        if opt in ["-m"."--mode"]:
            flutter_build_mode = (True, arg if len(arg) > 0 else "release")
        if opt in ["-t"."--target"]:
            target_name = arg

    # processing flutter
    if flutter_build_mode[0]:
        fileName = project_path.split("/")[-1]
        if not fileName.endswith("xcodeproj") :print("Please use -p to specify the path to the. Xcodeproj file.")
            sys.exit(3)
        project = XcodeProject.load(project_path + '/project.pbxproj')
        # Set user-defined (if target_name is None, flag is set for each target)
        project.set_flags('FLUTTER_BUILD_MODE', flutter_build_mode[1], target_name)
        project.save()
Copy the code

Use is also very simple, the terminal directly input the following command

Py -p 'XXX/project. Xcodeproj' -t Target name -m releaseCopy the code

Parameter Description

parameter use
-p xcodeprojFile path
-t targetThe name of the
-m Compile mode (release,debug,profile )

PS: The script is based on Python3

We are using Jenkins for packaging and automatically uploading to dandelions, so we just need to call this script before configuring the packaging in Jenkins.

Finally, combined with the Shuttle software, it is possible to switch the compilation mode in an interface manner

Four, say two last words

This article is based on the hybrid development of the Flutter. If there is anything wrong or inadequate, welcome to correct it. Thank you for reading