protobuf-java 3.10.0 is not compatible with older Android versions

Created on 2 Oct 2019  路  11Comments  路  Source: protocolbuffers/protobuf

protobuf-java 3.10.0 uses some Java 8 features which makes it incompatible with Android builds where minSdk < O, even with desugaring enabled.

I realize that mobile clients are supposed to use protobuf lite, but some libraries (like Dialogflow client library) use protobuf-java internally, so we do not have a choice.

What did you do?
Steps to reproduce the behavior:

  1. Download and extract
    ProtobufTest.zip
  2. Run ./gradlew assembleDebug

What did you expect to see

I expected build to succeed, like with protobuf-java 3.9.2

What did you see instead?

Build crashes with MethodHandle.invoke and MethodHandle.invokeExact are only supported starting with Android O error.

Most helpful comment

3.11 will be released sometime next week.

All 11 comments

Thanks for reporting the issue and sorry for the trouble. We added those methods for performance reasons, but if it breaks Java 7 compatibility then we are willing to revert the changes. This might take a few days/weeks. Meanwhile, can you please use 3.9.2?

Does anyone here understand why this would break Java 7 compatibility when MethodHandle should be available in Java7? https://docs.oracle.com/javase/7/docs/api/java/lang/invoke/MethodHandle.html

@gmarcosb I think you are right, the issue is not Java 7 specific but rather Android specific. Looking at the Android docs, MethodHandle was added only starting from Android API level 26 (Android O): https://developer.android.com/reference/java/lang/invoke/MethodHandle

Caused by: com.android.builder.dexing.DexArchiveBuilderException: Error while dexing.
    at com.android.builder.dexing.D8DexArchiveBuilder.getExceptionToRethrow(D8DexArchiveBuilder.java:124)
    at com.android.builder.dexing.D8DexArchiveBuilder.convert(D8DexArchiveBuilder.java:101)
    at com.android.build.gradle.internal.tasks.DexFileDependenciesTask$DexFileDependenciesWorkerAction.run(DexFileDependenciesTask.kt:131)
    at com.android.build.gradle.internal.tasks.Workers$ActionFacade.run(Workers.kt:335)
    at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:41)
    at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1.execute(NoIsolationWorkerFactory.java:58)
    at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:44)
    at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:41)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:416)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:406)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
    at org.gradle.workers.internal.AbstractWorker.executeWrappedInBuildOperation(AbstractWorker.java:41)
    at org.gradle.workers.internal.NoIsolationWorkerFactory$1.execute(NoIsolationWorkerFactory.java:51)
    at org.gradle.workers.internal.DefaultWorkerExecutor$1.call(DefaultWorkerExecutor.java:107)
    at org.gradle.workers.internal.DefaultWorkerExecutor$1.call(DefaultWorkerExecutor.java:101)
    at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runExecution(DefaultConditionalExecutionQueue.java:215)
    at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runBatch(DefaultConditionalExecutionQueue.java:164)
    at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.run(DefaultConditionalExecutionQueue.java:131)
    ... 3 more
Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete
    at com.android.tools.r8.utils.t.a(:55)
    at com.android.tools.r8.D8.run(:11)
    at com.android.builder.dexing.D8DexArchiveBuilder.convert(D8DexArchiveBuilder.java:99)
    ... 23 more
Caused by: com.android.tools.r8.utils.AbortException: Error: MethodHandle.invoke and MethodHandle.invokeExact are only supported starting with Android O (--min-api 26)
    at com.android.tools.r8.utils.Reporter.a(:21)
    at com.android.tools.r8.utils.Reporter.a(:7)
    at com.android.tools.r8.utils.t.a(:36)
    ... 25 more

We are having this issue too. As like many others, we cannot set minSdkVersion in Android to 26, as this drastically impacts compatibility. Using 3.9.2 is okay for now, but we are expecting this to be fixed in coming releases.

This should be fixed by https://github.com/protocolbuffers/protobuf/pull/6752. Based on the timeline I'll see if it makes sense to do a 3.10.1 release with the fix, otherwise it will be included in 3.11 release.

This is now fixed at master, we will include it in the 3.11 release.

@rafi-kamal do you know the timeline of the 3.11 release? I don't see a milestone for it in the issue tracker.

3.11 will be released sometime next week.

I've uploaded 3.11.0-rc1 to Maven.

thanks all for this thread, indeed skipping to v 3.11.0 saved the day for me

Was this page helpful?
0 / 5 - 0 ratings