我有一个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。见截图:
所以我的问题:
更新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
答案 0 :(得分:0)
正如我们很快讨论的那样 - &#39;提供了&#39;范围是支持库的错误,并使其编译时解决了maven问题。