Today, when I was doing an example of aidl, I encountered a small problem, and two processes were unable to communicate. According to the example of the book (here the code from the Crazy Android Handout 2nd edition), or error, and finally on the Internet to find out the problem is the package name. In other words, the package name of the package in which the Aidl interface is defined must remain consistent with the client and server side. Otherwise it will error, the program forced to quit. The error message is as follows (things bind failed):
In debug mode, you will see the following exception (the target invocation exception) thrown:
This is because my package name is inconsistent, as follows:
The package is different, because it was the Icat.aidl file that was copied directly, the content is:
1 Package com.qc.aidlservice; 2 Interface ICat 3 {4 String getColor (); 5 Double getweight (); 6 }
Because it involves the guide package, because the direct copy to the server will be error, so in the server file I need to import the package name changed to the following package:
1 Package com.example.myaidlclientdemo; 2 Interface ICat 3 {4 String getColor (); 5 Double getweight (); 6 }
However, this will appear above the error, in fact, this superfluous caused a mistake. The simplest way to do this is to directly copy the package containing the Aidl file to our client after writing the server-side code. The system will automatically generate. java files for us, simple and convenient. As follows:
The last thing to note is that when configuring the service, you must not configure the service's properties to android:exported= "false", in this case:
1 <service android:name= ". Aidlservice "2 android:exported=" false ">3 <intent-filter >4 < Action android:name= "Com.example.myaidldemo.action.AIDL_SERVICE"/>5 </intent-filter>6 </service>
This configuration of the external application of course no access AH (the reason for the mistake is to solve the IT warning problem is forgotten to change, so the program has been strong push, so be careful and careful again!!! )。
Should be configured to:
1 <service android:name= ". Aidlservice "2 android:process=": Remote >3 <intent-filter >4 <action android:name= "Com.example.myaidldemo.action.AIDL_SERVICE"/>5 </intent-filter> 6 </service>
About the package name problem with AIDL client-server interaction-package