使用 .aar NoClassDefFoundError 但类存在并被 Dexed [英] Using .aar NoClassDefFoundError But Class Exists and is Dexed

查看:25
本文介绍了使用 .aar NoClassDefFoundError 但类存在并被 Dexed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我构建了几个项目来创建 .aar.然后我将这个 .aar 导入到/libs 下的 Android Studio 中.此依赖项的 build.gradle 文件如下所示:

I have several projects which I build to create an .aar. I then import this .aar into into Android Studio under /libs. The build.gradle file for this dependency looks as follows:

repositories{
    flatDir{
        dirs 'libs'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.0.0'
    compile 'com.google.android.gms:play-services:7.0.0'
    compile 'com.android.support:multidex:+'
    compile(name: 'customApi-debug', ext:'aar')
}

由于库很大,我设置了 multiDexEnabled = true.Android Studio 找到库并自动完成工作.构建也可以正常运行,但运行应用程序会出现以下错误:

Since the library is quite large I have set multiDexEnabled = true. Android Studio finds the library and autocomplete works. Building works fine too but running the app gives the following error:

java.lang.NoClassDefFoundError: com.companyx.android.api.ui.vision.metaio.MetaIoView
            at com.companyx.android.api.ui.vision.metaio.MetaIoView$$InjectAdapter.<init>(MetaIoView$$InjectAdapter.java:29)

我分别解压和反汇编了 .aar 和 dex 文件,并验证了它抱怨的类确实存在.我已经尝试过现有的方法来处理这个问题,但没有一个奏效.

I uncompressed and disassembled the .aar and dex files, respectively, and verified that the classes its complaining about actually exist. I've tried existing approaches for dealing with this problem but none of them worked.

有其他人遇到过这种情况吗?提前致谢.

Anyone else experienced this? Thanks in advance.

推荐答案

我遇到了同样的问题.修复首先是将 AAR 文件部署到本地 maven(我使用了 https 上的插件)://github.com/dcendents/android-maven-gradle-plugin).然后我参考了 https://stackoverflow.com/a/23045791/2563009 中所述的本地 maven.最终我用传递选项声明了依赖关系,如下所示:

I run into the same issue. The fix is firstly to deploy the AAR file to a local maven (I utilized the plugin at https://github.com/dcendents/android-maven-gradle-plugin). Then I referenced to the local maven as described at https://stackoverflow.com/a/23045791/2563009. And eventually I declared the dependencies with a transitive option, like this:

dependencies {
  compile('com.myapp.awesomelib:awesomelib:0.0.1@aar') {
    transitive = true
  }
}

错误就会消失.

这篇关于使用 .aar NoClassDefFoundError 但类存在并被 Dexed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆