NoClassDefFoundError with Android Support Library and Maven

Using the latest version 4.0.0-rc.1 Maven Android Plugin, some classes seem to be missing from the assembly. I get one of these exceptions when starting the application (two possible ways to launch the application):

  • 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.

Definition of my addiction:

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

Is this a configuration error? Error in Android Maven plugin?

+5
source share
3 answers

You need to install the following configuration in 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 this change is that Google decided to put banks in aar, which is bad dependency practice. If you want to replace the version or something else, then this is currently not possible. In short, this makes dependency management difficult.

This parameter is set to false by default to cancel this behavior when creating aar with jar 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 no longer need to add it.

+10
source

I found a workaround:

  • 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 internal_impl-21.0.0.jar from the libs folder and load it into your own artifactory, if you have one, and change your pom file, which should work if you don't have your own artifactory, and then add it to the classpath.

This works for me.

0
source

Do you include a jar file with a "provided" scope for aar dependency? I seem to have found the same error and have the same problem.

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

0
source

Source: https://habr.com/ru/post/1205093/


All Articles