net.jpountz.lz4 (xxhash) dependency uses sun.misc.Unsafe methods therefore it fails in android
Description:
The dependency 'net.jpountz.lz4' uses unsafe methods which are not present in Android.
Steps to reproduce:
- Attempt to use API on Android
- Look at logcat
Expected behavior: It should work :)
Actual behavior: Fatal exception due to sun,misc.Unsafe method not present on Android
Stacktrace (If it's a crash): 08-07 14:23:49.019 4590-5031/net.mostlyharmless.pokemontracker E/AndroidRuntime: FATAL EXCEPTION: Async HTTP Thread Process: net.mostlyharmless.pokemontracker, PID: 4590 java.lang.NoSuchMethodError: No virtual method getByte(Ljava/lang/Object;J)B in class Lsun/misc/Unsafe; or its super classes (declaration of 'sun.misc.Unsafe' appears in /system/framework/core-libart.jar) at net.jpountz.util.UnsafeUtils.readByte(UnsafeUtils.java:68) at net.jpountz.xxhash.StreamingXXHash32JavaUnsafe.getValue(StreamingXXHash32JavaUnsafe.java:49) at com.pokegoapi.util.Signature.getLocationHash1(Signature.java:88) at com.pokegoapi.util.Signature.setSignature(Signature.java:39) at com.pokegoapi.main.RequestHandler.internalSendServerRequests(RequestHandler.java:179) at com.pokegoapi.main.RequestHandler.internalSendServerRequests(RequestHandler.java:221) at com.pokegoapi.main.RequestHandler.run(RequestHandler.java:290) at java.lang.Thread.run(Thread.java:818)
Version: 0.3.0
Going to poke around and see if I can find something that's compat with Android.
We could simply used safe implementation from this library. It will be a little slower, but... I'll do PR in a minute.
Looking at the github repo, this is using JNI; whatever that artifact is that's coming down from Jcenter is ... it's compiled for a single platform. (Or maybe it includes multiple? I guess I should look in the artifact)
id is using fastest implementation - if we will use safe implementation it will work. I checked it.
Android also has a default implementation of xxhash: https://android.googlesource.com/platform/external/lz4/+/master/lib/xxhash.c
@broach We arent using JNI, just the java impl of the encrypt function.
@vmarchaud Cool ... sorry, I should have dug deeper before mentioning it.
@LoungeKatt I know, but it will require to change implementation just for Android builds. Look at this PR https://github.com/Grover-c13/PokeGOAPI-Java/pull/501. If it is good for authors we could merge it :)
I'll test it and comment.
I was only talking about changing to a library that doesn't use Sun, as there is a lot of documentation about Sun package support depending on the Java build, platform, etc. Nothing else has been hosted on bintray, though.
Commented on the PR, that does the trick. 👍
I'm running on Android and haven't seen warnings or a crash yet from this. Of course I only use the API to scan for Pokemon.
@MrPat it appears to be linked to the Async variants, ie. CatchablePokemonAsync()