Well, I wasn’t planning on doing any “actual” dev blogging on this site. But…I wanted to point out a major flaw in the current Android SDK, and how you can get around it.
My Problem
I wanted to pass an Android class through an aidl file for some IPC with the new Amdroid service I created. In particular the android.os.Messenger class.
Sounds simple enough, right? The Messenger class already implements the Parcelable class, and even has it’s own aidl file already written as part of the SDK source code (Messenger.aidl).
One problem though, the current development documents make NO MENTION WHATSOEVER about including standard Android classes in your own aidl files.
Before you call me a heretic or something, try and add this line to your aidl file.
void registerMessenger( in Messenger messenger );
First I thought, ok, maybe the aidl compiler doesn’t know where the Messenger.aidl file is. Fair enough, so I create one like this:
package com.sound.ampache.service;
import amdroid.os.Messenger;
Parcelable Messenger;
Needless to say that didn’t work, I just got this instead:
-aidl:
[echo] Compiling aidl files into Java classes…
[apply] /home/<bla>/amdroid-h/src/com/sound/ampache/service/Messenger.aidl:5: couldn’t find import for class android.os.Messenger
Ok, to save you from the mind-numbing/hair-pulling madness that ensued next, as I meticulously combed Google (and subsequently found not much of value).
Well besides one post mentioning that the aidl files must be recompiled into the SDK. NOT FEASIBLE.
Anyways, Google was a dead end, so I decided to download the SDK source, where I found the Messenger.aidl and such (ok, so it exists).
So what do I do next, track it like a bug, I do
. I comb the ant build files for the aidl compiler option, and with some magic (/bin/cat
), I discover that the aidl compiler looks at the platform/android-<#>/framework.aidl every time you pass it a new aidl file to compile.
Next I noticed that there were some aidl files included that were very close to android.os.Messenger, namely android.os.Bundle.
Like any reasonable person I throw:
import android.os.Bundle;
into an aidl file, and what do you know…it compiles!
Anyways, on a total leap of faith, I add:
parcelable android.os.Messenger;
to the framework.aidl, and guess what it compiles AND WORKS!
Like WTF, get with the picture Google and document this!
As an added bonus PITA I have to advise all of my fellow devs to add this line to all of the framework.aidl they use with Amdroid, ARG! Not cool Google.
Questions/comments/more elegant solutions welcome!
