Today, FLUTTER was embedded into our old iOS project as a module. No error was reported during compilation, but there was an error of “Unable to install” during runtime, so the mobile phone could not be installed. It can be run in the Demo before. After looking up some information, I found a solution and recorded it.
If you have already configured the Flutter development environment, you can go to The Flutter Chinese website and follow this tutorial.
-
Create a flutter Module: CD into the corresponding folder of the project file. Execute the command: (my_flutter: file name, modifiable)
flutter create -t module my_flutter
-
Add the following code to your project’s Podfile via Cocoapods:
Flutter_application_path is the position of the FLUTTER module relative to the podfile file. Flutter_application_path = ‘/ Users/admin/Desktop/project/my_flutter flutter’ load the File. The join (flutter_application_path, ‘ios’, ‘Flutter’, ‘podhelper.rb’)
target ‘yiguan’ do use_frameworks! Install_all_flutter_pods (Flutter_APPLICation_path)
target 'yiguanTests' do inherit! :search_paths end end Copy the code
Update the pods
pod install
Copy the code
- Add a script
Go to the Xcode -> Target -> Build Phase location in the iOS project, go to ➕ and select New Run Script Phase. Then put the following two lines in.
"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" build
"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" embed
Copy the code
-
If the following error is reported when compiling the project:
/bin/sh: /packages/flutter_tools/bin/xcode_backend.sh: No such file or directory Copy the code
Need to specify FLUTTER_ROOT path, in my_flutter /. Ios (hidden files)/Flutter/Generated. Xcconfig path finding Generated. Xcconfig files, open the can see the diagram below:
Find the following two lines and add them to xcode -> target -> build setting-user-defined:
// This is a generated file; do not edit or check into version control. FLUTTER_ROOT=/Users/admin/development/flutter FLUTTER_APPLICATION_PATH = / Users/admin/Desktop/project/my_flutter flutterCopy the code
As shown in figure: