问题描述
我创建了几个项目来创建.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 所述的本地专家.最后,我使用传递选项声明了依赖项,如下所示:
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但类存在并且已消除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!