【错误记录】发布 Flutter 插件包报错 ( Failed to upload the package.pub finished with exit cod

195 阅读1分钟

文章目录

  • 一、报错信息
  • 二、解决方案

一、报错信息

发布插件包时,确认发布并校验Google账号后出现以下报错:

Failed to upload the package.
pub finished with exit code 1

完整报错信息:

D:\002_Project\002_Android_Learn\flutter_package>flutter packages pub publish
Publishing flutter_package 0.0.1 to https://pub.flutter-io.cn:
|-- .gitignore
|-- .metadata
|-- CHANGELOG.md
|-- LICENSE
|-- README.md
|-- lib
|   '-- flutter_package.dart
|-- pubspec.yaml
'-- test
    '-- flutter_package_test.dart

Publishing is forever; packages cannot be unpublished.
Policy details are available at https://pub.dev/policy

Do you want to publish flutter_package 0.0.1 (y/N)? y
Uploading...
Failed to upload the package.
pub finished with exit code 1

使用flutter packages pub publish -v命令可以获取更详细的日志信息:

FINE: Uploading finished (0.642s).
FINE: Saving OAuth2 credentials.
IO  : Writing 1381 characters to text file D:\001_Develop\010_Flutter\flutter_windows_2.2.3-stable\flutter\.pub-cache\credentials.json.
ERR : Failed to upload the package.
FINE: Exception type: ApplicationException
...

二、解决方案

这个问题通常是由于设置了Flutter镜像导致的。很多开发者在使用appuploader等iOS开发工具时也会遇到类似的配置问题,解决方案如下:

  1. 检查环境变量中是否设置了以下镜像:

    PUB_HOSTED_URL : https://pub.flutter-io.cn 
    FLUTTER_STORAGE_BASE_URL : https://storage.flutter-io.cn
    
  2. 从环境变量中移除上述两个镜像

  3. 使用以下命令向Flutter中央仓库推送Dart包:

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

成功上传后会显示:

D:\002_Project\002_Android_Learn\flutter_package>flutter packages pub publish --server=https://pub.dartlang.org
Publishing flutter_package_first_demo 0.0.1 to https://pub.dartlang.org:
...
Successfully uploaded package.

对于iOS开发者来说,类似的问题在使用appuploader等工具上传应用时也可能遇到。建议在上传前仔细检查网络配置和证书设置,确保开发环境配置正确。