9

I am unable to overload a method in the AIDL interface.

I wanted to have 2 functions with the same name but diffrent number of arguments like this:

boolean callMethod(in String pClass, in String pMethod, in String pParam);
void    callMethod(in String pClass, in String pMethod);

when I do so, I get an error saying "attempt to redefine method callMethod"

Regards,

Rajan
  • 292
  • 2
  • 10
  • 4
    You need unique method names in an AIDL interface, mostly due to limitations in the java code generation. – Jens Aug 13 '12 at 12:32
  • Hi jens,Thanks for the help. Do we have this documented by Android as a limitation in AIDL? – Rajan Aug 14 '12 at 06:17
  • 4
    Nope, documentation = code as usual - but if you want to see the bit that prevents multiple methods with the same name but different signatures you can checkout `frameworks/base/tools/aidl/aidl.cpp` and look in the `check_types(const char* filename, document_item_type* items)` method, where you should be able to spot the bit that only uses the method name to filter out duplicates. – Jens Aug 14 '12 at 07:12

1 Answers1

10

AIDL does not support overloading. I did not see any mention of this in the documentation, but Google did clarify this point in the android-platform forum here. You can add new methods to the bottom of your AIDL interface without breaking compatibility.

Jim Vitek
  • 4,174
  • 3
  • 23
  • 32
  • **You can add new methods to the bottom of your AIDL interface without breaking compatibility** is this the solution?. As per the link share in above comment someone added comment saying he tried , but no luck it seems – Ashok Reddy Narra May 29 '18 at 13:18
  • 1
    I've successfully added new methods without breaking compatibility. There must have been other issues leading to that other comment. – Jim Vitek May 30 '18 at 14:12
  • @AshokReddy It seems that the order of the methods in the .aidl interface must be preserved, hence stressing the importance of the line: "...to the bottom of your AIDL interface...". You can not put a new method at the top because Android parcels and unparcels the methods with an expected signature in exactly the order they are defined in the .aidl file. Maybe "someone" didn't put the new methods last... – JohnyTex Oct 22 '19 at 13:30