5

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?

Benoit
  • 4,549
  • 3
  • 28
  • 45
Markus Junginger
  • 6,950
  • 31
  • 52
  • 1
    I can confirm that both classes are present if you pull in `support-v4-21.0.0` via gradle. – Thomas Keller Oct 20 '14 at 14:37
  • I second what Thomas Keller said, it works well with gradle, but not maven, i have been trying to figure out why for hours already, here is issue i submitted to android maven plugin repo: https://github.com/jayway/maven-android-plugin/issues/484 – jianinz Oct 21 '14 at 13:23
  • The logcat shows that the DexOut cannot direct calls from classes.jar to internal_impl-21.0.0.jar. The maven android plugin seems successfully extract all dependencies from aar and package it, if you looked at the `target/unpacked-libs/cas_support-v4` folder, it has everything we need. – jianinz Oct 21 '14 at 13:30

3 Answers3

10

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.

Community
  • 1
  • 1
Benoit
  • 4,549
  • 3
  • 28
  • 45
  • Thanks! I tried it, it works well! Another question, since support-v4 and support-v13 aar packages come with libs folder where it contains the **same** jar file name internal_impl-21.0.0.jar, will maven-shade plugin filter out one of them if both of them are being used? You know, application contains library which has support-v4 in? – jianinz Oct 23 '14 at 20:18
  • Was running into the same issue as topic starter with "class file for android.support.v4.widget.DrawerLayoutImpl not found". This has smoothly fixed it. – riwnodennyk Oct 26 '14 at 13:43
0

I found a temporary solution:

  • cp support-v4-21.0.0.aar ~/Desktop
  • cd ~/Desktop && mv support-v4-21.0.0.aar support-v4-21.0.0.jar
  • jar xf support-v4-21.0.0.jar

then pull out internal_impl-21.0.0.jar from libs folder and upload to your own artifactory if you have any, and modify your pom file it should work, if you don't have your own artifactory then add it into classpath.

This works for me.

jianinz
  • 163
  • 1
  • 11
0

Are you including a jar file with a "provided" scope for the aar dependency? I think I found the same bug and have the same issue.

https://github.com/jayway/maven-android-plugin/issues/485

Summers Pittman
  • 199
  • 1
  • 8