Protoc compiler error for multiple imports

232 views
Skip to first unread message

ritesh singh

unread,
May 22, 2023, 10:27:53 AM5/22/23
to Protocol Buffers
Here's how my protofile looks like in the same directory

userpreference.proto

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 {
    ThemeBrandProto theme_brand = 16;
    DarkThemeConfigProto dark_theme_config = 17;
}


dark_theme_config.proto

syntax = "proto3";

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

enum DarkThemeConfigProto {
  DARK_THEME_CONFIG_UNSPECIFIED = 0;
  DARK_THEME_CONFIG_FOLLOW_SYSTEM = 1;
  DARK_THEME_CONFIG_LIGHT = 2;
  DARK_THEME_CONFIG_DARK = 3;
}

Running protoc compiler

protoc -I . --include_imports --descriptor_set_out=/dev/stdout google/samples/apps/nowinandroid/data/user_preferences.proto

errors out and gives me this error

com/google/samples/apps/nowinandroid/data/dark_theme_config.proto: File not found.

com/google/samples/apps/nowinandroid/data/theme_brand.proto: File not found.

user_preferences.proto:19:1: Import "com/google/samples/apps/nowinandroid/data/dark_theme_config.proto" was not found or had errors.

user_preferences.proto:20:1: Import "com/google/samples/apps/nowinandroid/data/theme_brand.proto" was not found or had errors.

user_preferences.proto:44:5: "ThemeBrandProto" is not defined.

user_preferences.proto:45:5: "DarkThemeConfigProto" is not defined.



But, if i change userpreferences imports from this

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

to

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

works fine

ritesh singh

unread,
May 22, 2023, 10:30:45 AM5/22/23
to Protocol Buffers
Any leads on it, the protoc compiler is hooked with the IDE plugin i am writing and i am hoping it to work on any kind of imports.

Just to add on - changing the imports to 

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

fixes the protoc error but the project fails to compile, with error

Caused by: org.gradle.api.GradleException: protoc: stdout: . stderr: theme_brand.proto: File not found.
dark_theme_config.proto: File not found.
com/google/samples/apps/nowinandroid/data/user_preferences.proto:18:1: Import "theme_brand.proto" was not found or had errors.
com/google/samples/apps/nowinandroid/data/user_preferences.proto:19:1: Import "dark_theme_config.proto" was not found or had errors.
com/google/samples/apps/nowinandroid/data/user_preferences.proto:45:5: "ThemeBrandProto" seems to be defined in "com/google/samples/apps/nowinandroid/data/theme_brand.proto", which is not imported by "com/google/samples/apps/nowinandroid/data/user_preferences.proto".  To use it here, please add the necessary import.
com/google/samples/apps/nowinandroid/data/user_preferences.proto:46:5: "DarkThemeConfigProto" seems to be defined in "com/google/samples/apps/nowinandroid/data/dark_theme_config.proto", which is not imported by "com/google/samples/apps/nowinandroid/data/user_preferences.proto".  To use it here, please add the necessary import.

ritesh singh

unread,
May 23, 2023, 5:03:55 AM5/23/23
to Protocol Buffers
Fixed. Thanks!
Reply all
Reply to author
Forward
0 new messages