googleapis / google-http-java-client

Google HTTP Client Library for Java
Apache License 2.0
1.39k stars 451 forks source link

Proguard/r8 instructions missing #1843

Open mtotschnig opened 1 year ago

mtotschnig commented 1 year ago

From the Readme, I am following Setup Instructions, then Android. Here it says "pay special attention to the Android instructions for ProGuard." but the referenced Proguard section does not exist. I have been using this library with R8 successfully in the past, but recently tried out full mode, and got following exception:

Non-fatal Exception: java.lang.ExceptionInInitializerError:
       at java.lang.Class.newInstance(Class.java)
       at com.google.api.client.util.Types.newInstance(Types.java:113)
       at com.google.api.client.util.Data.newMapInstance(Data.java:550)
       at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:766)
       at com.google.api.client.json.JsonParser.parse(JsonParser.java:360)
       at com.google.api.client.json.JsonParser.parse(JsonParser.java:335)
       at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:79)
       at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:73)
       at com.google.api.client.http.HttpResponse.parseAs(HttpResponse.java:460)
       at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:603)
       at org.totschnig.drive.sync.DriveServiceHelper.getFile(DriveServiceHelper.java:143)
       at org.totschnig.drive.sync.GoogleDriveBackendProvider.requireBaseFolder(GoogleDriveBackendProvider.kt:403)
       at org.totschnig.drive.sync.GoogleDriveBackendProvider.<init>(GoogleDriveBackendProvider.kt:420)
       at org.totschnig.drive.sync.GoogleDriveBackendProviderFactory.fromAccount(GoogleDriveBackendProviderFactory.kt:19)
       at org.totschnig.drive.sync.GoogleDriveBackendProviderFactory.fromAccount(GoogleDriveBackendProviderFactory.kt:12)
       at org.totschnig.myexpenses.sync.SyncBackendProviderFactory.from-0E7RQCE(SyncBackendProviderFactory.kt:18)
       at org.totschnig.myexpenses.sync.SyncBackendProviderFactory.access$from-0E7RQCE(SyncBackendProviderFactory.kt:12)
       at org.totschnig.myexpenses.sync.SyncBackendProviderFactory$Companion.get-0E7RQCE(SyncBackendProviderFactory.kt:41)
       at org.totschnig.myexpenses.sync.SyncAdapter.onPerformSync(SyncAdapter.kt:123)
       at android.content.AbstractThreadedSyncAdapter$SyncThread.run(AbstractThreadedSyncAdapter.java:354)

Caused by java.lang.IllegalArgumentException: unable to create new instance of class kc.a because it is abstract and because it has no accessible default constructor
       at com.google.api.client.util.Types.handleExceptionForNewInstance(Types.java:162)
       at com.google.api.client.util.Types.newInstance(Types.java:117)
       at com.google.api.client.util.Data.createNullInstance(Data.java:166)
       at com.google.api.client.util.Data.nullOf(Data.java:134)
       at com.google.api.services.drive.model.File.<clinit>(File.java:69)
       at java.lang.Class.newInstance(Class.java)
       at com.google.api.client.util.Types.newInstance(Types.java:113)
       at com.google.api.client.util.Data.newMapInstance(Data.java:550)
       at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:766)
       at com.google.api.client.json.JsonParser.parse(JsonParser.java:360)
       at com.google.api.client.json.JsonParser.parse(JsonParser.java:335)
       at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:79)
       at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:73)
       at com.google.api.client.http.HttpResponse.parseAs(HttpResponse.java:460)
       at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:603)
       at org.totschnig.drive.sync.DriveServiceHelper.getFile(DriveServiceHelper.java:143)
       at org.totschnig.drive.sync.GoogleDriveBackendProvider.requireBaseFolder(GoogleDriveBackendProvider.kt:403)
       at org.totschnig.drive.sync.GoogleDriveBackendProvider.<init>(GoogleDriveBackendProvider.kt:420)
       at org.totschnig.drive.sync.GoogleDriveBackendProviderFactory.fromAccount(GoogleDriveBackendProviderFactory.kt:19)
       at org.totschnig.drive.sync.GoogleDriveBackendProviderFactory.fromAccount(GoogleDriveBackendProviderFactory.kt:12)
       at org.totschnig.myexpenses.sync.SyncBackendProviderFactory.from-0E7RQCE(SyncBackendProviderFactory.kt:18)
       at org.totschnig.myexpenses.sync.SyncBackendProviderFactory.access$from-0E7RQCE(SyncBackendProviderFactory.kt:12)
       at org.totschnig.myexpenses.sync.SyncBackendProviderFactory$Companion.get-0E7RQCE(SyncBackendProviderFactory.kt:41)
       at org.totschnig.myexpenses.sync.SyncAdapter.onPerformSync(SyncAdapter.kt:123)
       at android.content.AbstractThreadedSyncAdapter$SyncThread.run(AbstractThreadedSyncAdapter.java:354)

Caused by java.lang.InstantiationException: java.lang.Class<kc.a> cannot be instantiated
       at java.lang.Class.newInstance(Class.java)
       at com.google.api.client.util.Types.newInstance(Types.java:113)
       at com.google.api.client.util.Data.createNullInstance(Data.java:166)
       at com.google.api.client.util.Data.nullOf(Data.java:134)
       at com.google.api.services.drive.model.File.<clinit>(File.java:69)
       at java.lang.Class.newInstance(Class.java)
       at com.google.api.client.util.Types.newInstance(Types.java:113)
       at com.google.api.client.util.Data.newMapInstance(Data.java:550)
       at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:766)
       at com.google.api.client.json.JsonParser.parse(JsonParser.java:360)
       at com.google.api.client.json.JsonParser.parse(JsonParser.java:335)
       at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:79)
       at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:73)
       at com.google.api.client.http.HttpResponse.parseAs(HttpResponse.java:460)
       at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:603)
       at org.totschnig.drive.sync.DriveServiceHelper.getFile(DriveServiceHelper.java:143)
       at org.totschnig.drive.sync.GoogleDriveBackendProvider.requireBaseFolder(GoogleDriveBackendProvider.kt:403)
       at org.totschnig.drive.sync.GoogleDriveBackendProvider.<init>(GoogleDriveBackendProvider.kt:420)
       at org.totschnig.drive.sync.GoogleDriveBackendProviderFactory.fromAccount(GoogleDriveBackendProviderFactory.kt:19)
       at org.totschnig.drive.sync.GoogleDriveBackendProviderFactory.fromAccount(GoogleDriveBackendProviderFactory.kt:12)
       at org.totschnig.myexpenses.sync.SyncBackendProviderFactory.from-0E7RQCE(SyncBackendProviderFactory.kt:18)
       at org.totschnig.myexpenses.sync.SyncBackendProviderFactory.access$from-0E7RQCE(SyncBackendProviderFactory.kt:12)
       at org.totschnig.myexpenses.sync.SyncBackendProviderFactory$Companion.get-0E7RQCE(SyncBackendProviderFactory.kt:41)
       at org.totschnig.myexpenses.sync.SyncAdapter.onPerformSync(SyncAdapter.kt:123)
       at android.content.AbstractThreadedSyncAdapter$SyncThread.run(AbstractThreadedSyncAdapter.java:354)
suztomo commented 1 year ago

Would you share the background of the problem? Which Google service were you trying to use?

mtotschnig commented 8 months ago

@suztomo Sorry for not following-up. I am using the Google Drive API, and was able to fix the problem by adding

-keep class com.google.api.services.drive.model.* { ; }

So the crash I mentioned does not belong here, but my point about the misleading documentation seems still valid to me.

suztomo commented 8 months ago

Thank you for update. Glad to hear you've resolved the problem.