美文网首页
【Flutter】从零开始发布Package到Pub

【Flutter】从零开始发布Package到Pub

作者: Wing_Li | 来源:发表于2022-05-25 00:34 被阅读0次

    废话不多直入主题。

    1. 创建package工程

    2. 实现功能

    在 lib 中跟正常开发 App 一样,编写自己需要的功能。

    3. 创建example工程,实现demo代码

    在控制台输入如下:

    flutter create example

    4. 修改 CHANGELOG.md

    # 更新日志
    
    ## 0.0.2
    * TODO: fix
    
    ## 0.0.1
    
    * TODO: Describe initial release.
    

    5. 添加License

    MIT License
    
    Copyright (c) 2021 Wing_Li
    
    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:
    
    The above copyright notice and this permission notice shall be included in all
    copies or substantial portions of the Software.
    
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    SOFTWARE.
    

    6. 修改pubspec.yaml文件

    name: flutter_appears_randomly
    description: Animation with random gradients
    version: 0.0.2
    homepage: https://github.com/Wing-Li/flutter_appears_randomly
    

    7. 检查组件

    每次上传之前都要先检查有没有什么错误。

    flutter packages pub publish --dry-run

    执行后的输出结果如下:

    Publishing flutter_appears_randomly 0.0.2 to https://pub.flutter-io.cn:
    |-- .gitignore
    |-- .metadata
    |-- CHANGELOG.md
    |-- LICENSE
    |-- README.md
    |-- lib
    |   |-- appears_randomly_widget.dart
    |   '-- stagger_animation.dart
    |-- pubspec.yaml
    '-- res
        |-- example_video.gif
        '-- example_video.mp4
    
    Package has 0 warnings.
    

    Package has 0 warnings. 则代表 没什么问题。

    8. 发布

    发布的过程因为网络的各种问题,总是磕磕绊绊。

    官网发布使用的是(如果失败,往后看):

    flutter packages pub publish

    8.1 输入后会提示是否继续:
    8.2 提示 Google 验证:

    可点击跳转,也可以复制到浏览器。

    9. 成功

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

    发布时,可能出现的错误,都是网络原因引起的。

    错误一:

    Authorization received, processing...
    It looks like accounts.google.com is having some trouble.
    Pub will wait for a while before trying to connect again.

    在自己代理,打开设置找到如下端口:


    在控制台执行如下命令(如果是在 Android Studio 控制台发布,则就在此控制台执行):
    将命令中的端口号替换成自己的。

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

    然后再执行发布命令。

    错误二:

    Flutter pub finished with exit code 1

    使用如下命令发布:

    sudo flutter packages pub publish -v


    查看结果

    https://pub.dartlang.org/

    相关文章

      网友评论

          本文标题:【Flutter】从零开始发布Package到Pub

          本文链接:https://www.haomeiwen.com/subject/bfrkjltx.html