[Flutter] 發佈本身的插件 package

咱們本身作了插件包,固然也想發佈到pub.dartlang.org上去。怎麼發佈呢?先看看官方的說明(https://flutter.io/developing-packages/)。html

Publishing packages

Once you have implemented a package, you can publish it on Pub, so that other developers can easily use it.api

Prior to publishing, make sure to review the pubspec.yamlREADME.md, and CHANGELOG.md files to make sure their content is complete and correct.瀏覽器

Next, run the dry-run command to see if everything passes analysis:bash

$ flutter packages pub publish --dry-run

Finally, run the actual publish command:app

$ flutter packages pub publish

For details on publishing, see the Pub publishing docs.工具

 

意思就是說,作好插件後,在終端中先執行  $ flutter packages pub publish --dry-run 來檢查看是否沒有問題了,再執行下一句 $ flutter packages pub publish 來上傳。google

在這兩步中,若是沒有問題會在終端中會顯示 」Package has 0 warnings.「。url

 

在這一步若是出錯,能夠檢查一下 pubspec.yaml 中最後的 environment 字段是否設置。通常會是這樣:spa

environment:
  sdk: ">=2.0.0-dev.28.0 <3.0.0"
  flutter: ">=0.1.4 <2.0.0"

若是配置了仍是不行,按照提示修改。插件

好了,在一切都沒有問題時,咱們開始上傳。輸入命令  $ flutter packages pub publish 回車,會先檢測項目結構是否合法,而後會出現這樣的界面:

輸入 "y" 回車。

第一次上傳,會要求登陸谷歌帳號。這個時候終端會出現一個url地址,相似這樣:

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%3A62338&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email

  

將地址複製出來,在瀏覽器URL中輸入打開這個地址,容許登陸谷歌帳號就能夠了。

可是在這裏,因爲國內限制了谷歌的訪問,因此通常會打不開,怎麼辦呢?這個時候咱們只能藉助SVN工具了。我使用的是」無界「。

打開無界,設置成以下:

配置 Internet 屬性中的局域網設置

在代理設置界面中,輸入無界的代理地址和端口。如上圖所示。

這個時候再刷新頁面,應該能夠打開咱們要登陸谷歌的網址了。

登陸谷歌帳號後出來若是所示的界在,這時候點擊相關帳號確認就好了。

確認登陸後,瀏覽器會回調給 Android Studio ,這時候 Android Studio 會開始鏈接谷歌並上傳咱們的插件包。

可是這裏也要注意,可能也會由於谷歌被屏蔽而失敗。(出現下圖所示的提示時,通常就是這個問題了)

這個時候咱們須要設置終端的HTTP代理(在Android Studio中系統設置的配置的並無效果)。在終端中執行以下命令配置代理:

set http_proxy=http://127.0.0.1:9666
set https_proxy=https://127.0.0.1:9666

配置好後從新執行發佈命令,從新執行上面認證登陸的流程便可。(下圖爲上傳成功的提示)

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

  

相關文章
相關標籤/搜索