Maven:NoClassDefFoundError:android.support.v4.app.Fragment

时间:2013-08-23 13:16:26

标签: android maven android-support-library

我有一个Android项目,我可以直接在Eclipse中构建和运行而没有问题。

但是,从maven构建错误

NoClassDefFoundError: android.support.v4.app.Fragment

当我使用android-support lib时弹出像soons一样。我有我的pom:

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

并且所有软件包都已正确下载,并且可以毫无问题地构建应用程序。

应用程序在Eclipse构建时运行,如上所述。让我想知道的一件事是,android-support库没有出现在Maven Dependencies下。因此我将它添加为外部Jar。见截图:

enter image description here

所以我的问题:

  1. 为什么maven构建运行时异常?
  2. 为什么android-support lib不会出现在Eclipse中? (是的,我已经运行了“Maven” - &gt;“更新项目......”数十次)。
  3. 更新1 :关于问题2:删除<scope>provided</scope>代码(Maven Eclipse Plugin won't add Android support-v4 to build path)。

    删除<scope>provided</scope>后,我在maven构建时遇到此运行时错误(MyFragmentAdapter扩展FragmentPagerAdapter)

    08-26 10:42:56.054: W/dalvikvm(8132): Class resolved by unexpected DEX: Lcom/firm/myapp/adapter/MyFragmentAdapter;(0x41ce03a8):0x5a55c000 ref [Landroid/support/v4/app/FragmentPagerAdapter;] Landroid/support/v4/app/FragmentPagerAdapter;(0x41ce03a8):0x5a4e3000
    08-26 10:42:56.054: W/dalvikvm(8132): (Lcom/firm/myapp/adapter/MyFragmentAdapter; had used a different Landroid/support/v4/app/FragmentPagerAdapter; during pre-verification)
    08-26 10:42:56.054: W/dalvikvm(8132): Unable to resolve superclass of Lcom/firm/myapp/adapter/MyFragmentAdapter; (119)
    08-26 10:42:56.054: W/dalvikvm(8132): Link of class 'Lcom/firm/myapp/adapter/MyFragmentAdapter;' failed
    08-26 10:42:56.064: W/ClassPathPackageInfoSource(8132): Cannot load class. Make sure it is in your apk. Class name: 'com.firm.myapp.adapter.MyFragmentAdapter'. Message: com.firm.myapp.adapter.MyFragmentAdapter
    08-26 10:42:56.064: W/ClassPathPackageInfoSource(8132): java.lang.ClassNotFoundException: com.firm.myapp.adapter.MyFragmentAdapter
    

1 个答案:

答案 0 :(得分:0)

正如我们很快讨论的那样 - &#39;提供了&#39;范围是支持库的错误,并使其编译时解决了maven问题。