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

Gson crashes when minified with R8 strict mode #634

Merged
merged 1 commit into from
Mar 7, 2023

Conversation

wiyarmir
Copy link
Contributor

@wiyarmir wiyarmir commented Feb 24, 2023

The proguard rules are not exhaustive enough, and crash when running R8 in strict mode.

Here <init>() is being accessed by reflection but not kept:

val bridgeCredentials = gson.fromJson(json, OptionalCredentials::class.java)

Example stacktrace:

java.lang.RuntimeException: Unable to create instance of class mdi.sdk.jr5. Registering an InstanceCreator or a TypeAdapter for this type, or adding a no-args constructor may fix this problem.
    com.google.gson.internal.ConstructorConstructor$16.construct(ConstructorConstructor.java:275)
    com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:211)
    com.auth0.android.request.internal.JsonRequiredTypeAdapterFactory$1.read(JsonRequiredTypeAdapterFactory.java:31)
    com.google.gson.TypeAdapter$1.read(TypeAdapter.java:199)
    com.google.gson.Gson.fromJson(Gson.java:991)
    com.google.gson.Gson.fromJson(Gson.java:956)
    com.google.gson.Gson.fromJson(Gson.java:905)
    com.google.gson.Gson.fromJson(Gson.java:876)
    com.auth0.android.authentication.storage.SecureCredentialsManager.continueGetCredentials$lambda-3(SecureCredentialsManager.java:436)
    com.auth0.android.authentication.storage.SecureCredentialsManager$$InternalSyntheticLambda$1$c09ebe59feb1659569cade6fd369c5089a7c5416c6136c04dd1d923283ecba7f$0.run(SecureCredentialsManager.java:85)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
    java.lang.Thread.run(Thread.java:1012)
Caused by: java.lang.UnsupportedOperationException: Abstract class can't be instantiated! Class name: mdi.sdk.jr5
    com.google.gson.internal.UnsafeAllocator.assertInstantiable(UnsafeAllocator.java:121)
    com.google.gson.internal.UnsafeAllocator$1.newInstance(UnsafeAllocator.java:49)
    com.google.gson.internal.ConstructorConstructor$16.construct(ConstructorConstructor.java:272)
    com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:211)
    com.auth0.android.request.internal.JsonRequiredTypeAdapterFactory$1.read(JsonRequiredTypeAdapterFactory.java:31)
    com.google.gson.TypeAdapter$1.read(TypeAdapter.java:199)
    com.google.gson.Gson.fromJson(Gson.java:991)
    com.google.gson.Gson.fromJson(Gson.java:956)
    com.google.gson.Gson.fromJson(Gson.java:905)
    com.google.gson.Gson.fromJson(Gson.java:876)
    com.auth0.android.authentication.storage.SecureCredentialsManager.continueGetCredentials$lambda-3(SecureCredentialsManager.java:436)
    com.auth0.android.authentication.storage.SecureCredentialsManager$$InternalSyntheticLambda$1$c09ebe59feb1659569cade6fd369c5089a7c5416c6136c04dd1d923283ecba7f$0.run(SecureCredentialsManager.java:85)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
    java.lang.Thread.run(Thread.java:1012)

Reproduced on AGP 7.4.0

Changes

Updated proguard rules to the ones suggested by Google.

References

Relevant Issue Tracker Bug

Testing

Build release version of app that uses SecureCredentialsManager and run.

Checklist

@wiyarmir wiyarmir requested a review from a team as a code owner February 24, 2023 21:40
@wiyarmir wiyarmir changed the title Gson Proguard issues starting AGP 3.6.0 Gson crashes when minified with R8 strict mode Feb 24, 2023
@poovamraj
Copy link
Contributor

Thanks @wiyarmir, this is a really nice contribution. I will approve the workflow and check it manually once before merging this to our main branch.

Copy link
Contributor

@poovamraj poovamraj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@poovamraj poovamraj merged commit 5ea1195 into auth0:main Mar 7, 2023
@poovamraj poovamraj added this to the 2.9.0 milestone Mar 16, 2023
This was referenced Mar 16, 2023
@wiyarmir wiyarmir deleted the patch-1 branch October 1, 2024 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants