Osmdroid 5.1 java.lang.NoClassDefFoundError

Osmdroid 5.1 java.lang.NoClassDefFoundError

我什至无法创建简单的地图。我正在使用 osmdroid-android-5.1 库,据我了解,我不需要从 5.0 及更高版本添加 slf4j 库。

我的activity_main.xml如下:

<include
    layout="@layout/app_bar_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_main"
    app:menu="@menu/activity_main_drawer" />

content_main.xml 包含如下地图:

<org.osmdroid.views.MapView android:id="@+id/map"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    tilesource="Mapnik" />

我的AndroidManifest.xml如下:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

当我点击 activity_main 预览时,出现错误:

java.lang.NoClassDefFoundError: Could not initialize class org.osmdroid.tileprovider.constants.OpenStreetMapTileProviderConstants
    at org.osmdroid.tileprovider.MapTileProviderArray.getMapTile(MapTileProviderArray.java:93)
    at org.osmdroid.views.overlay.TilesOverlay.handleTile(TilesOverlay.java:185)
    at org.osmdroid.util.TileLooper.loop(TileLooper.java:34)
    at org.osmdroid.views.overlay.TilesOverlay.drawTiles(TilesOverlay.java:164)
    at org.osmdroid.views.overlay.TilesOverlay.draw(TilesOverlay.java:151)
    at org.osmdroid.views.overlay.DefaultOverlayManager.onDraw(DefaultOverlayManager.java:107)
    at org.osmdroid.views.MapView.dispatchDraw(MapView.java:1008)
    at android.view.View.draw(View.java:16088)
    at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3609)
    at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:61)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
    at android.view.View.draw(View.java:16088)
    at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3609)
    at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:61)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
    at android.support.design.widget.CoordinatorLayout.drawChild(CoordinatorLayout.java:1077)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
    at android.view.View.draw(View.java:16181)
    at android.view.View.draw(View.java:16090)
    at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3609)
    at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:61)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
    at android.support.v4.widget.DrawerLayout.drawChild(DrawerLayout.java:1229)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
    at android.view.View.draw(View.java:16181)
    at android.view.View.draw(View.java:16090)
    at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3609)
    at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:61)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
    at android.view.View.draw(View.java:16088)
    at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3609)
    at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:61)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
    at android.view.View.draw(View.java:16088)
    at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3609)
    at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:61)
    at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
    at android.view.View.draw(View.java:16181)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.render(RenderSessionImpl.java:431)
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:428)
    at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:350)
    at com.android.tools.idea.rendering.RenderTask.compute(RenderTask.java:510)
    at com.android.tools.idea.rendering.RenderTask.compute(RenderTask.java:498)
    at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:888)
    at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:498)
    at com.android.tools.idea.rendering.RenderTask.access0(RenderTask.java:72)
    at com.android.tools.idea.rendering.RenderTask.call(RenderTask.java:610)
    at com.android.tools.idea.rendering.RenderTask.call(RenderTask.java:607)
    at com.android.tools.idea.rendering.RenderService.runRenderAction(RenderService.java:362)
    at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:607)
    at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:629)
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.doRender(AndroidLayoutPreviewToolWindowManager.java:652)
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.access00(AndroidLayoutPreviewToolWindowManager.java:80)
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.run(AndroidLayoutPreviewToolWindowManager.java:594)
    at com.intellij.openapi.progress.impl.CoreProgressManager.run(CoreProgressManager.java:152)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:452)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:402)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:54)
    at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:137)
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.run(AndroidLayoutPreviewToolWindowManager.java:589)
    at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:320)
    at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:310)
    at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:254)
    at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:269)
    at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:227)
    at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:217)
    at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
    at com.intellij.util.Alarm$Request.run(Alarm.java:351)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

知道错误可能在哪里并且无法实现如此简单的事情(除非我没有看到任何明显的东西)吗?

osmdroid 不提供 intellij 试图呈现的 "preview"。常量 class 正在尝试扫描本地存储以用作下载缓存。它可能可以更好地处理。

无论如何,要解决您的问题,只需点击播放按钮并 运行 应用程序。它应该在 android 设备或​​模拟器

上正常工作