欢迎光临
我们一直在努力

flutter发布插件到私服

1. 创建要发布的插件

创建项目一般有2中方法

flutter create -t plugin helloworld 

你也可以通过 flutter create -h 命令来查看flutter支持的所有命令:

-h, --help Print this usage information. --[no-]pub Whether to run "flutter pub get" after the project has been created. (defaults to on) --[no-]offline When "flutter pub get" is run by the create command, this indicates whether to run it in offline mode or not. In offline mode, it will need to have all dependencies already available in the pub cache to succeed. --[no-]with-driver-test Also add a flutter_driver dependency and generate a sample 'flutter drive' test. -t, --template=<type> Specify the type of project to create. [app] (default) Generate a Flutter application. [module] Generate a project to add a Flutter module to an existing Android or iOS application. [package] Generate a shareable Flutter project containing modular Dart code. [plugin] Generate a shareable Flutter project containing an API in Dart code with a platform-specific implementation for Android, for iOS code, or for both. -s, --sample=<id> Specifies the Flutter code sample to use as the main.dart for an application. Implies --template=app. The value should be the sample ID of the desired sample from the API documentation website (http://docs.flutter.dev). An example can be found at https://master-api.flutter.dev/flutter/widgets/SingleChildScrollView-cla ss.html --list-samples=<path> Specifies a JSON output file for a listing of Flutter code samples that can created with --sample. --[no-]overwrite When performing operations, overwrite existing files. --description The description to use for your new Flutter project. This string ends up in the pubspec.yaml file. (defaults to "A new Flutter project.") --org The organization responsible for your new Flutter project, in reverse domain name notation. This string is used in Java package names and as prefix in the iOS bundle identifier. (defaults to "com.example") --project-name The project name for this new Flutter project. This must be a valid dart package name. -i, --ios-language [objc, swift (default)] -a, --android-language [java, kotlin (default)] --[no-]androidx Generate a project using the AndroidX support libraries (defaults to on) 

File->New->New Flutter Project...
然后选择 plugin 就好

<img src="https://tva1.sinaimg.cn/large/007S8ZIlgy1gic4wx8jopj30lv02jgo6.jpg" alt="image-20200902111524956" />

<img src="https://tva1.sinaimg.cn/large/007S8ZIlgy1gic4x7iro1j30p00io3zw.jpg" alt="image-20200902111541613" style="zoom:50%;" />

修改项目的 pubspec.yaml 文件, 添加如下配置:

name: helloword # 要发布的项目名称 description: A Test Flutter plugin. # 项目描述 version: 1.0.0 # 发布的版本 authors: [zhangsan <zhangsan@qq.com>] # 项目作者 homepage: http://localhost:8080 # 项目地址 publish_to: http://localhost:8080 # 发布的私有服务器地址 如果要发布到公共pub库,则该行可以省略 

配置好了之后通过命令检查一下:

flutter packages pub publish --dry-run 

如用以上命令有warning就按要求修改下,如没错误就开始发布了, 发布命令:

flutter packages pub publish 
|-- lib | '-- helloworld.dart |-- pubspec.yaml '-- test '-- helloworld_test.dart Looks great! Are you ready to upload your package (y/n)? y Uploading... Successfully uploaded package. 

如出现以上情况就表示发布成功了

然而,多数情况下我们会出现下述情况:

对,没错。需要进行google验证,即便发布到私有仓库也要通过这一步。而国内进行google验证要fq,比较麻烦。

如果发布到共有pub库就乖乖进行验证吧,验证后接着发布,坐等成功。

那发布到私有仓库如何设置跳过google验证?别着急,我们往下看

2. 搭建pub私服

这个源码也是个dart项目,我们可以解压后直接用Android Studio打开

打开Terminal窗口,输入pub get拉取依赖,成功后会显示Got dependencies!

然后执行命令:dart example/example.dart -d /tmp/package-db 来启动服务

出现上述图案表示服务已经成功启动

3. 跳过google验证

保存&退出

再切换到plugin工程进行发布,ok!发布成功、已经不需要google验证了

4. 依赖我们发布的插件

在我们需要依赖的项目的yaml文件中 dependencies:下添加:

helloword: hosted: name: helloword url: http://localhost:8080 version: ^1.0.0 

注意:yaml中层级一定要用空格对齐(helloword一级,hosted和version二级,name和url3级),否则会报错;然后执行pub get即可

如果我们仅仅只需要在本地依赖,可以直接用路径依赖,免去发布的这一步:

helloword: path: ...../Workspace/plugin/hellowork 
  • 海报
海报图正在生成中...
赞(0) 打赏
声明:
1、本博客不从事任何主机及服务器租赁业务,不参与任何交易,也绝非中介。博客内容仅记录博主个人感兴趣的服务器测评结果及一些服务器相关的优惠活动,信息均摘自网络或来自服务商主动提供;所以对本博客提及的内容不作直接、间接、法定、约定的保证,博客内容也不具备任何参考价值及引导作用,访问者需自行甄别。
2、访问本博客请务必遵守有关互联网的相关法律、规定与规则;不能利用本博客所提及的内容从事任何违法、违规操作;否则造成的一切后果由访问者自行承担。
3、未成年人及不能独立承担法律责任的个人及群体请勿访问本博客。
4、一旦您访问本博客,即表示您已经知晓并接受了以上声明通告。
文章名称:《flutter发布插件到私服》
文章链接:https://www.456zj.com/38969.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址