Search code examples
protoprotoc

How to run protoc correctly with different file import?


My main file to generate has these import :

import "protos/google_annotations.proto";
import "protos/nakama_annotations.proto";
import "protos/nakama_api.proto";

The folder structure :

├── lib
    ├── protos
         ├── google_annotations.proto
         ├── nakama_annotations.proto
         ├── nakama_api.proto
         ├── apigrpc.proto   <--- this is the file to generate.
    

The highlight syntax is ok.(Android studio)

The 2 cases that i got error are :

1.

  • Command run in protos directory

  • Run protoc apigrpc.proto --java_out=. --proto_path=.

  • Get this error

     protos/google_annotations.proto: File not found.
     protos/nakama_annotations.proto: File not found.
     protos/nakama_api.proto: File not found.
    
  1. Specify all import files
  • Command run in protos directory

  • Run

    protoc apigrpc.proto --java_out=. --proto_path=google_annotations.proto --proto_path=nakama_annotations.proto --proto_path=nakama_api.proto

  • Get this error apigrpc.proto: File does not reside within any path specified using --proto_path

What did i do wrong?


Solution

  • I just found what's wrong. It's about import.

    I have to remove the prefex protos because the import file is in the same level of directory.

    So the import become this :

    import "google_annotations.proto";
    import "nakama_annotations.proto";
    import "nakama_api.proto";
    

    The reason that I put protos in front before because the Android Studio plugin doesn't show red highlight when I put like that. Now After remove that, it highlight red, but it works.