Graphhopper: GraphHopper crash on Android 4.1

Created on 19 Dec 2016  路  9Comments  路  Source: graphhopper/graphhopper

Sample crashes on Android 4.1 at application exit with the following exception:

Caused by: java.lang.IllegalArgumentException: expected receiver of type java.nio.DirectByteBuffer, but got java.nio.MappedByteBufferAdapter
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at com.graphhopper.util.Helper$1.run(Helper.java:377)
   at java.security.AccessController.doPrivileged(AccessController.java:60)
   at com.graphhopper.util.Helper.cleanMappedByteBuffer(Helper.java:366)
   at com.graphhopper.storage.MMapDataAccess.clean(MMapDataAccess.java:356)
   at com.graphhopper.storage.MMapDataAccess.close(MMapDataAccess.java:257)
   at com.graphhopper.storage.MMapDataAccess.close(MMapDataAccess.java:249)
   at com.graphhopper.storage.StorableProperties.close(StorableProperties.java:113)
   at com.graphhopper.storage.GraphHopperStorage.close(GraphHopperStorage.java:277)
   at com.graphhopper.GraphHopper.close(GraphHopper.java:1222)
android bug

All 9 comments

I think this is related to #852 where I was hoping to get 'freeing' support for Android. See here

Would you mind to try if using java.nio.MappedByteBufferAdapter instead of Class.forName("java.nio.DirectByteBuffer") works? It should have a free method too.

(it was reported in Cruiser forum - I should test more often older Android versions :slightly_frowning_face: )

Is cruiser using the latest master? (I guess, yes)

I should test more often older Android versions

Ah, so newer versions work with this code. Interesting.

java.nio.MappedByteBufferAdapter isn't public right?

Yes, it is package protected. But with reflection we might still get it via dbbFreeMethod.setAccessible(true);?

Using Class.forName("java.nio.MappedByteBufferAdapter") seems to work.

Is cruiser using the latest master? (I guess, yes)

Yes Cruiser always uses latest master of Mapsforge / VTM / GraphHopper! :slightly_smiling_face:

Ah, so newer versions work with this code. Interesting.

I tested backwards to Android 5 and works, not checked on what version exactly the crash starts happening.

But java.nio.MappedByteBufferAdapter does not work on desktop with e.g. Java 8 (Oracle) due to:

java.lang.ClassNotFoundException: java.nio.MappedByteBufferAdapter

Can you have a look if the commit in branch android_bug_914 fixes the problem and still runs on newer Android versions?

But java.nio.MappedByteBufferAdapter does not work on desktop with e.g. Java 8 (Oracle) due to:

This was just a quick hack and the commit should make it working everywhere - at least I hope so.

I checked android_bug_914 branch on Android (latest & older) and on desktop and buffers clean seems working fine!

Merged

With #934 we use the JDK8 approach for all Android versions except if the buffer is of type MappedByteBufferAdapter

Was this page helpful?
0 / 5 - 0 ratings

Related issues

karussell picture karussell  路  7Comments

michaz picture michaz  路  7Comments

karussell picture karussell  路  3Comments

devemux86 picture devemux86  路  5Comments

karussell picture karussell  路  9Comments