NoClassDefFoundError with Mapsforge 0.4.0 and Eclipse

…衆ロ難τιáo~ 提交于 2019-12-01 08:10:25

问题


I am trying to add a map view to my application using Mapsforge. I have done the following:

  • Downloaded jar files and placed them in the libs/ folder
    • mapsforge-core-0.4.0.jar
    • mapsforge-map-0.4.0.jar
    • mapsforge-map-android-0.4.0.jar
    • mapsforge-map-reader-0.4.0.jar
  • Right-clicked file and selected Build Path > Add to Build Path.
  • In Project Properties, marked the four jars as exported.

However, when I run my app, it crashes on the first call to a class from the library:

E/AndroidRuntime(21265): java.lang.NoClassDefFoundError: org.mapsforge.map.android.graphics.AndroidGraphicFactory

Android SDK tools are all above version 17. No Maven involved.

I've been searching for an answer, but to no avail. I've tried moving the jars up in the list, cleaning the project – this and the things I did already are the essence of what's being suggested on the net. Nothing helped.

When I examine the contents of bin/dexedLibs, I notice that jars for mapsforge were created but are virtually empty, except for the manifest file and (in the case of the maps jar) the osmarender resources. Notably, the classes.dex file is absent. The Android support library in that folder contains a classes.dex file.

Any clues?

EDIT: I examined the original jar files. When looking at the .class files, I noticed each of them starts with CA FE BA BE 00 00 00 33, i.e. is in Java 7 format.

According to some of the information I found on the net, Java 7 is not supported by Android SDK. Is that still the case? This would explain why nothing works but would make me wonder why the Mapsforge devs would use Java 7 to compile a jar that is to be used with Android...


回答1:


NoClassDefFound is really a hard Exception to solve,a workaround you can try.

workaroud: Java Build Path -> Oeder and Export -> make sur 3rd.jar above yourPath/src

I know android support java7, only when you use the version above 19.




回答2:


@Ninja pointed me in the right direction but I'll post the detailed steps here.

Short answer: You need version 19 or higher of the Android toolchain, as that version introduced the Java 7 support needed to build against the prebuilt Mapsforge 0.4.0 libraries.

How to update:

  • Start ADT. Update all installed packages and additionally select at least one version of Android SDK Build-tools that is 19 or higher. (You can have multiple versions of the Android SDK Build-tools installed alongside each other.)
  • Now open Eclipse and select Help > Check for Updates from the menu.
    • If you get an error message that no software sources are available, go to Help > Install new software. In the dialog, click Add and add a new repository named ADT Plugin, URL https://dl-ssl.google.com/android/eclipse/. Then retry.
  • Restart Eclipse when prompted to do so.
  • Setting the compiler compliance level turned out not to be necessary in my case (I left it at 1.6).

With these steps my Mapsforge project works – I can display a map and the NoClassDefFoundError is gone.



来源:https://stackoverflow.com/questions/23587939/noclassdeffounderror-with-mapsforge-0-4-0-and-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!