github.com/flutter/flu… 上面是官方的原文,有空我再逐字翻译,下面我初略的讲一下iOS的混合编译流程。
(凡是遇到问题,或者从其他过时译文过来的读者,必须要从第一步重新开始)
1.先切换到flutter master分支,再升级sdk
1.
flutter channel master
2.
flutter upgrade
//网络状况自己解决,这两步很重要
2.找到自己编写的flutter项目的路径
flutter_application_path = "../flutter_more/"
//我这里写的是相对路径,可以填写绝对路径,但是绝对路径不好让团队其他人操作
3.向podfile文件添加一下代码
flutter_application_path = "../flutter_more/"
//这里的代码上和过时的文档不一样,一定要改成这样!
load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')
//向你需要引用的target添加以下代码
install_all_flutter_pods(flutter_application_path)
//cocopods你们应该比我熟练,我今天才接触
- 使用pod install
pod install
//如果报错,请注意第三步的部分是否有出入
5.你现在已经可以直接启动了ios项目了,下面是绑定flutter桥的代码(我从原文直接复制的代码,你应该看得懂这部操作,另外,如果AppDelegate继承了其他类,原文中有其他方式解决)
In AppDelegate.h:
#import <UIKit/UIKit.h>
#import <Flutter/Flutter.h>
@interface AppDelegate : FlutterAppDelegate
@property (nonatomic,strong) FlutterEngine *flutterEngine;
@end
This allows AppDelegate.m to be really simple, unless your host app needs to override other methods here:
#import <FlutterPluginRegistrant/GeneratedPluginRegistrant.h> // Only if you have Flutter Plugins
#include "AppDelegate.h"
@implementation AppDelegate
// This override can be omitted if you do not have any Flutter Plugins.
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.flutterEngine = [[FlutterEngine alloc] initWithName:@"io.flutter" project:nil];
[self.flutterEngine runWithEntrypoint:nil];
[GeneratedPluginRegistrant registerWithRegistry:self.flutterEngine];
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
@end
6.目前到这里就结束了混编的基础了。