i am creating a new aidl service, which will be used by 3rd party and facing one problem while updating the AIDL file in server side. suppose. Server AIDL file rivison 1: one API is there 1. Add(int a, int b)

Client AIDL file Rivision 1: one api is there 1. Add(int a, int b)

now i have updated the server AIDL Server AIDL file rivision 2: two APIs are there 1. Subtract(int a, int b); 2. Add(int a, int b);

when i am running my second rivision server with first revision client instead of calling add it is calling subtract method.. is there any solution to this problem ? is it a restriction from android that both Server and client end AIDL function order should be same.??

有帮助吗?

解决方案

Yes, the AIDL interfaces on the Server and on the Clint sides must be synchronized. AIDL file is just an interface the implementations of which on the client and server side are generated during the compilation of your client and server code. This interface defines how to marshal the calls from client to server, thus, if your interfaces are not synchronized on the client and on the server you'll get the problems in marshalling calls (this is the problem you see in your case).

It is better to create a library that contains the AIDL interface as a separate project and attach it to your client and server projects. Thus, you'll have the same AIDL interface for both projects.

其他提示

In my testing I have found that you add methods at the end of the AIDL then the old methods continue to work without updating the AIDL. ( I would not recommend you to do this unless there is no other option though)

If you insert the new method in between then it ends up calling the wrong method.

Yes, you must keep the functions have the same declaration order.

The AIDL will generate proper java file for binder communication. It depends on different message ids to distinguish what function would be called.

The base message id is zero, the message id of 1st declared function would be (0 + 1), the message id of 2nd declared function would be (0 + 2).

So that, if you try to keep the compatibility between different versions of the AIDL file. Please keep the function order is the same and just add function at tail.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top