Using AIDL with Mono for Android

て烟熏妆下的殇ゞ 提交于 2019-12-21 18:00:33

问题


Not being patient enough for the Mono for Android book I started going through the Android programming constructs and translate them to the Mono infrastructure. Seems like most the time the good folks at Xamarin and I think along similar lines so progress has been relatively pain free but on the AIDL issue I'm stuck. Was AIDL implemented? If so, how can I use it? If not, what is the recommended way to use IPC?


回答1:


AIDL is, lamentably, something that isn't readily supported at this time. It is only supported via Java Interop Support; that is, you'd need to:

  1. Write your .aidl files.
  2. Compile the .aidl files into .java files (possibly as a pre-build step?).
  3. Include the generated .java files into your build by adding them to the project and setting their build action to AndroidJavaSource.

Of course, for parcels you'll need to implement them...in Java, and for services you'll likewise need to write some Java code.

The documentation on Java Native Interop Support may be useful as well.

In all, not very elegant. Not difficult, but not elegant either.

Consequently, the recommended way to do IPC is to use Intents, BroadcastReceivers, and ContentProviders (depending on the needs of your IPC), and avoiding the use of parcels; use Strings and other builtin types instead.




回答2:


AIDLs are finally supported. To use them add aidl files into your project and set Build Action to AndroidInterfaceDefinition. Xamarin.Android will generate cs files, that are compiled together with your source code, so you can use aidl interfaces in your c# code. VS2012 still marks them as unknown/errors in code, but in the end, code is compiled and working.



来源:https://stackoverflow.com/questions/7872505/using-aidl-with-mono-for-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!