Recently, I was busy upgrading the Flutter SDK version and encountered some problems, so I recorded them.

Resource file naming

cannot load assets file starting with “#” from the rootBundle after install

  • # # XXXX beginning. PNG
  • PNG with the space XXX XXX.png
  • Chinese character 4401- School almanac. SVG
  • Special characters are not Latin

To solve

  • Changing the Naming Mode
  • performgit revert 383e90eb13bdc50ca0cce9f2575329ba8593506eRoll back the Flutter version
  • Wait for official hotfix

Name is not standard, Alex two lines of tears

ios bitcode

Due to some problems, existing ios projects cannot enable Bitcode. However, Flutter is enabled by default in V1.12.13 and the engine is enabled bitcode. This will cause the entire project to fail to compile successfully. After searching around the Web and asking some ios bosses, the owner of Flutter Team finally told me how to use commands to extract bitcode.

  • Execute the commandflutter build ios-framework --no-debug --no-profile, generate app. framework and Flutter. Framework (369.8MB)
➜ flutter_module flutter build ios - framework - no - debug - no - profile Building framework for com. Example. FlutterModule. Cc  in release mode... ├ ─ Populating Flutter. The framework... 486 Ms Flag School - Building AOT for App. Framework... 121.1 s (!) ├─ Levitating Resources for App. Framework... 0.2 s └ ─ Moving to build/ios/framework/Release 0.0 sCopy the code
  • CD to framework, usexcrun bitcode_strip -r app -o appOut of bitcode

App is the executable file in app. framework

Do the same for Flutter. Framework xcrun bitcode_strip -r Flutter -o Flutter

App.framework(10.6MB) and Flutter. Framework (39.2MB)

Android hybrid development code migration

I won’t mention the changes to the registration of the plugin in the Adaptation tutorial of the Flutter update 1.12.

  • There is a problem with the FlutterActivity setting transparent official API, the BackgroundMode enumeration is not exposed
  FlutterActivity
    .withNewEngine()
    .backgroundMode(FlutterActivity.BackgroundMode.transparent)
    .build(context)
Copy the code

This can be set temporarily with the following code

       Intent intent = FlutterActivity.withNewEngine().initialRoute('route').build(activity);
       intent.putExtra("background_mode"."transparent");
       activity.startActivity(intent);
Copy the code
  • Caching engines are officially supported

But I didn’t find a way to initialize a route. If entering a native flutter page requires a new engine, what does FlutterEngineCache do? Hope to know the small partners can answer questions.

update

You can use the flutterEngine. GetNavigationChannel (.) setInitialRoute (‘ my/the route);

But page heap management is a bit more complicated, and that’s what salty fish Flutter_boost does for us.

create

    // Instantiate a FlutterEngine.
    flutterEngine = new FlutterEngine(this);

    // Start executing Dart code to pre-warm the FlutterEngine.
    flutterEngine.getDartExecutor().executeDartEntrypoint(
      DartEntrypoint.createDefault()
    );

    // Cache the FlutterEngine to be used by FlutterActivity.
    FlutterEngineCache
      .getInstance()
      .put("my_engine_id", flutterEngine);
Copy the code

use

startActivity(
      FlutterActivity
        .withCachedEngine("my_engine_id")
        .build(currentActivity)
      );
Copy the code

Mixed development debugging hot overloading

Hybrid development is generally android AAR, ios framework this way, v1.12.13 support debugging and hot reload and other features.

It’s very simple. Let’s take Android for example.

  1. Install debug’s Flutter AAR to reference your Android project. You can use Maven locally or upload it to your Own Maven library for remote reference.
  2. Debug Runs the Android project
  3. Open your flutter module project in vscode and find it in the vscode command palette

debug:flutter attach to process(devices) 4. Enter the flutter module in your android project, at which point vscode synchronizes files to the device.

I tried debugging and hot reloading, but I felt there was a bug. The breakpoint would not enter the first time I entered it, so I had to hot reload it.

Ios, there is a bug, hot reload error

For the previous helpless pain of mixed debugging for me, has been very good, will use, I hope the official continue to improve.

Huawei Android devices blink back

Huawei devices blink back

  • Huawei DUB AL00A
  • Huawei DUB AL00
  • Honor BKK AL10
  • Huawei ARS AL00
  • Huawei DUB AL20

There is already a solution in issue, roll back the engine. Official rollback is also done, waiting for hotfix.

During the official reply, I tried to touch the Flutter engine (originally intended to remove bitcode, Creating- An-ios-bitcode-enabled -app and Android Huawei backoff by repackaging the engine), but I didn’t need to use it.

  • Compile engine official documentation

  • Prepare the compile engine environment

  1. Note that the cross-compilation platform only supports Android and ios on MAC
  • Linux supports cross-compiling artifacts for Android, but not iOS.

  • macOS supports cross-compiling artifacts for Android and iOS.

  • Windows doesn’t support cross-compiling artifacts for either Android or iOS.

MAC delicious? The only one that can cross-compile Android and ios is the MAC, which is a shame for my big-window users. The following operations are performed on the MAC

  1. Set this up, you know
Export http_proxy = http://127.0.0.1:1087 export https_proxy = http://127.0.0.1:1087Copy the code
  1. Download Google’s depot_tools toolkit

Depot_tools is a toolkit that includes tools like GClient, GN, and Ninja. Is a source code management tool provided by Google for Chromium to solve the problem of source code management.

  • Clone code

    git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git

  • Setting environment Variables

    export PATH="$PATH:/xxx/xxx/depot_tools"

  1. To github.com/flutter/eng… Download the code to the local, the official recommendation you fork, so that you can easily update, depending on the individual situation
  2. Create a. Gclient file under the engine directory
  • Use the branch of fork and add the following to replace the name of your fork
solutions = [
  {
    "managed": False,
    "name": "src/flutter",
    "url": "[email protected]:<your_name_here>/engine.git",
    "custom_deps": {},
    "deps_file": "DEPS",
    "safesync_url": "",
  },
]
Copy the code
  • We can also specify a certain version, for example we specify the rollback crashed version
solutions = [
  {
    "managed": False,
    "name": "src/flutter",
    "url": "https://github.com/flutter/engine.git@2994f7e1e682039464cb25e31a78b86a3c59b695",
    "custom_deps": {
      'src/third_party/skia': "https://skia.googlesource.com/skia.git@768f900a88cbfc5237e8edcc16aadde32536ed3e",
      'src/third_party/wuffs': 'https://skia.googlesource.com/external/github.com/google/wuffs.git@65e7b2b6c98a4d35e26bc2fc437e2e00f1393dc2',
    },
    "deps_file": "DEPS",
    "safesync_url": "",
  },
]
Copy the code
  1. CD to engine directory and execute gClient sync, this is a long process and the network is ok
  2. The engine of Flutter is based on Ninja, which was developed by Google to improve compilation speed. Chromium is also currently built through Ninja, and most of the members of the Flutter team cannot come from Chromium

All parameter combination

Main parameters of construction

  • Optimized /unoptimized
  • debug/profile/release
  • CPU Android comes in arm, ARM64, x86 and X86_64
  • CPU ios is divided into ARM, ARM64, and a simulator parameter –simulator
  1. CD to SRC /flutter/tools

Gn –android — Runtime-mode =release 3618 files will compile, which can take anywhere from half an hour to a lifetime depending on the performance of your MAC.

When compiled, the android_release folder is generated under SRC /out

For Android, you can get Flutter. So out of this folder and use it directly

  1. CD to SRC /flutter/tools

Gn — Runtime-mode =release 4271 files, where my MAC was overtaken by Alex’s MAC, it took me half a day to compile.

After compiling, the host_release folder will be generated under SRC /out. This folder must be generated if you want to package with the engine you compiled.

  1. Use local engine packaging

flutter build apk --target-platform android-arm --local-engine-src-path /Users/roott/Documents/Tools/flutter/engine/src --local-engine=android_release

  • – local – engine – SRC – path toward the engine/SRC

  • –local-engine points to the android_release directory under engine/ SRC /out

conclusion

Recently we found that the government is making Fuchsia, and we heard the grapevine that domestic manufacturers are adapting Fuchsia, we should be able to eat Fuchsia soon in 2020, and we have new expectations for the New Year.

Welcome to joinFlutter CandiesTogether to produce cute little Flutter candies (QQ group: 181398081)

And finally, put Flutter Candies on it. It smells sweet.