Android Aidl Compile Error: couldn't find import for class Android Aidl Compile Error: couldn't find import for class android android

Android Aidl Compile Error: couldn't find import for class


Finally I got it resolved.

If you dig into /build/core/base_rules.mk, you'll find that LOCAL_AIDL_INCLUDES is actually the folders to be included during AIDL compiling phase in addition to the default folders like framework or so.

$(aidl_java_sources): PRIVATE_AIDL_FLAGS := -b $(addprefix -p,$(aidl_preprocess_import)) -I$(LOCAL_PATH) -I$(LOCAL_PATH)/src $(addprefix -I,$(LOCAL_AIDL_INCLUDES))

In this specific case, what you want is actually,

LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-Iaidl-files-under, aidl)LOCAL_AIDL_INCLUDES := $(LOCAL_PATH)/aidl


So I looked around - the solution is to put the AIDL files only into their own directory called aidl, which I think some others have suggested.

It turns out that Android Studio looks there, but doesn't quite know what to do about .aidl files put in the src directory.

I don't get it. I just don't get it. AIDL imports worked perfectly in Eclipse. Android Studio is not production ready. This is a major step backwards.

I'm was having trouble getting the AIDL compiler to find imports as well, and I'm thinking there has to be a better way than modifying base_rules.mk, which the platform manages.

Arg!


Ok, so I was struggling for days trying to figure out this same problem. Clean/Rebuilds didn't work for me. Eventually, I realized a really simple mistake I was doing in Android Studio - When I right-clicked my mouse and created a new "AIDL", I wasn't clicking in the appropriate folder as my original model classes.

For example, my model was in a java package called com.example.model, but I wasn't right-clicking in that folder when I created my AIDL. So when Android Studio generates the AIDL folder for me, it would reference the wrong folder, and I would end up with a compile error. I wish the android documentation made it clear that we needed to be right-clicking in the appropriate folder before generating the AIDL files. I know, it sounds silly, but I hope this answer applies to some of you!