I have an Android project which I can build and run directly in Eclipse without problems.
However, when build from maven the error
NoClassDefFoundError: android.support.v4.app.Fragment
Pops up as soons as I use the android-support lib. This I have in my 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>
and the packages are all downloaded correctly and the app can be build without problems.
The app runs when build by Eclipse, as I wrote above. One thing that made me wonder was, that the android-support library do not show up under Maven Dependencies. Hence I added it as an external Jar. See screenshot:
So my questions:
- Why the runtime exception when built by maven?
- Why does the android-support lib not show up in Eclipse? (And yes I've run "Maven" -> "Update Project..." dozens of times).
UPDATE 1: Regarding question 2: Remove the <scope>provided</scope>
tag (Maven Eclipse Plugin won't add Android support-v4 to build path).
After removing <scope>provided</scope>
I get this runtime-error when built by maven (MyFragmentAdapter extends 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