问题
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.
回答1:
I have the same warning with activeandroid
VFY: unable to resolve static method
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
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
then specify MainDexList
<mainDexList>MainDexList</mainDexList>
in dex section of android-plugin configuration or use this file for dx utility.
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.
来源:https://stackoverflow.com/questions/32723590/generate-maindexlist-multidex-for-maven