2

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:

enter image description here

So my questions:

  1. Why the runtime exception when built by maven?
  2. 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
Community
  • 1
  • 1
Vering
  • 907
  • 9
  • 19
  • I don't get do you have scope provided for support library or not? Because from xml I don't see it but your comment for question number 2 mentions that you had it – Eugen Martynov Aug 23 '13 at 13:39
  • Sorry for being unclear, yes you are correct. I override the above pom.xml in my Android-app project and my Android-test project – Vering Aug 23 '13 at 13:41
  • So you don'e have issue anymore because provided is wrong scope for support library – Eugen Martynov Aug 23 '13 at 14:18
  • I still have issues. Removing the provided-scope made the jar file appear in Eclipse under Maven Dependencies. However, the app cannot find the support-library at runtime when started from Eclipse. – Vering Aug 26 '13 at 06:08
  • I don't use eclipse but my colleagues always have issue with maven-eclipse integration. Please check that export check box for support library is on on the "Order and Export" tab – Eugen Martynov Aug 26 '13 at 06:47
  • I indeed have the check box marked in "Order and Export". Thanks. The strange thing is, at the project can be built, but cannot run. – Vering Aug 26 '13 at 07:57
  • I'm glad you resolved issue. The eclipse issue. In general there is nothing strange because you can't guarantee that runtime classpath will be same as compiletime – Eugen Martynov Aug 26 '13 at 08:39
  • I see many Android dependencies in eclipse - android itself, android dependencies and android private libraries - what all of these mean? Also Android dependency should have "provided" scope as well as android-test I suppose – Eugen Martynov Aug 26 '13 at 12:59

1 Answers1

0

As we quickly discussed - 'provided' scope is wrong for support library and making it compile time resolved maven issue.

Eugen Martynov
  • 19,888
  • 10
  • 61
  • 114
  • The issue is not resolved... Yes removing provided-scope did make the dependency appear in Eclipse. However, I still have question 1 unresolved. I cannot run the app when build from Maven. After removing the provided-scope, I get a new error similar to the first (I'll update my question). Thanks for your help so far. – Vering Aug 26 '13 at 08:56
  • Do you have other dependencies? Any libraries that use support library (like ABS)? – Eugen Martynov Aug 26 '13 at 12:56
  • Hi Eugen, I think the problem is solved now. In my android project pom I removed the scope provided (making the scope "compile"). In my android-test project I kept the provided-scope. I'll update my question as soon as I can confirm that the problem is solved. – Vering Aug 27 '13 at 07:11
  • i would suggest to create new question – Eugen Martynov Aug 27 '13 at 11:02