Android项目上的NoClassDefFoundError

时间:2014-02-25 16:14:23

标签: java android eclipse mapsforge

我有这个问题,我无法理解如何解决。我使用maven在eclipse中导入了一个map forge项目,但如果尝试在设备上加载项目,我会收到此错误。 但我知道那个班级在项目中。我该如何解决这个问题?

我正在使用Mapsforge rescue 4.0库。 我使用相同的方法导入Mapsforge 0.31,一切正常。

    02-25 16:46:03.202: E/AndroidRuntime(6370): java.lang.NoClassDefFoundError: org.mapsforge.map.android.graphics.AndroidGraphicFactory

这是应用程序的pom.xml。

    <?xml version="1.0" encoding="UTF-8"?>

http://maven.apache.org/xsd/maven-4.0.0.xsd“&GT;     4.0.0              org.mapsforge         mapsforge         0.4.0-SNAPSHOT         ../../../pom.xml     

<artifactId>Samples</artifactId>
<packaging>apk</packaging>

<properties>
    <rootDirectory>../../../</rootDirectory>
    <targetJdk>1.6</targetJdk>
</properties>

<build>
    <plugins>
        <plugin>
            <groupId>com.jayway.maven.plugins.android.generation2</groupId>
            <artifactId>android-maven-plugin</artifactId>
            <configuration>
                <dex>
                    <jvmArguments>
                        <jvmArgument>-Xmx512M</jvmArgument>
                    </jvmArguments>
                </dex>
            </configuration>
            <extensions>true</extensions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-eclipse-plugin</artifactId>
            <configuration>
                <useProjectReferences>false</useProjectReferences>
                <buildOutputDirectory>bin/classes</buildOutputDirectory>
                <additionalBuildcommands>
                    <buildcommand>com.android.ide.eclipse.adt.ResourceManagerBuilder</buildcommand>
                    <buildcommand>com.android.ide.eclipse.adt.PreCompilerBuilder</buildcommand>
                    <buildcommand>com.android.ide.eclipse.adt.ApkBuilder</buildcommand>
                    <buildcommand>org.eclipse.jdt.core.javabuilder</buildcommand>
                </additionalBuildcommands>
                <additionalProjectnatures>
                    <projectnature>org.eclipse.jdt.core.javanature</projectnature>
                    <projectnature>com.android.ide.eclipse.adt.AndroidNature</projectnature>
                </additionalProjectnatures>
                <classpathContainers>
                    <classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
                    <classpathContainer>com.android.ide.eclipse.adt.ANDROID_FRAMEWORK</classpathContainer>
                    <classpathContainer>com.android.ide.eclipse.adt.LIBRARIES</classpathContainer>
                    <classpathContainer>com.android.ide.eclipse.adt.DEPENDENCIES</classpathContainer>
                </classpathContainers>
                <excludes>
                    <exclude>com.google.android:android</exclude>
                    <exclude>org.apache.httpcomponents:httpclient</exclude>
                    <exclude>org.apache.httpcomponents:httpcore</exclude>
                    <exclude>commons-codec:commons-codec</exclude>
                    <exclude>commons-logging:commons-logging</exclude>
                    <exclude>org.json:json</exclude>
                    <exclude>org.khronos:opengl-api</exclude>
                    <exclude>xerces:xmlParserAPIs</exclude>
                    <exclude>xpp3:xpp3</exclude>
                </excludes>
            </configuration>
        </plugin>
    </plugins>
</build>

<dependencies>
    <dependency>
        <groupId>org.mapsforge</groupId>
        <artifactId>mapsforge-map-android</artifactId>
        <type>apklib</type>
        <version>${project.version}</version>
    </dependency>

    <dependency>
        <groupId>android</groupId>
        <artifactId>android</artifactId>
        <version>4.4.2_r2</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>com.jayway.android.robotium</groupId>
        <artifactId>robotium-solo</artifactId>
        <version>5.0.1</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>com.google.android</groupId>
        <artifactId>support-v4</artifactId>
        <version>r7</version>
    </dependency>
</dependencies>

1 个答案:

答案 0 :(得分:0)

解决方案如下:

  1. 下载这5个文件: mapsforge核心 mapsforge地图 mapsforge地图阅读器 mapsforge地图,安卓 SVG-机器人
  2. 将这些库(jar文件)放在项目文件夹 libs
  3. 转到Project-&gt; clean
  4. 您无需安装Maven或其他插件。通过Java Build Path包含库 - &gt;图书馆 - &gt;添加外部JAR将无法正常工作。您需要将它放在libs文件夹中。 如果仍然无效,请确保更新Android工具并重试。

    祝你好运:)