简体   繁体   English

使用Android支持库和Maven的NoClassDefFoundError

[英]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. 使用Maven Android插件的最新版本4.0.0-rc.1,构建中似乎缺少一些类。 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.app.TaskStackBuilderHoneycomb
  • java.lang.NoClassDefFoundError: android.support.v4.widget.EdgeEffectCompatIcs 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. 两个缺少的类都在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? Android Maven插件中的一个错误?

You need to set the following config in the pom: 您需要在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. 这种变化的原因是谷歌决定把罐子放在aar里面,这是一种不好的依赖做法。 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. 默认情况下,此设置设置为false,以阻止在libs文件夹中使用jar创建aar的行为。

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. 使用最新的Android-Maven-Plugin(现在4.1.1很快4.2.0),默认情况下此标志设置为true,因此您不再需要添加它。

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. 然后从libs文件夹中取出internal_impl-21.0.0.jar并上传到你自己的工件(如果有的话),并修改你应该工作的pom文件,如果你没有自己的工件然后将它添加到classpath中。

This works for me. 这适合我。

Are you including a jar file with a "provided" scope for the aar dependency? 你是否包含一个jar文件,其中包含aar依赖的“提供”范围? I think I found the same bug and have the same issue. 我想我发现了同样的错误并且遇到了同样的问题。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Android应用程序,Maven和Eclipse开发库的NoClassDefFoundError - NoClassDefFoundError developing library with Android app, Maven, and Eclipse 使用maven安装Android支持库 - Android support library setup with maven Maven:NoClassDefFoundError:android.support.v4.app.Fragment - Maven: NoClassDefFoundError: android.support.v4.app.Fragment 使用Android支持库v7在Android Maven项目中的ActionBar - ActionBar in Android Maven Project using Android Support Library v7 maven android插件与android支持库v7 - maven android plugin with android support library v7 java.lang.NoClassDefFoundError:android.support.v7.widget。*自升级到支持库v23以来 - java.lang.NoClassDefFoundError: android.support.v7.widget.* since upgrading to Support Library v23 Android Glide库NoClassDefFoundError - Android Glide library NoClassDefFoundError 在android中使用android-support-v7-appcompat库运行PopupMenu时出现NoClassDefFoundError - NoClassDefFoundError when running PopupMenu using android-support-v7-appcompat library in android Android应用程序项目中的依赖库项目的NoClassDefFoundError(使用maven作为构建工具) - NoClassDefFoundError for dependent library projects in Android app project (using maven as build tool) afiledialog android库不起作用| 的NoClassDefFoundError - afiledialog android library not working | NoClassDefFoundError
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM