Proto File not found while running protoc

6,802 views
Skip to first unread message

ritesh singh

unread,
Feb 24, 2023, 12:39:59 PM2/24/23
to Protocol Buffers
I have 3 proto files in the current directory.

user_preferences.proto imports other protos and all are available in the same directory.

But, if i try to run this command, it throws an error. - Imported file not found.


protoc --include_imports --descriptor_set_out=/dev/stdout user_preferences.proto

Here, I am trying to invoke protoc with --descriptor_set_out to parse the proto file and convert it into a serialized FileDescriptorSet

Adam Cozzette

unread,
Feb 24, 2023, 2:04:51 PM2/24/23
to ritesh singh, Protocol Buffers
What do the import lines in user_preferences.proto look like? In your case the import paths should point to files relative to the current directory.

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/46f16320-f15b-4c79-a998-57b30e94751cn%40googlegroups.com.

ritesh singh

unread,
Feb 24, 2023, 2:11:13 PM2/24/23
to Protocol Buffers
It looks like this

syntax = "proto3";

import "com/google/samples/apps/nowinandroid/data/dark_theme_config.proto";
import "com/google/samples/apps/nowinandroid/data/theme_brand.proto";

option java_package = "com.google.samples.apps.nowinandroid.core.datastore";
option java_multiple_files = true;

message UserPreferences {
reserved 2;
repeated int32 deprecated_int_followed_topic_ids = 1;
int32 topicChangeListVersion = 3;
int32 authorChangeListVersion = 4;
int32 newsResourceChangeListVersion = 6;
repeated int32 deprecated_int_followed_author_ids = 7;
bool has_done_int_to_string_id_migration = 8;
repeated string deprecated_followed_topic_ids = 9;
repeated string deprecated_followed_author_ids = 10;
repeated string deprecated_bookmarked_news_resource_ids = 11;
bool has_done_list_to_map_migration = 12;

// Each map is used to store a set of string IDs. The bool has no meaning, but proto3 doesn't
// have a Set type so this is the closest we can get to a Set.
map<string, bool> followed_topic_ids = 13;
map<string, bool> followed_author_ids = 14;
map<string, bool> bookmarked_news_resource_ids = 15;

ThemeBrandProto theme_brand = 16;
DarkThemeConfigProto dark_theme_config = 17;

bool should_hide_onboarding = 18;

bool use_dynamic_color = 19;
}

ritesh singh

unread,
Feb 24, 2023, 2:11:39 PM2/24/23
to Protocol Buffers
If i remove imports, it works fine.

Adam Cozzette

unread,
Feb 24, 2023, 4:05:02 PM2/24/23
to ritesh singh, Protocol Buffers
Probably the cleanest solution would be to cd to the directory containing com/ and run protoc from there: protoc -I . --include_imports --descriptor_set_out=/dev/stdout com/google/samples/apps/nowinandroid/data/user_preferences.proto

Message has been deleted

ritesh singh

unread,
Feb 24, 2023, 7:12:28 PM2/24/23
to Protocol Buffers
This is resolved. Thanks.
Message has been deleted

ritesh singh

unread,
Feb 24, 2023, 10:31:50 PM2/24/23
to Protocol Buffers
I think it's not working with absolute path.

If my imports are like this

import "com/google/samples/apps/nowinandroid/data/dark_theme_config.proto";
import "com/google/samples/apps/nowinandroid/data/theme_brand.proto";



it wont work. But if it's relative it works

import "theme_brand.proto";
import "dark_theme_config.proto";

ritesh singh

unread,
Feb 26, 2023, 8:55:49 AM2/26/23
to Protocol Buffers
I was also wondering, if
 https://mvnrepository.com/artifact/com.google.protobuf/protoc can be used to do what above protoc command is doing? Because, to run the protoc command from my plugin, the user's machine needs to have the protoc compiler installed.

My idea is to just get the .proto file and .pb file and just generate the json using DynamicMessage, i don't want to go through the process of generating .java files  as i want this plugin be light.

ritesh singh

unread,
Feb 27, 2023, 2:29:48 PM2/27/23
to Protocol Buffers
I went through docs - and i guess importer can be used -  https://protobuf.dev/reference/cpp/api-docs/google.protobuf.compiler.importer/
But, this is not exposed as java api.

ritesh singh

unread,
Feb 27, 2023, 2:32:20 PM2/27/23
to Protocol Buffers
Unless, there's some option or way to execute it in java/kotlin without reying on user's machine. I believe https://github.com/os72/protoc-jar is the only option.
Reply all
Reply to author
Forward
0 new messages