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

How to use a later version than mapsforge 0.8.0 with the latest (6.0.3) version of osmdroid-mapsforge? #1265

Closed
TomasJohansson opened this Issue Feb 13, 2019 · 15 comments

Comments

Projects
None yet
5 participants
@TomasJohansson
Copy link

TomasJohansson commented Feb 13, 2019

Issue Type

[x] Question
[x] Bug
[x] Improvement (supporting later version of mapsforge)
[ ] Build system related
[ ] Performance
[x] Documentation

If it's a bug, version(s) of android this affects:

All

Version of osmdroid the issue relates to:

6.0.3
when using osmdroid-mapsforge 6.0.3 together with mapsforge 0.9+ (0.10 is currently the latest)

Description and/or steps/code to reproduce the problem

Try to use osmdroid with mapsforge as it is documented here:
https://github.com/osmdroid/osmdroid/wiki/Mapsforge
but with the current latest versions of mapsforge and osmdroid i.e. this gradle configurations:

    implementation 'org.osmdroid:osmdroid-android:6.0.3'
    implementation 'org.osmdroid:osmdroid-mapsforge:6.0.3'
    implementation 'org.mapsforge:mapsforge-themes:0.10.0'
    implementation 'org.mapsforge:mapsforge-map-android:0.10.0'
    implementation 'org.mapsforge:mapsforge-map:0.10.0'

Quote from the above documentation page:

//super important to configure some of the mapsforge settings first in your activity onCreate:
MapsForgeTileSource.createInstance(this.getApplication());

The implementation of the above method "MapsForgeTileSource.createInstance" (in osmdroid-mapsforge version 6.0.3) will invoke this method:
org.mapsforge.map.reader.ReadBuffer.setMaximumBufferSize
which does not exist in version 0.9.0 of mapsforge-map-reader (nor in version 0.10.0)

Therefore the result becomes:
java.lang.NoSuchMethodError: No static method setMaximumBufferSize(I)V in class Lorg/mapsforge/map/reader/ReadBuffer; or its super classes (declaration of 'org.mapsforge.map.reader.ReadBuffer'

The method ReadBuffer.setMaximumBufferSize seem to have been removed from mapsforge in september 2017:
mapsforge/mapsforge@c755db6#diff-77b9f5256e13803ec9ab28654633fd5a
mapsforge/mapsforge#994

So, obviously it is not possible to use "MapsForgeTileSource.createInstance" which is currently described as "super important" in the above linked documentation page.
On the other hand, that documentation may have not been updated, and maybe there is some other way to use the latest osmdroid with a later version than mapsforge 0.8.0 ?

@spyhunter99

This comment has been minimized.

Copy link
Collaborator

spyhunter99 commented Feb 14, 2019

i think there was some work update this a while ago. the maps forge folks changed their apis around significantly i don't think i ever got it working with a 0.8 version. Something related to theme resource files IIRC

@spyhunter99

This comment has been minimized.

Copy link
Collaborator

spyhunter99 commented Feb 15, 2019

@spyhunter99

This comment has been minimized.

Copy link
Collaborator

spyhunter99 commented Feb 15, 2019

i do have a stash of an attempt to update to 0.10.0 but it definitely didn't work and wasn't a straight forward update due to the api changes and no clear path forward

@TomasJohansson

This comment has been minimized.

Copy link
Author

TomasJohansson commented Feb 16, 2019

i don't think i ever got it working with a 0.8 version

Do you mean osmdroid does not work properly with mapsforge 0.8 ?
Or was it a typing error i.e. you meant it works with 0.8 but you never got it working with a 0.9+ version?

@spyhunter99

This comment has been minimized.

Copy link
Collaborator

spyhunter99 commented Feb 16, 2019

i don't remember honestly. i know have the stash for the attempt at 0.10.

@TomasJohansson

This comment has been minimized.

Copy link
Author

TomasJohansson commented Feb 16, 2019

osmdroid 6.0.1 should work with mapsforge 0.8.0 since @MKergall added that version combination into the documentation revision ea98bfb
https://github.com/osmdroid/osmdroid/wiki/Mapsforge/_history
Of course there is no guarantee for that since docs may have bugs but there should have been a reason for those version numbers in the documentation.
(i.e. the reason should be that those two versions was actually tested together)

@MKergall

This comment has been minimized.

Copy link
Collaborator

MKergall commented Feb 18, 2019

I tested again, and I confirm that osmdroid 6.0.3 works (fine) with mapsforge 0.8.0.

Important warning: mapsforge 0.8.0 means using mapsforge maps in v4 format (v5 format has been introduced with mapsforge 0.10.0)

Upgrading upcoming osmdroid release to mapsforge 0.10.0 would be a good point.

monsieurtanuki added a commit that referenced this issue Feb 20, 2019

bug/#1265 - switching to mapsforge 0.10.0 (from 0.8.0)
Impacted files:
* `MapsForgeTileSource.java`: removed the call to `ReadBuffer.setMaximumBufferSize` in `createInstance`
* `osmdroid-mapsforge/build.gradle`: now using version `0.10.0` of mapsforge
@monsieurtanuki

This comment has been minimized.

Copy link
Collaborator

monsieurtanuki commented Feb 20, 2019

@TomasJohansson I've just PR'ed #1275, that switches to mapsforge 0.10.0 and removes the ReadBuffer.setMaximumBufferSize line.
I don't know very much about MapsForge, but the little code sample I use for #1145 works.
Feel free to test it, tell us what you think, and then it will be included in the next osmdroid version.

@monsieurtanuki monsieurtanuki self-assigned this Feb 20, 2019

@MKergall

This comment has been minimized.

Copy link
Collaborator

MKergall commented Feb 20, 2019

@monsieurtanuki Thanks a lot!

@monsieurtanuki

This comment has been minimized.

Copy link
Collaborator

monsieurtanuki commented Feb 20, 2019

@MKergall Had time to test it? Should I merge, then?

@TomasJohansson

This comment has been minimized.

Copy link
Author

TomasJohansson commented Feb 21, 2019

@TomasJohansson I've just PR'ed #1275, that switches to mapsforge 0.10.0 and removes the ReadBuffer.setMaximumBufferSize line.
I don't know very much about MapsForge, but the little code sample I use for #1145 works.
Feel free to test it, tell us what you think, and then it will be included in the next osmdroid version.

Okay I have now tested to use the code in PR #1275 (i.e. using mapsforge 0.10.0 dependencies with the only java code difference that the invocation of ReadBuffer.setMaximumBufferSize has been removed).

It seems to work. Although I have not tested everything that might be tested, but I have just tested a small experimental app with my tablet, using mapsforge maps with many of the features mentioned at "How to use the osmdroid library
" and "Markers, Lines and Polygons" .
At least the same things work with 0.10.0 (with removed ReadBuffer.setMaximumBufferSize) as worked for me when using mapsforge 0.8.0.

It was a bit surprising to me though that it seems to work with such a small code change considering what was written above regarding it wasn't a straight forward update due to the api changes and no clear path forward.
Anyway I can close this issue now.

monsieurtanuki added a commit that referenced this issue Feb 23, 2019

Merge pull request #1275 from osmdroid/bug/#1265
bug/#1265 - switching to mapsforge 0.10.0 (from 0.8.0)
@monsieurtanuki

This comment has been minimized.

Copy link
Collaborator

monsieurtanuki commented Feb 23, 2019

@TomasJohansson Thank you for your test, in first approach it's good enough for a "go!". Is that a 100% perfect update path: I don't think so, but that will do for the moment.
If later you find issues with this osmdroid vs. mapsforge 0.10.0 combination, that will be dealt with in new issues.

@k3b

This comment has been minimized.

Copy link
Contributor

k3b commented Mar 12, 2019

Same situation here:

try to use mapsforge 0.10.0 with org.osmdroid:osmdroid-mapsforge:6.0.3:

As a workaround I tried to use proguard-rues.pro to remove the call as explainded in https://www.guardsquare.com/proguard/manual/examples#logging with

 -assumenosideeffects class org.mapsforge.map.reader.ReadBuffer { 
     public void setMaximumBufferSize(...); }

but got

Warning: org.osmdroid.mapsforge.MapsForgeTileSource: can't find referenced method 
'void setMaximumBufferSize(int)' in program class org.mapsforge.map.reader.ReadBuffer
Warning: there were 1 unresolved references to program class members.
		 Your input classes appear to be inconsistent.
		 You may need to recompile the code.

Any idea how to fix this with proguard while the next osmdroid-release 0.6.0.4 with #1265 (or later) is not available yet?

@TomasJohansson

@monsieurtanuki

This comment has been minimized.

Copy link
Collaborator

monsieurtanuki commented Mar 13, 2019

Disclaimer: I'm a bit confused in general with gradle stuff.

If the problem is only at run time, that would make sense to:

  • copy the 3 "osmdroid x MapsForge" classes (MapsForgeTileModuleProvider, MapsForgeTileProvider and MapsForgeTileSource) into your project (latest version available in osmdroid)
  • use whatever version of MapsForge is relevant for your app
  • use the 3 copied classes, that don't include the ReadBuffer.setMaximumBufferSize part
@k3b

This comment has been minimized.

Copy link
Contributor

k3b commented Mar 14, 2019

the problem occurs when obfuscating which also warns about unresolved dependencies.

you solution is simple and effective. i will try it.

thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.