java - Do inherited methods count against the Dex method limit in Android? -
dalvik has well-known limitation on number of methods can have in single .dex file (about 65,536 of them). question whether inherited (but not overridden) methods count against limit or not.
to make things concrete, suppose have:
public class foo { public int foo() { return 0; } } public class extends foo { } public class b extends foo { } public class c extends foo { } for purposes of 65,536 method limit, count adding 1 method, or adding 4? (or, guess, take things logical conclusion, count 1 method or 52 methods, considering java.lang.object brings 12 methods along too).
as background, i've got non-trivial number of generated classes commonality, , i'm bumping against method limit, i'm wondering if it's worthwhile try abstract of out class hierarchy in order buy time.
an inherited not overridden method counts against method limit if ever referenced (called).
in example, let's have following piece of code
public class main { public static void main(string[] args) { foo foo = new a(); foo.foo(); } } in case, referring foo.foo(), has reference, due explicit definition. assuming these 5 classes classes in dex file, have total of 2 method references*. 1 main.main(string[]), , 1 foo.foo().
instead, let's have following code
public class main { public static void main(string[] args) { a = new a(); a.foo(); b b = new b(); b.foo(); c c = new c(); c.foo(); } } in case, since foo method each subclass referenced, count against method limit. dex file have 5 method references*.
- main.main(string[])
- foo.foo()
- a.foo()
- b.foo()
- c.foo()
* this count isn't quite accurate, doesn't take account constructor methods added each class behind scenes. each constructor calls superclass' constructor, have reference object constructor, total of 6 additional method references in each case, giving method count of 8 , 11 respectively.
if in doubt, can try out various scenarios , use baksmali's raw dump functionality see method list in dex file contains.
e.g.
javac *.java dx --dex --output=temp.dex *.class baksmali -n -d temp.dump temp.dex and then, in dump file, "method_id_item section". list of method references 64k limit applies to.
Comments
Post a Comment