) ios和android,Flutter作为iOS和Android的Module

截止:2019-08-20

iOS

1、切换Flutter环境到master环境

查看当前环境:flutter channel

切换到master环境:flutter channel master

执行flutter doctor

2、创建项目基本目录flutter_test

3、flutter_test下使用Xcode创建iOS项目,添加CocosPods支持

4、flutter_test目录下,创建flutter module

flutter create -t module my_flutter

5、添加Flutter app到Podfile

修改Podfile文件,如下,执行pod install:

platform :ios, '9.0'

use_frameworks!

target 'DouDiZhu' do

flutter_application_path = '../flutter_module'

load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')

install_all_flutter_pods(flutter_application_path)

end

podhelper.rb说明:

Whenever you change the Flutter plugin dependencies in some/path/my_flutter/pubspec.yaml, you need to run flutter packages get from some/path/my_flutter to refresh the list of plugins read by the podhelper.rb script. Then run pod install again from some/path/MyApp.

6、iOS项目中Build Settings->Build Options->Enable Bitcode的bitcode改为NO

7、iOS项目中创建AppViewController.swift,内容如下:

import UIKit

import Flutter

class AppViewController: FlutterViewController {

override func viewDidLoad() {

super.viewDidLoad()

// Do any additional setup after loading the view.

}

/*

// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

// Get the new view controller using segue.destination.

// Pass the selected object to the new view controller.

}

*/

}

8、iOS项目中Appdelegate.swift中修改如下:

import UIKit

import Flutter

import FlutterPluginRegistrant

@UIApplicationMain

class AppDelegate: FlutterAppDelegate {

var flutterEngine: FlutterEngine?

var myWindow: UIWindow!

var navigationController: UINavigationController?

override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {

self.flutterEngine = FlutterEngine(name: "io.flutter", project: nil)

self.flutterEngine?.run(withEntrypoint: nil)

GeneratedPluginRegistrant.register(with: self.flutterEngine)

let appController = AppViewController()

self.navigationController = UINavigationController(rootViewController: appController)

self.myWindow = UIWindow(frame: UIScreen.main.bounds)

self.myWindow.rootViewController = self.navigationController

self.myWindow.makeKeyAndVisible()

return super.application(application, didFinishLaunchingWithOptions: launchOptions)

}

}

8、iOS项目中general中Main Interface删除为空

9、Android Studio打开flutter项目,运行到iOS设备或者模拟器一次

10、打开Xcode运行iOS项目,即可看到项目内容为flutter所开发的内容

46925e80eed4

WX20190820-195636@2x.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值