By Ricardo Amaral


2013-03-15 16:03:40 8 Comments

My team and I have inherited a large Android project from another team. The whole application with all the included libraries is reported to have around 35000 methods. We now have the task to implement a new service in the app where we need to use Protocol Buffers.

The problem is that the generated .jar file with all the required .proto files creates another couple of 35000 methods, that's 70000 methods. And if you are not aware, the Android compiler has a limitation of 65536 methods per .dex file. We are clearly over that limit and we are getting the following error trying to compile the app:

Unable to execute dex: method ID not in [0, 0xffff]: 65536
Conversion to Dalvik format failed: Unable to execute dex: method ID not in [0, 0xffff]: 65536

Yes, the application architecture should probably be restructured but that will take time. And for now we are trying to figure out a solution to work around this problem temporarily.

Any suggestions?

7 comments

@mboy 2016-07-11 06:29:48

If you are using eclipse this is the easiest work around Click Here!

@akshay 2015-02-27 08:32:23

In versions of Google Play services prior to 6.5, you had to compile the entire package of APIs into your app. In some cases, doing so made it more difficult to keep the number of methods in your app (including framework APIs, library methods, and your own code) under the 65,536 limit.

From version 6.5, you can instead selectively compile Google Play service APIs into your app. For example, to include only the Google Fit and Android Wear APIs, replace the following line in your build.gradle file:

compile 'com.google.android.gms:play-services:6.5.87'

with these lines:

compile 'com.google.android.gms:play-services-fitness:6.5.87'
compile 'com.google.android.gms:play-services-wearable:6.5.87'

for more reference, you can click here

@Abhay Buch 2013-11-01 16:57:53

Square had similar issues and they built Wire to deal with the method explosion caused by protobufs. They claim to have killed 10,000 methods.

@Wink Saville 2013-07-18 03:32:25

We've recently added Nano Protobufs to Android which significantly reduces the number of methods generated.

@icedwater 2013-07-18 03:50:12

More details, please, if you will?

@Ricardo Amaral 2013-07-18 23:51:31

Yes, please... More details on what exactly do we have to do to start using Nano Protobufs...

@Udinic 2013-03-16 01:15:34

@Tom Susel 2014-07-28 09:14:58

Here is a script for counting the number of methods in each jar: gist.github.com/toms972/c83504df2da1176a248a

@woot 2014-10-30 14:03:01

The linked post is a bit outdated, it shows how to load multiple DEX files in an Ant based project. It also uses the DexClassLoader directly, a thing which is no longer required since android.support.multidex helps you with that and it's available in the support library (revision 21). Detailed explanation of how to integrate MultiDex into your app is here: contentful.com/blog/2014/10/30/…

@philipp 2015-07-31 16:27:07

similar to @TomSusel script, we wrote a small gradle plugin that gives you a deeper insight on your method count and where it comes from on each build - github.com/KeepSafe/dexcount-gradle-plugin

@Bruce Martin 2013-03-15 23:38:59

If this is the first use of Protocol buffers, you could look at alternative JavaME implementations i.e.

there are others listed in Third party add ons. If have not used any of them, but they seem to be smaller and do not have all the methods created by the standard protocol buffers.

@fadden 2013-03-15 22:39:10

Enable Proguard (http://developer.android.com/tools/help/proguard.html) to remove unused methods. The protobuf generator creates thousands of methods that are never actually used.

Micro-protobuffers (https://code.google.com/p/micro-protobuf/) may also be useful.

@Ricardo Amaral 2013-03-17 14:53:46

I've been looking into using proguard for this but I'm not sure how to enable it for debug/run configuration builds within Eclipse. Any hints on this?

@fadden 2013-03-17 16:02:16

There are some posts on stackoverflow that may be helpful, such as stackoverflow.com/questions/4732656/… .

@Ricardo Amaral 2013-03-17 16:22:39

I can't seem to find anything on that question that mentions using proguard with the debug/run configurations withing Eclipse...

Related Questions

Sponsored Content

31 Answered Questions

[SOLVED] Activity restart on rotation Android

12 Answered Questions

[SOLVED] How to shrink code - 65k method limit in dex

6 Answered Questions

[SOLVED] dex loader unable to execute dex: method ID not in [0, 0xffff]: 65536

3 Answered Questions

[SOLVED] Unable to execute dex: method ID not in [0, 0xffff]:

  • 2014-10-13 12:55:57
  • Navakanth
  • 3617 View
  • 0 Score
  • 3 Answer
  • Tags:   android eclipse dex

1 Answered Questions

1 Answered Questions

Sponsored Content