Flutter快速入门实战
flutter常用命令
1 | flutter run --release |
安装-环境搭建-debug-运行发布一个应用到手机上
- 下载flutter_macos_3.0.1-stable.zip
- 解压到
~/flutter
- 配置环境变量,在
~/.zshrc
末尾添加export PATH="~/flutter/bin:$PATH"
- idea安装flutter插件并附带安装Dart插件
- 配置idea的flutter路径
~/flutter
- 新建一个Flutter项目
IOS设置
- 安装Xcode
- 设置IOS模拟器,在idea或bash执行
open -a Simulator
- 在idea项目上面右键,然后点击
Flutter->Opne IOS module in Xcode
- 然后在Xcode里面点击运行即可
- (可选)启用其他平台执行
flutter config --enable-linux-desktop
- 设置开发者账号,在
Xcode-runner-setting-team
添加苹果账号 - 点击即可debug测试
- iOS提示
不受信任的开发者
,点击设置-通用-VPN与设备管理-添加信任
- 断开数据线会提示
In iOS 14+,debug mode Flutter apps can only
执行flutter run --release
进行发布安装
常见问题
找不到ios设备,健康检查提示
CocoaPods not installed
解决:执行
sudo gem install cocoapods
安装cocoapods1
2
3
4
5
6
7#无sudo安装,报错
gem install cocoapods --user-install
#错误信息,解决,用sudo gem install cocoapods安装
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/ruby.h:24:10: fatal error: 'ruby/config.h' file not found
#include "ruby/config.h"
^~~~~~~~~~~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/ruby.h:24:10: note: did not find header 'config.h' in framework 'ruby' (loaded from '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks')健康检查提示`HTTP host “https://maven.google.com/" is not reachable. Reason: An error
occurred while checking the HTTP host: Operation timed out
✗ HTTP host “https://cloud.google.com/" is not reachable. Reason: An error
occurred while checking the HTTP host: Operation timed out`
解决:在
~/.zshrc
添加环境如下变量1
2
3# 国内用户需要设置
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn(该问题似乎未解决)提示错误
Searching for inspections failed: undefined method 'map' for nil:NilClass
解决:执行
sudo arch -x86_64 gem install ffi
执行
flutter doctor
提示1
2[!] Proxy Configuration
! NO_PROXY is not set解决:执行
vim .zshrc
添加export NO_PROXY=localhost,127.0.0.1
然后保存。苹果IOS:xcode提示“codesign 想要访问您的钥匙串中的密钥”
解决(最终采用):钥匙串访问APP=>登录=>我的证书=>双击“Apple Development:xxx“(这个选择系统,使用的签名的开发证书)=>访问控制=>允许所有应用
解决方案二(采用):一直输用户名和密码大概8次左右
出现错误
Error (Xcode): File not found: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc/libarclite_iphoneos.a
解决:将
Podfile
文件内容末位post_install do |installer|..... end
替换为1
2
3
4
5
6
7
8
9post_install do |installer|
installer.generated_projects.each do |project|
project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0'
end
end
end
end在ios目录,执行命令
pod install