使用 .aar NoClassDefFoundError 但类存在并被 Dexed

编程入门 行业动态 更新时间:2024-10-28 11:32:40
本文介绍了使用 .aar NoClassDefFoundError 但类存在并被 Dexed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我构建了几个项目来创建 .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: companyx.android.api.ui.vision.metaio.MetaIoView
            at 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/dcendents/android-maven-gradle-plugin).然后我参考了 https://stackoverflow/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/dcendents/android-maven-gradle-plugin). Then I referenced to the local maven as described at https://stackoverflow/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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-14 23:54:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/851410.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:aar   NoClassDefFoundError   Dexed

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!