Flutter stock iOS application access Flutter

Foreword

This article based on a blog post: Flutter Build ios product analysis

Due to the current Flutter nascent stage, so if you want to use, it should be a gradual process of evolution, namely the gradual integration of Native Flutter, Flutter of gradual and complete.

Debug integrated solutions

  • Debug integrated solution for debugging , you can directly source-level debugging and development, easy look into the problem. (Flutter plug empathy)

Native dependent Flutter analysis

According to the contents of the last chapter shows, Native dependent Flutter of the core content is dependent Flutter Engine (Flutter.framework), parse and rely Flutter plug-ins, as well as dependent Flutter business layer codes (App.framework).

Native Pod Install Flutter

Therefore, direct development in Native engineering, commissioning Flutter plugin configuration process is as follows:

  • Analysis of Generated.xcconfigacquisitionFLUTTER_ROOT
  • Dependent Flutter Engine
  • Dependent Flutter business code
  • Plug-dependent Flutter registry
  • Plug-dependent Flutter
  • Set to false Bitcode

Therefore, Native dependent Flutter of engineering flutter_podhelper.rbwill be included in the section above.

Access Process

Modify xcode_backend.sh

In Flutter 1.9.1 version, you need to modify the script. Other versions temporarily unclear.

  • vim $FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh
--- a/packages/flutter_tools/bin/xcode_backend.sh
+++ b/packages/flutter_tools/bin/xcode_backend.sh
@@ -141,7 +141,7 @@ BuildApp() {
     mkdir "${derived_dir}/engine"
     RunCommand cp -r -- "${flutter_podspec}" "${derived_dir}/engine"
     RunCommand cp -r -- "${flutter_framework}" "${derived_dir}/engine"
-    RunCommand find "${derived_dir}/engine/Flutter.framework" -type f -exec chmod a-w "{}" \;
+    RunCommand find "${derived_dir}/engine/Flutter.framework" -type f -iname '.h' -exec chmod a-w "{}" \;
   else
     RunCommand rm -rf -- "${derived_dir}/Flutter.framework"
     RunCommand cp -r -- "${flutter_framework}" "${derived_dir}"

Project hierarchy

  • To ensure Flutter project (app) and Native engineering (Android, iOS) in the same directory.
➜  temp tree -L 1
.
├── Android
├── flutter_module
└── iOS

3 directories, 0 files

Modify iOS / Podfile

In ios/Podfileuse app/flutter_podhelper.rb:

# 配置Flutter Module的目录
flutter_application_path = '../flutter_module'
# 加载.ios/Flutter/podhelper.rb来注入依赖
load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')

target 'MyApp' do
  # 依赖注入:Flutter引擎、Flutter业务代码、Flutter插件依赖
  install_all_flutter_pods(flutter_application_path)
end

Compile Flutter product

In appthe next directory, add the following build.sh:

# !/bin/sh

# 当前目录为app
echo "当前路径为:`pwd`" 

# 先清除.ios和.android
flutter clean

# 拉包
flutter pub get
flutter packages get

# 安装依赖
cd .ios  # 从当前目录为app进入.ios
# 插件依赖
pod install --verbose --no-repo-update
cd ../   # 从当前目录为app/.ios退出

# 编译
flutter build ios

Then in flutter_modulethe directory, execute ./build.sh, wait compile product success.

➜  flutter_module flutter build ios
Building com.wtfexample.flutterModule for device (ios-release)...
Found saved certificate choice "Apple Development: [email protected] (xxxxxxxx)". To clear, use
"flutter config".
Signing iOS app for device deployment using developer identity: "Apple Development:
[email protected] (xxxxxxxx)"
Running Xcode build...

 ├─Building Dart code...                                    20.0s
 ├─Generating dSYM file...                                   0.3s
 ├─Stripping debug symbols...                                0.0s
 ├─Assembling Flutter resources...                           0.7s
 └─Compiling, linking and signing...                         3.9s
Xcode build done.                                           29.6s
Built /Users/.../flutter_module/build/ios/iphoneos/Runner.app.

Dependent on product

In the iOSproject execution pod install --verbose --no-repo-updateto complete dependency injection.

Release integration scheme

Release dependent Debug program based on integrated solutions, simply Flutter engine, Flutter business layer codes, FlutterPluginRegistrant, Flutter plug-ins and their dependencies compiled into a static library can be integrated through the pod.

pod 'Flutter', :git => GitPath, :tag => GitTag
pod 'FlutterApp', :git => GitPath, :tag => GitTag
pod 'FlutterPluginRegistrant',  :git => GitPath,:tag => GitTag
Module Explanation
Flutter Flutter engine
FlutterApp Flutter business layer code and its resource files
FlutterPluginRegistrant Flutter plug-in registration system, including the plug-Flutter
  • See this article for more Flutter CI script production analysis, how to make Flutter iOS end product program.
    • This script shows how to make these programs static library, follow only need to upload a static library to Podspec product such as static hosting platform can be.

appendix

He published 183 original articles · won praise 217 · Views 460,000 +

Guess you like

Origin blog.csdn.net/Notzuonotdied/article/details/103746222