Installation and use of flutter protobuf plugin

1. Install the plugin
insert image description here
2. Add the plugin in pubspec.yaml

  protobuf: ^2.1.0
  protoc_plugin: ^20.0.1

3. Install protoc

brew install protobuf

Check if the installation is successful

protoc --version

4. Install dart

brew tap dart-lang/dart
brew install dart

After dart is installed, there is a pub command. Enter the dart command line and dart pub to check whether it is successful

5. Install protoc_plugin

pub global activate protoc_plugin

6. Add protoc-gen-dart to the path
in the user root directory: .bash_profile added

export PATH="$PATH":"$HOME/.pub-cache/bin"

After installation, there is the protoc-gen-dart command. (In fact, the installation was not successful and did not take effect)

7. Compile the .proto file into a dart file

protoc --dart_out=. test.proto

Because I did not succeed in adding protoc-gen-dart to the path, fortunately, it is okay not to add this environment, just add a paragraph later

protoc --dart_out=. test.proto --plugin ~/.pub-cache/bin/protoc-gen-dart

My specific generation command line here: protoc -I folder absolute path --dart_out= folder absolute path proto file absolute path --plugin ~/.pub-cache/bin/protoc-gen-dart

protoc -I /Users/macminihao/AndroidStudioProjects/SocialIM/lib/protobufdart/dart/room --dart_out=/Users/macminihao/AndroidStudioProjects/SocialIM/lib/protobufdart/dart/room /Users/macminihao/AndroidStudioProjects/SocialIM/lib/protobufdart/dart/room/room_text.proto --plugin ~/.pub-cache/bin/protoc-gen-dart

The most important configuration environment:
mac related command
vim ~/.bash_profile
Press esc to enter the command mode, enter: wq to exit and save
Execute source ~/.bash_profile to make the configuration take effect

export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
FLUTTER_PATH='/Users/macminihao/Library/flutter'
export PATH="$PATH:/Users/macminihao/Library/flutter/bin"
export PATH="$PATH":"$FLUTTER_PATH/bin/cache/dart-sdk/bin"
export PATH="$PATH":"$FLUTTER_PATH/.pub-cache/bin"
export PATH="$PATH":"$HOME/.pub-cache/bin"
//镜像
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
//flutter路径,通用名称,$FLUTTER_PATH指代这个
FLUTTER_PATH='/Users/macminihao/Library/flutter'
//Flutter SDK
export PATH="$PATH:/Users/macminihao/Library/flutter/bin"
//Dart SDK within Flutter SDK
export PATH="$PATH":"$FLUTTER_PATH/bin/cache/dart-sdk/bin"
//Pub cache within Flutter SDK (where the protoc plugin will be located at)
export PATH="$PATH":"$FLUTTER_PATH/.pub-cache/bin"
//这个实际上是protoc-gen-dart,不过没生效
export PATH="$PATH":"$HOME/.pub-cache/bin"

Other commands
View the path of $HOME

echo $HOME

Will display /Users/macminihao

Guess you like

Origin blog.csdn.net/weixin_44911775/article/details/130327732
Recommended