Strange behavior when I add new method in AIDL file in the beginning

1.2k Views Asked by At

I have AIDL file (methodA,methodB) as part of my android project. I added a new method(methodC) at the beginning of file and built the project,and at client side i didn't update/replace to new AIDL file.

Now, when i call methodA from client it is calling methodC in serverside. I don't understand how the mapping happens.

Can some one explain this behavior?

client side file:      serverside file:
methodA                 methodC 
methodB                 methodA
                        methodB
2

There are 2 best solutions below

0
On

Actually, the answer is very easy. The methods during the compilation of AIDL receives the incremental identifiers. Roughly saying, during the compilation of AIDL file of your client methodA receives identifier equal to 1, methodB - 2. Similarly, on your server side during the compilation methodA receives identifier equal to 1, methodB - 2. When you updated AIDL file on the server and put methodC in the beginning of the interface, during the compilation this methodC received identifier equal to 1. Thus, when your client calls methodA your updated server receives a command to execute a method with identifier equal to 1, which is now methodC.

1
On

Your methods are calling by the transaction numbers, not by the names. Transaction numbers are generated automatically in auto-generated .java in build folder. Numbers for methods are generating in orders the methods meeting. So, if you want to add a new method to the aidl-file and don't update this file in all your apps, put this method in the end of file.

Do something like this:

client side file:      serverside file:
methodA                 methodA 
methodB                 methodB
                        methodC
                        methodD

In this case methods A and B from the client will call correct methods on the server side, because they will have the same transact numbers.