Flutter(*)Mac发布Plugin到Pub

0、学习网站:

https://www.dartlang.org/tools/pub/cmd/pub-lish

1、下载flutter

存放位置:

/Users/zhangchaozhou/Documents/flutter

2、配置环境

打开配置文件:

vi ~/.bash_profile

编辑保存配置文件:

export M2_HOME=/Users/zhangchaozhou/Documents/bin/apache-maven-3.5.0
export PATH=$PATH:$M2_HOME/bin
export PATH=${PATH}:/Users/zhangchaozhou/Documents/flutter/bin

执行命令:

source ~/.bash_profile

否则执行flutter命令会出现以下错误:

-bash: flutter: command not found

3、发布插件库到pub

在Android Studio终端执行命令:

flutter packages pub publish --dry-run

出现警告:

Missing requirements:
* Your pubspec.yaml must have an "author" or "authors" field.
* Your pubspec.yaml is missing a "homepage" field.

添加配置:

author: chaozhouzhang <13760289294@139.com>
homepage: https://github.com/chaozhouzhang

检查成功:

Package has 0 warnings.

发布命令:

flutter packages pub publish --server=https://pub.dartlang.org

待授权:

Looks great! Are you ready to upload your package (y/n)? y
Pub needs your authorization to upload packages on your behalf.
In a web browser, go to https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=force&response_type=code&client_id=818368855108-8grd2eg9tj9f38os6f1urbcvsq399u8n.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A52809&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email
Then click "Allow access".

Waiting for your authorization...

点击链接,需要科*学上网:

《Flutter(*)Mac发布Plugin到Pub》
《Flutter(*)Mac发布Plugin到Pub》 选择需要授权的Google邮箱账号
《Flutter(*)Mac发布Plugin到Pub》
《Flutter(*)Mac发布Plugin到Pub》 输入Google邮箱账号的密码进行授权

《Flutter(*)Mac发布Plugin到Pub》
《Flutter(*)Mac发布Plugin到Pub》 授权发布成功

授权失败:

Authorization received, processing...
It looks like accounts.google.com is having some trouble.
Pub will wait for a while before trying to connect again.
OS Error: Operation timed out, errno = 60, address = accounts.google.com, port = 54374
pub finished with exit code 69

参考Github解决方案:

https://github.com/flutter/flutter/issues/17070

查看Flutter对应的Dart版本:

flutter doctor -v

《Flutter(*)Mac发布Plugin到Pub》
《Flutter(*)Mac发布Plugin到Pub》 Flutter相关信息

全局模式科*学上网,查看HTTP代理设置:

《Flutter(*)Mac发布Plugin到Pub》
HTTP代理设置

设置代理,需要更换网络或重新启动的时候在android studio终端中设置:

export https_proxy=http://127.0.0.1:1087
export http_proxy=http://127.0.0.1:1087
set https_proxy=https://127.0.0.1:1087
set http_proxy=http://127.0.0.1:1087

重新发布、授权,成功上传:

Waiting for your authorization...
Authorization received, processing...
Successfully authorized.
Uploading...
Successfully uploaded package.

查看结果:

https://pub.dartlang.org/

《Flutter(*)Mac发布Plugin到Pub》
《Flutter(*)Mac发布Plugin到Pub》

使用:

https://pub.dartlang.org/packages/data_plugin#-installing-tab-

《Flutter(*)Mac发布Plugin到Pub》
《Flutter(*)Mac发布Plugin到Pub》 使用Plugin方式

获取包的时候一直处于一下状态:

Running "flutter packages get" in project_name...

解决方法参考:

https://flutter.dev/community/china

终端指令:

export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
flutter doctor -v

重新package get:

Running "flutter packages get" in data_demo...                      0.5s
Process finished with exit code 0

    原文作者:chaozhouzhang
    原文地址: https://zhuanlan.zhihu.com/p/60136574
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞