PokeGOAPI-Java icon indicating copy to clipboard operation
PokeGOAPI-Java copied to clipboard

net.jpountz.lz4 (xxhash) dependency uses sun.misc.Unsafe methods therefore it fails in android

Open broach opened this issue 10 years ago • 13 comments

Description:

The dependency 'net.jpountz.lz4' uses unsafe methods which are not present in Android.

Steps to reproduce:

  1. Attempt to use API on Android
  2. 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

broach avatar Aug 07 '16 20:08 broach

Going to poke around and see if I can find something that's compat with Android.

broach avatar Aug 07 '16 20:08 broach

We could simply used safe implementation from this library. It will be a little slower, but... I'll do PR in a minute.

mgorski-mg avatar Aug 07 '16 20:08 mgorski-mg

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)

broach avatar Aug 07 '16 20:08 broach

id is using fastest implementation - if we will use safe implementation it will work. I checked it.

mgorski-mg avatar Aug 07 '16 20:08 mgorski-mg

Android also has a default implementation of xxhash: https://android.googlesource.com/platform/external/lz4/+/master/lib/xxhash.c

AbandonedCart avatar Aug 07 '16 20:08 AbandonedCart

@broach We arent using JNI, just the java impl of the encrypt function.

vmarchaud avatar Aug 07 '16 21:08 vmarchaud

@vmarchaud Cool ... sorry, I should have dug deeper before mentioning it.

broach avatar Aug 07 '16 21:08 broach

@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 :)

mgorski-mg avatar Aug 07 '16 21:08 mgorski-mg

I'll test it and comment.

broach avatar Aug 07 '16 21:08 broach

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.

AbandonedCart avatar Aug 07 '16 21:08 AbandonedCart

Commented on the PR, that does the trick. 👍

broach avatar Aug 07 '16 21:08 broach

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 avatar Aug 08 '16 01:08 MrPat

@MrPat it appears to be linked to the Async variants, ie. CatchablePokemonAsync()

AbandonedCart avatar Aug 08 '16 01:08 AbandonedCart