Android: my application is too large and gives “Unable to execute dex: method ID not in [0, 0xffff]: 65536”?

前端 未结 8 1991
慢半拍i
慢半拍i 2020-11-27 04:52

I am trying to integrate my application with Box, Dropbox, and Google Drive. All 3 of these services require a number of 3rd party jars. Additionally, my application alrea

8条回答
  •  清酒与你
    2020-11-27 04:58

    I faced this issue recently. After scouring the web for some more detailed implementation, I realized there wasn't much out there other than:

    • Good but a little outdated now that Gradle is around: http://android-developers.blogspot.co.il/2011/07/custom-class-loading-in-dalvik.html
    • Not much details but a vague idea of how it could be done: https://www.facebook.com/notes/facebook-engineering/under-the-hood-dalvik-patch-for-facebook-for-android/10151345597798920

    I realized that the problem was not necessarily that there were too many methods in my code, but that the full dex of my code and other libraries was the issue. So, if I could compile my code against the libraries but not include them in the classes.dex, and then dex the libraries separately, and then put it all together at runtime it should work. The only issue left to address is the class loader, which Facebook mentioned in passing.

    So with a little reflection and some Groovy code, I think I came up with a relatively stable way to package the libraries and the application code into separate dex files.

    https://gist.github.com/nickcaballero/7045993

提交回复
热议问题