为Maven生成MainDexList multidex [英] Generate MainDexList multidex for Maven

查看:216
本文介绍了为Maven生成MainDexList multidex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android项目中遇到一些构建问题.鉴于我们的方法已超过65K的限制,因此我们必须开始使用multidex支持.我遇到的一件事是创建主dex列表文件.我可以构建所有内容,但是将apk拖放到设备上后,应用程序崩溃了,并且出现了诸如NoClassDefFoundError或VerifyError之类的非正统错误.因此,我认为它与Multidex有关,但我还是很固执.我应该将所有课程文件添加到列表中吗?谢谢.

I am experiencing some build issues for an Android project. We had to start using multidex support given that we have over the 65K limit for methods. One thing I'm having issues with though is creating the main dex list file. I can build everything but after I drop down the apk onto my device the app crashes and I get unorthodx errors like NoClassDefFoundError or VerifyError. So, I think it has something to do with multidex, I'm pretty stuck. Should I just add all class files to the list? Thanks.

推荐答案

我在使用activeandroid时也有同样的警告

I have the same warning with activeandroid

VFY: unable to resolve static method 

然后致命的NoClassDefFound错误完成运行时过程.无法找到某些静态方法,有时会在设备api低于目标sdk api版本时发生.我发现mainDexClasses脚本有助于将所有类加入一个dex文件.不幸的是,该实用程序不适用于我的情况.因此,我使用dexdump实用程序来获取设备无法找到的所有类

then fatal NoClassDefFound error finishes runtime process. It cannot be found some static methods sometimes it happens when device api is lower then target sdk api version. I found that mainDexClasses script can be helpful for joining all classes in one dex-file. Unfortunately this utility is not for my case. So I use dexdump utility for getting all classes which cannot be found by device

${ANDROID_HOME}/build-tools/[sdkNum]/dexdump target/classes.dex |grep "Class descriptor"|grep activeandroid >> MainDexList.txt

并将类从classes2.dex添加到MainDexList.txt中,如上所述.请注意,只有activeandroid程序包而不是整个类的列表.接下来,删除多余的前缀和后缀

and add classes from classes2.dex to MainDexList.txt like above. Notice that there is getting only activeandroid package not entire class's list. Next, remove redundant prefix and suffix like this

sed -r "s/  Class descriptor  : 'L//g" MainDexList.txt>MainDexList.tmp;\
sed -r "s/;'/.class/g" MainDexList.tmp > MainDexList;\
rm MainDexList.tmp 

然后指定MainDexList

then specify MainDexList

<mainDexList>MainDexList</mainDexList>

在android-plugin配置的dex部分中,或将此文件用于dx实用程序.

in dex section of android-plugin configuration or use this file for dx utility.

我不清楚不清楚为什么65k会限制方法编号.您是否启用了multiDex选项(请参见此处)?我猜这是生成一些dex文件的主要原因,这就是为什么在我的情况下将一个包拆分为2个文件时会出现问题.因此,我们应该避免如上所述获得整个MainDexList.

I'm not clear undestand why 65k does limit method number. Have you enabled multiDex option (see here)? I guess it's a main reason why a few dex-files are generated and that's why there is a problem when one package is split to 2 files in my case. So we should avoid to get entire MainDexList as described above.

这篇关于为Maven生成MainDexList multidex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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