Flutter Packages development practice – Release failure resolved
The library of Flutter is managed as a package. Package is divided into two types, Dart Package (also called Library Package) and Plugin Package. When we say Fluter package, we also mean Dart package, which can only use Dart and Flutter apis. When we say the Flutter plugin, we mean the plugin package. The Flutter plugin usually contains platform-specific code. To the user of the package, there is no difference.
Here we create a package and publish it to the DART repository.
1. Package development process
Create a New Flutter Package project using Android Studio
The specific process is as follows:
- On the menu, choose File -> New -> New Flutter Project.
- Select Flutter Package in the panel that pops up and click Next.
- Fill in the relevant information of the package. Just fill in our Project Name for Project Name, and fill in other information as required.
The details are shown below.
Specific business development
Next we can write our own code in the lib/ package.
The focus of this article is not here. For more information about Flutter, please refer to the Package API plugin for Flutter.
2. Fill in the upload information
Enter the user name, email address, and personal homepage information
Before uploading, we need to complete the local configuration information in the pubspec.yaml file. When we use AS to create a new project, the corresponding information has been automatically generated in this file, and we only need to fill in the user name, personal email and home page address.
name: flutter_lifecycle_state
description: Make State support lifecycle method just like Android' Activity#onCreate, Activity#onResume, Activity#onPause, Activity#onDestroy.Version: 0.0.1 Author: Tinytongtong <[email protected]> Homepage: https://blog.csdn.net/qq_26287435Copy the code
The values of the Name and Description fields here are the information entered in the New Package dialog.
The version field is used to issue a new version, increment the version number each time you issue a new version.
In the Author field, fill in the author name and the available Google email in the format of username. Note that this Gmail needs to be usable.
In the field of homepage, enter the URL of your homepage. In this case, enter my CSDN homepage.
LICENSE file
In addition, packages published to Pub need to include a LICENSE file, and the easiest way to do this is to select one when creating a repository on GitHub.
I pasted this from a new Github project.
Check the package configuration
To check the configuration of the package, run the following command at the root of the project:
flutter packages pub publish --dry-run
Copy the code
If there are no problems, the output is as follows:
. Package has 0 warnings.Copy the code
Publish a package
Publish the package as in the previous step, but without the –dry-run argument:
flutter packages pub publish
Copy the code
If this is your first Posting, you will be prompted to verify your Google account. The Google account starts with “HTTPS:” and ends with “. Email “to prevent page opening errors due to incomplete addresses.
Successful matches package is displayed after the file is uploaded.
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=xxxxxxx xxxxxxx-8grd2eg9tj9f38os6f1urbcvsq399u8n.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A52589&scope=ht tps%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email Then click"Allow access".
Waiting for your authorization...
Successfully authorized.
Uploading...
Copy the code
Of course, most of the time you’re reporting errors, but if it were that simple, I wouldn’t be writing this article. Don’t panic. Keep reading.
3. Common errors during release
- Remove target from host file
PUB_HOSTED_URL
,FLUTTER_STORAGE_BASE_URL
Modifications.
If you see this error as shown in the first line below, you will need to remove the changes to PUB_HOSTED_URL and FLUTTER_STORAGE_BASE_URL from the official guidelines, which will cause uploading the PUB to fail. Github.com/flutter/flu…
The new host is as follows: Refresh the terminal.
# flutter
#export PUB_HOSTED_URL=https://pub.flutter-io.cn
#export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
export PWD=/Users/tinytongtong/Documents/workspace/flutter/sdk/flutter/bin
export PATH="${PWD}:${PATH}"
Copy the code
- No open agent in general if you do not have
Bring your own ladder
If you do, you’ll see that the upload step is stuck here differently. As shown below.
TinytongtongdeMacBook -Pro% flutter Packages pub publish Publishing Flutter_lifecycle_state 0.0.1 to https://pub.flutter-io.cn: ... Looks great! Are you ready to upload your package (y/n)? y Uploading...Copy the code
If you press enter, the following error message will appear:
Looks great! Are you ready to upload your package (y/n)? y
Uploading...
Unhandled exception:
SocketException: Write failed (OS Error: Broken pipe, errno = 32), port = 0
#0 _rootHandleUncaughtError.
(dart:async/zone.dart:1112:29)
#1 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#2 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#3 _runPendingImmediateCallback (dart:isolate/runtime/libisolate_patch.dart:115:13)
#4 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:172:5)
tinytongtongdeMacBook-Pro%
Copy the code
The root cause of this error is that the agent was not opened.
- opened
lantern
The agent.
If you already have an agent, such as lantern, on, you may see the following error:
Bogon % flutter packages pub publish Publishing flutter_lifecycle_state 0.0.1 to 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=xx1urbcvsq39xxe=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo .email Then click"Allow access".
Waiting for your authorization...
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 = 58913
pub finished with exit code 69
bogon%
Copy the code
Or something like this:
Waiting for your authorization...
Authorization received, processing...
Connection closed before full header was received
pub finished with exit code 69
Copy the code
The root cause of these two errors is that you need to set up a proxy for the terminal, which is the command line proxy.
4. Final solution — command line wall climbing tool
Update: Using the Lantern to set the proxy for the TERMINAL Go to the MAC address to set the proxy for the terminal using the lantern.
One solution is recommended: Use Proxifier + SS on the MAC terminal.
Proxifier+Shadowshocks system the correct posture of global proxy
ss X
Follow the tutorial to download the configuration.
Command line proxy success verification mode:
If you have a successful palindrome (a text message in HTML format), you have succeeded. If you have no successful palindrome, your terminal is still inside the wall
Curl google.com = google.com = google.com = google.com = google.com
tinytongtongdeMacBook-Pro% curl google.com
<HTML><HEAD><meta http-equiv="content-type" content="text/html; charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>
tinytongtongdeMacBook-Pro%
Copy the code
An example of a successful upload
After all the problems have been resolved, the flutter packages pub publish command returns the following output:
TinytongtongdeMacBook -Pro% flutter Packages pub publish Publishing Flutter_lifecycle_state 0.0.2 to https://pub.dartlang.org: |-- .gitignore |-- .idea | |-- codeStyles | |'-- Project.xml | |-- dbnavigator.xml | |-- encodings.xml | |-- libraries | | |-- Dart_Packages.xml | | |-- Dart_SDK.xml | | '-- Flutter_Plugins.xml
| |-- markdown-navigator
| | '-- profiles_settings.xml | |-- markdown-navigator.xml | |-- misc.xml | |-- modules.xml | |-- vcs.xml | '-- workspace.xml
|-- .metadata
|-- CHANGELOG.md
|-- LICENSE
|-- README.md
|-- android
| |-- app
| | '-- src | | '-- main
| | '-- java | | '-- io
| | '-- flutter | | '-- plugins
| | '-- GeneratedPluginRegistrant.java | '-- local.properties
|-- lib
| '-- flutter_lifecycle_state.dart
|-- pubspec.yaml
'-- test
'-- flutter_lifecycle_state_test.dart Looks great! Are you ready to upload your package (y/n)? y Uploading... Successfully uploaded package. tinytongtongdeMacBook-Pro%Copy the code
When you publish successfully, you will receive a notification email on Gmail with a link to your project like this:
reference
Learn guide to Flutter: Encapsulate API plugin – Says Yu Gang
Failed to publish the Flutter pub
Failed to upload the package #16658
Publish plugin in china #17070
zhuanlan.zhihu.com/p/60136574