Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.IllegalAccessError: class com.google.protobuf.GeneratedMessageV3 tried to access method 'boolean com.google.protobuf.CodedInputStream.shouldDiscardUnknownFields()' #19371

Closed
zgzong opened this issue Nov 23, 2024 · 14 comments
Labels

Comments

@zgzong
Copy link

zgzong commented Nov 23, 2024

What version of protobuf and what language are you using?
Version: protobuf-lite: version: 3.0.1
Language: java

What operating system (Linux, Windows, ...) and version?
Windows 11

What runtime / compiler are you using (e.g., python version or gcc version)
Running AndroidTest from Android studio v2023.3.1

What did you do?
Steps to reproduce the behavior:

  1. Config AndroidTest
  2. Click run on AndroidStudio

What did you expect to see
The AndroidTest can be launched on connected Android device and finish AndroidTest.

What did you see instead?
SEVERE: Fatal error while executing main with args: --proto_config=C:\Users\xxx.android\utp\runnerConfig969432027192655346.pb --proto_server_config=C:\Users\xxx.android\utp\serverConfig5384709628783943825.pb
java.lang.IllegalAccessError: class com.google.protobuf.GeneratedMessageV3 tried to access method 'boolean com.google.protobuf.CodedInputStream.shouldDiscardUnknownFields()

Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs).

Anything else we should know about your project / environment
Tried with connected device: Pixel Tablet, Pixel 6, 7, and 8 with varies android os.
I am rung android test with debug flavour build, which doesn't require proGuard/R8. Anyway, the following trick doesn't works for me.

-keep class com.google.protobuf.** {*;}
-keepclassmembers class * extends com.google.protobuf.GeneratedMessageLite {
;
}
-keepclassmembers class * extends com.google.protobuf.GeneratedMessageV3 {
;
}

@zgzong zgzong added the untriaged auto added to all issues by default when created. label Nov 23, 2024
@acozzette acozzette added java and removed untriaged auto added to all issues by default when created. labels Nov 25, 2024
@acozzette
Copy link
Member

Could you try using a recent version of protobuf-javalite instead of protobuf-lite?

@zgzong
Copy link
Author

zgzong commented Nov 26, 2024

@acozzette I tried with varied different version from protobuf-javalite. The project can't compile with following new issues.

image

@acozzette
Copy link
Member

@zgzong I suspect that your build is still using an old version of protoc. If you regenerate your code using a protoc version that matches the protobuf-javalite version then those errors should hopefully go away.

@zgzong
Copy link
Author

zgzong commented Nov 26, 2024

@acozzette
These compile error does go after align the protoc version with protobuf-javalite.
When use protoc & protobuf-javalite with 3.25.5, or 4.28.3 the original issue occurs.

java.lang.IllegalAccessError: class com.google.protobuf.GeneratedMessageV3 tried to access method 'boolean com.google.protobuf.CodedInputStream.shouldDiscardUnknownFields()' (com.google.protobuf.GeneratedMessageV3 is in unnamed module of loader java.net.URLClassLoader @4cd1c1dc; com.google.protobuf.CodedInputStream is in unnamed module of loader 'app') at com.google.protobuf.GeneratedMessageV3.parseUnknownField(GeneratedMessageV3.java:317) at com.android.server.adb.protos.AppProcessesProto$ProcessEntry.<init>(AppProcessesProto.java:119) at com.android.server.adb.protos.AppProcessesProto$ProcessEntry.<init>(AppProcessesProto.java:54) at com.android.server.adb.protos.AppProcessesProto$ProcessEntry$1.parsePartialFrom(AppProcessesProto.java:778) at com.android.server.adb.protos.AppProcessesProto$ProcessEntry$1.parsePartialFrom(AppProcessesProto.java:772) at com.google.protobuf.CodedInputStream$ArrayDecoder.readMessage(CodedInputStream.java:980) at com.android.server.adb.protos.AppProcessesProto$AppProcesses.<init>(AppProcessesProto.java:879) at com.android.server.adb.protos.AppProcessesProto$AppProcesses.<init>(AppProcessesProto.java:829) at com.android.server.adb.protos.AppProcessesProto$AppProcesses$1.parsePartialFrom(AppProcessesProto.java:1571) at com.android.server.adb.protos.AppProcessesProto$AppProcesses$1.parsePartialFrom(AppProcessesProto.java:1565) at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:111) at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:126) at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:20) at com.android.server.adb.protos.AppProcessesProto$AppProcesses.parseFrom(AppProcessesProto.java:1027) at com.android.ddmlib.internal.DeviceClientMonitorTask$TrackAppProcessor.onMessage(DeviceClientMonitorTask.java:585) at com.android.ddmlib.internal.DeviceClientMonitorTask$Processor.onBytesReceived(DeviceClientMonitorTask.java:501) at com.android.ddmlib.internal.DeviceClientMonitorTask.run(DeviceClientMonitorTask.java:281) at java.base/java.lang.Thread.run(Thread.java:840)

@acozzette
Copy link
Member

I think you must be somehow mixing multiple protobuf versions in the same program.

@sirius60111
Copy link

same issue here
I use Jetpack macrobenchmark testing my app
It works fine when I connect and test on an Android 13 device, but when I switch to an Android 15 device, this IllegalAccessError came out

Nov 27, 2024 5:41:13 PM com.android.tools.utp.plugins.host.apkinstaller.AndroidTestApkInstallerPlugin configure
INFO: No installables found in test fixture. Nothing to install.
Nov 27, 2024 5:41:13 PM com.google.testing.platform.plugin.android.AndroidDevicePlugin configure
INFO: No installables found in test fixture. Nothing to install.
Nov 27, 2024 5:41:13 PM com.google.testing.platform.main.MainKt$main$2 uncaughtException
SEVERE: Fatal error while executing main with args: --proto_config=/home/mi/.android/utp/runnerConfig7828165919515485024.pb --proto_server_config=/home/mi/.android/utp/serverConfig1928644563722895952.pb
java.lang.IllegalAccessError: class com.google.protobuf.GeneratedMessageV3 tried to access method 'boolean com.google.protobuf.CodedInputStream.shouldDiscardUnknownFields()' (com.google.protobuf.GeneratedMessageV3 is in unnamed module of loader java.net.URLClassLoader @4b4bfb48; com.google.protobuf.CodedInputStream is in unnamed module of loader 'app')
	at com.google.protobuf.GeneratedMessageV3.parseUnknownField(GeneratedMessageV3.java:317)
	at com.android.server.adb.protos.AppProcessesProto$ProcessEntry.<init>(AppProcessesProto.java:119)
	at com.android.server.adb.protos.AppProcessesProto$ProcessEntry.<init>(AppProcessesProto.java:54)
	at com.android.server.adb.protos.AppProcessesProto$ProcessEntry$1.parsePartialFrom(AppProcessesProto.java:778)
	at com.android.server.adb.protos.AppProcessesProto$ProcessEntry$1.parsePartialFrom(AppProcessesProto.java:772)
	at com.google.protobuf.CodedInputStream$ArrayDecoder.readMessage(CodedInputStream.java:980)
	at com.android.server.adb.protos.AppProcessesProto$AppProcesses.<init>(AppProcessesProto.java:879)
	at com.android.server.adb.protos.AppProcessesProto$AppProcesses.<init>(AppProcessesProto.java:829)
	at com.android.server.adb.protos.AppProcessesProto$AppProcesses$1.parsePartialFrom(AppProcessesProto.java:1571)
	at com.android.server.adb.protos.AppProcessesProto$AppProcesses$1.parsePartialFrom(AppProcessesProto.java:1565)
	at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:111)
	at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:126)
	at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:20)
	at com.android.server.adb.protos.AppProcessesProto$AppProcesses.parseFrom(AppProcessesProto.java:1027)
	at com.android.ddmlib.internal.DeviceClientMonitorTask$TrackAppProcessor.onMessage(DeviceClientMonitorTask.java:585)
	at com.android.ddmlib.internal.DeviceClientMonitorTask$Processor.onBytesReceived(DeviceClientMonitorTask.java:501)
	at com.android.ddmlib.internal.DeviceClientMonitorTask.run(DeviceClientMonitorTask.java:281)
	at java.base/java.lang.Thread.run(Thread.java:898)

@acozzette
Copy link
Member

Hmm, interesting. I see a very similar error reported here as well. I wonder if this may be a bug in the way Android uses protobuf. Let me dig into this some more and see if I can figure it out.

@acozzette
Copy link
Member

@zgzong @sirius60111 Are you able to reproduce this with the most recent version of Android Studio? It's possible that someone has already fixed it in the most recent version.

@acozzette
Copy link
Member

@zgzong @sirius60111 Actually could you do "Help -> Submit feedback" to submit a bug report in Android Studio and reference this GitHub issue? That should help reach the owners of the affected code.

@sirius60111
Copy link

sirius60111 commented Nov 28, 2024

@zgzong @sirius60111 Are you able to reproduce this with the most recent version of Android Studio? It's possible that someone has already fixed it in the most recent version.

@acozzette I run macrobenchmark test using command line
./gradlew --daemon clean :benchmark:connectedXXXBenchmarkAndroidTest
not click run button in Android Studio

@bnorth-cltd
Copy link

bnorth-cltd commented Nov 29, 2024

Hmm, interesting. I see a very similar error reported here as well. I wonder if this may be a bug in the way Android uses protobuf. Let me dig into this some more and see if I can figure it out.

Thanks @acozzette for linking to that issue. I followed the suggestion of someone there in upgrading Android Build Gradle plugin, and that fixed the issue for me (which I was also facing when running an Android instrumented test, same as OP). See my comment here for specifics on versions: leancodepl/patrol#2307 (comment).

@zgzong, could you try upgrading your Android Build Gradle plugin?

@sirius60111
Copy link

Hmm, interesting. I see a very similar error reported here as well. I wonder if this may be a bug in the way Android uses protobuf. Let me dig into this some more and see if I can figure it out.

Thanks @acozzette for linking to that issue. I followed the suggestion of someone there in upgrading Android Build Gradle plugin, and that fixed the issue for me (which I was also facing when running an Android instrumented test, same as OP). See my comment here for specifics on versions: leancodepl/patrol#2307 (comment).

@zgzong, could you try upgrading your Android Build Gradle plugin?

After upgrading the Android Gradle Plugin, the issue was resolved.
However, due to some internal restrictions, we cannot upgrade the Android Gradle Plugin to such a high version.
Are there any other solutions to this problem?

@zgzong
Copy link
Author

zgzong commented Dec 9, 2024

Thanks @acozzette @bnorth-cltd for shine the light.

Strange thing that I didn't see any AGP release notes mention same issue.
Anyway I tried upgrade AGP from 8.0.2 to 8.2.1, then the issue is not reproducible anymore.

@sirius60111 connectedXXXBenchmarkAndroidTest is same as run from gradle tasks from dropdown list.
I am not sure what's AGP version do you use at moment, maybe worth to try 8.2.1.

@bnorth-cltd
Copy link

Yeah, I'm not sure which version of AGP fixes the issue (maybe when they upgraded a protobuf dependency?). But it's good to hear that 8.2.1 resolves it.

@zgzong zgzong closed this as completed Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants