google / java-photoslibrary

Java client library for the Google Photos Library API
http://developers.google.com/photos
Apache License 2.0
107 stars 64 forks source link

Failure to initialize using R8 in full mode on Android #54

Closed samsonjs closed 1 year ago

samsonjs commented 1 year ago

We're using this library on Android and that tooling has been updated to enable R8's full optimization mode by default. This is causing a runtime failure when trying to use the SDK:

java.lang.ExceptionInInitializerError
    at com.google.api.gax.grpc.GaxGrpcProperties.getGrpcTokenName(Unknown Source:0)
    at com.google.photos.library.v1.internal.stub.PhotosLibraryStubSettings.defaultApiClientHeaderProviderBuilder(SourceFile:17)
    at com.google.photos.library.v1.internal.stub.PhotosLibraryStubSettings$Builder.createDefault(SourceFile:25)
    at com.google.photos.library.v1.internal.stub.PhotosLibraryStubSettings$Builder.access$400(Unknown Source:0)
    at com.google.photos.library.v1.internal.stub.PhotosLibraryStubSettings.newBuilder(SourceFile:1)
    at com.google.photos.library.v1.PhotosLibrarySettings$Builder.createDefault(Unknown Source:2)
    at com.google.photos.library.v1.PhotosLibrarySettings.newBuilder(Unknown Source:0)
    [... elided ...]
    at kotlinx.coroutines.scheduling.CoroutineScheduler$c.run(Unknown Source:0)
    Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [cn5{Cancelling}@59d8b6f, Dispatchers.IO]
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Package.getImplementationVersion()' on a null object reference
    at com.google.api.gax.core.GaxProperties.getLibraryVersion(SourceFile:1)
    at com.google.api.gax.core.GaxProperties.getLibraryVersion(SourceFile:3)
    at com.google.api.gax.grpc.GaxGrpcProperties.<clinit>(SourceFile:15)
    ... 31 more

The class loader isn't finding the package for com.google.photos.api.grpc.GaxGrpcProperties and there's a null-pointer exception in GaxProperties.getLibraryVersion(). I've confirmed that our app contains both of those classes so I'm at a loss as to why the class loader can't find it.

Any ideas or pointers would be very much appreciated if this isn't a bug in this library. I'm at a loss as to how to proceed.

CleanShot 2023-06-20 at 10 42 21@2x

CleanShot 2023-06-20 at 10 42 41@2x

samsonjs commented 1 year ago

Looks like one of our ProGuard rules for R8 is responsible for the problem here.