google / google/protobuf-gradle-plugin

Issue compiling protos...

Open
#758 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Groovy
Stars
1.8k
Forks
288
PR merge metrics
No merged PRs in 30d

Description

Hi, I am trying to build a simple android app that uses protocol buffers (and will try to move the protocol buffer code into an android library in the same project thereafter if successful).
Here is my build.gradle...

```
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.jetbrains.kotlin.android)
id "com.google.protobuf" version "0.9.4"
}

android {
namespace 'choice.dimension.new_protobuf_app'
compileSdk 34

defaultConfig {
applicationId "choice.dimension.new_protobuf_app"
minSdk 24
targetSdk 34
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion '1.5.1'
}
packaging {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}

dependencies {

implementation libs.androidx.core.ktx
implementation libs.androidx.lifecycle.runtime.ktx
implementation libs.androidx.activity.compose
implementation platform(libs.androidx.compose.bom)
implementation libs.androidx.ui
implementation libs.androidx.ui.graphics
implementation libs.androidx.ui.tooling.preview
implementation libs.androidx.material3
testImplementation libs.junit
androidTestImplementation libs.androidx.junit
androidTestImplementation libs.androidx.espresso.core
androidTestImplementation platform(libs.androidx.compose.bom)
androidTestImplementation libs.androidx.ui.test.junit4
debugImplementation libs.androidx.ui.tooling
debugImplementation libs.androidx.ui.test.manifest
api libs.protobuf.javalite
}

protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.0.0'
}
plugins {
javalite {
artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
}
}
generateProtoTasks {
all().each { task ->
task.builtins {
remove java
}
task.plugins {
javalite { }
}
}
}
}
```

and here is the output...

```
> Task :app:compileDebugJavaWithJavac FAILED
/home/cyril/AndroidStudioProjects/new_protobuf_app/app/build/generated/source/proto/debug/javalite/tutorial/PersonOuterClass.java:181: error: memoizedSerializedSize has private access in GeneratedMessageLite
int size = memoizedSerializedSize;
^
/home/cyril/AndroidStudioProjects/new_protobuf_app/app/build/generated/source/proto/debug/javalite/tutorial/PersonOuterClass.java:197: error: memoizedSerializedSize has private access in GeneratedMessageLite
memoizedSerializedSize = size;
^
/home/cyril/AndroidStudioProjects/new_protobuf_app/app/build/generated/source/proto/debug/javalite/tutorial/PersonOuterClass.java:395: error: an enum switch case label must be the unqualified name of an enumeration constant
case IS_INITIALIZED: {
^
/home/cyril/AndroidStudioProjects/new_protobuf_app/app/build/generated/source/proto/debug/javalite/tutorial/PersonOuterClass.java:398: error: an enum switch case label must be the unqualified name of an enumeration constant
case MAKE_IMMUTABLE: {
^
/home/cyril/AndroidStudioProjects/new_protobuf_app/app/build/generated/source/proto/debug/javalite/tutorial/PersonOuterClass.java:404: error: an enum switch case label must be the unqualified name of an enumeration constant
case VISIT: {
^
/home/cyril/AndroidStudioProjects/new_protobuf_app/app/build/generated/source/proto/debug/javalite/tutorial/PersonOuterClass.java:405: error: cannot find symbol
Visitor visitor = (Visitor) arg0;
^
symbol: class Visitor
location: class Person
/home/cyril/AndroidStudioProjects/new_protobuf_app/app/build/generated/source/proto/debug/javalite/tutorial/PersonOuterClass.java:405: error: cannot find symbol
Visitor visitor = (Visitor) arg0;
^
symbol: class Visitor
location: class Person
/home/cyril/AndroidStudioProjects/new_protobuf_app/app/build/generated/source/proto/debug/javalite/tutorial/PersonOuterClass.java:413: error: cannot find symbol
if (visitor == com.google.protobuf.GeneratedMessageLite.MergeFromVisitor
^
symbol: variable MergeFromVisitor
location: class GeneratedMessageLite
/home/cyril/AndroidStudioProjects/new_protobuf_app/app/build/generated/source/proto/debug/javalite/tutorial/PersonOuterClass.java:418: error: an enum switch case label must be the unqualified name of an enumeration constant
case MERGE_FROM_STREAM: {
^
Note: /home/cyril/AndroidStudioProjects/new_protobuf_app/app/build/generated/source/proto/debug/javalite/tutorial/PersonOuterClass.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
9 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
> Run with --info option to get more log output.
> Run with --scan to get full insights.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.7/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

BUILD FAILED in 1s
20 actionable tasks: 1 executed, 19 up-to-date
```

I would be grateful for any suggestions as to where I might be going wrong (if I have tried to do a similar thing with the kotlin DSL but had no luck) or let me know if you need any more information (gradle version is 8.7)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.