Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoClassDefFoundError with Android Support Library and Maven

Using the latest version 4.0.0-rc.1 of the Maven Android Plugin, some classes seem to be missing in the build. I get one of those exceptions when I start the app (two possible ways to start the app):

  • java.lang.NoClassDefFoundError: android.support.v4.app.TaskStackBuilderHoneycomb
  • java.lang.NoClassDefFoundError: android.support.v4.widget.EdgeEffectCompatIcs

Both missing classes are inside support-v4-21.0.0.aar/libs/internal_impl-21.0.0.jar.

My dependency definition:

    <dependency>
        <groupId>com.android.support</groupId>
        <artifactId>support-v4</artifactId>
        <version>21.0.0</version>
        <type>aar</type>
    </dependency>

Is this some configuration error? A bug in the Android Maven plugin?

like image 302
Markus Junginger Avatar asked Oct 20 '14 13:10

Markus Junginger


1 Answers

You need to set the following config in the pom:

<includeLibsJarsFromAar>true</includeLibsJarsFromAar>

So it will look something like this:

<plugin>
    <groupId>com.jayway.maven.plugins.android.generation2</groupId>
    <artifactId>android-maven-plugin</artifactId>
    <extensions>true</extensions>
    <configuration>
        //...
        <includeLibsJarsFromAar>true</includeLibsJarsFromAar>
        //... rest of config
    </configuration>    
</plugin>

The reason for that change is that Google decided to put jars inside the aar which is a bad practice of dependencies. If you want to substitute the version or something else it is not currently possible. In short it makes dependencies much more difficult to manage.

This setting is set to false by default to discourage this behavior of creating aar's with jar's inside the libs folder.

Update:

Using the latest Android-Maven-Plugin (Now 4.1.1 soon 4.2.0) this flag is set to true by default so you do not need to add it anymore.

like image 164
Benoit Avatar answered Nov 15 '22 17:11

Benoit