5
votes

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?

3
I can confirm that both classes are present if you pull in support-v4-21.0.0 via gradle. - Thomas Keller
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: github.com/jayway/maven-android-plugin/issues/484 - jianinz
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

3 Answers

10
votes

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.

0
votes

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.

0
votes

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