mapbox-java icon indicating copy to clipboard operation
mapbox-java copied to clipboard

Mapbox-java incompatible with gson 2.13.0 and up - call to internal GSON classes that were renamed

Open freszu opened this issue 6 months ago • 2 comments

Attempted upgrading GSON (for internal app use and third-party integration requiring a newer version), but encountered issues with mapbox-java. R8 began reporting missing classes due to the following reference:

https://github.com/mapbox/mapbox-java/blob/977651247bcd5dd642de1dd5fd3093d00152099b/services-geocoding/src/main/java/com/mapbox/api/geocoding/v5/SingleElementSafeListTypeAdapter.java#L6

The root cause is the renaming of internal classes in GSON version 2.13.0:

The internal classes $Gson$Types and $Gson$Preconditions have been renamed to remove the $ characters. Since these are internal classes (as signaled not only by the package name but by the $ characters), client code should not be affected. If your code was depending on these classes then we suggest making a copy of the class (subject to the license) rather than depending on the new names.

r8 error:

ERROR: Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in REDACTED/missing_rules.txt. ERROR: R8: Missing class com.google.gson.internal.$Gson$Types (referenced from: com.google.gson.TypeAdapter com.mapbox.api.geocoding.v5.SingleElementSafeListTypeAdapter$1.create(com.google.gson.Gson, com.google.gson.reflect.TypeToken))

freszu avatar Jul 07 '25 14:07 freszu

I'm encountering this too. Any workarounds?

LimmaPaulus avatar Aug 06 '25 06:08 LimmaPaulus

Ok, found a workaround myself.

Download the deleted file from Gson-repository history. You need both $Gson$Types.java and $Gson$Preconditions.java. Direct links to files before rename:

$Gson$Types.java $Gson$Preconditions.java

Then just add them to your project structure to the correct path:

Image

Mapbox authors: Please update the Gson dependency version asap

LimmaPaulus avatar Aug 06 '25 07:08 LimmaPaulus