4

I have a project that uses AIDL interfaces and everything is building just fine in android studio with gradle. however, im only using android studio for the convenience of an IDE for developing my android applications, i have to actually use Android make files to build my applications with the rest of the AOSP tree.

when i started this project i just had one small aidl file as a proof of concept and it built fine in both AS and android make. but when i started adding more aidl files it just broke with the error:

[ 14% 1/7] Aidl: myradioservice<= vendor/apps/radioservice/myRadioService/aidl/com/foo/myradioservice/IMetadataCallback.aidl
FAILED: out/target/common/obj/APPS/myRadioService_intermediates/aidl/com/foo/myradioservice/IMetadataCallback.java
vendor/apps/radioservice/myRadioService/aidl/com/foo/myradioservice/IMetadataCallback.aidl:4: couldn't find import for class com.foo.myradioservice.MyMetaData
[ 28% 2/7] Aidl: myradioservice <= vendor/apps/radioservice/myRadioService/foo/com/foo/myradioservice/IMyRadioManager.aidl
FAILED: out/target/common/obj/APPS/myRadioService_intermediates/aidl/com/harman/myradioservice/IMyRadioManager.java
vendor/apps/radioservice/myRadioService/aidl/com/foo/myradioservice/IMyRadioManager.aidl:4: couldn't find import for class com.foo.myradioservice.IMetadataCallback

here are my aidl files:

IMetadataCallback.aidl

package com.foo.myradioservice;

import com.foo.myradioservice.MyMetaData;

interface IMetadataCallback {

    void onMetadataChange(out MyMetaData metadata);

}

IMyManager.aidl

package com.foo.myradioservice;

import com.foo.myradioservice.IMetadataCallback;

interface IMyManager {

    void tune(int channelNumber);

    void registerMetadataListener(IMetadataCallback cb);

    void unregisterMetadataListener(IMetadataCallback cb);
}

MyMetadata.aidl

package com.foo.myradioservice;

parcelable MyMetaData;

(I also have a MyMetadata.java file that implements Parcelable in the java source directory.)

and here is my android make file

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

LOCAL_PACKAGE_NAME := myRadioService

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

LOCAL_STATIC_JAVA_LIBRARIES += android-support-v4

LOCAL_AAPT_FLAGS := --auto-add-overlay

LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
LOCAL_RESOURCE_DIR += frameworks/support/v7/appcompat/res

LOCAL_JAVA_LIBRARIES := android.car

LOCAL_PROGUARD_ENABLED := disabled

LOCAL_DEX_PREOPT := false

include $(BUILD_PACKAGE)

Things ive tried:

  • moving all aidl files into the java directory with the rest of the code, ive seen this done in other places.
  • creating a separate module that compiles the aidl files and including that into my service, also have seen this done in other places.
  • moving the parcelable java code into the aidl directory
  • stubbing out all implementations of the interfaces
  • changing my aidl includes macro to: LOCAL_AIDL_INCLUDES := $(LOCAL_PATH)/aidl as suggested in another SO answer
  • all sorts of combinations of changes to the LOCAL_SRC_FILES and LOCAL_AIDL_INCLUDES, even using absolute paths to the files
Aaron Czajka
  • 147
  • 2
  • 10
  • do you have `MyMetaData.aidl`? did you read [this](https://developer.android.com/guide/components/aidl#PassingObjects)? – pskink Aug 06 '18 at 19:28
  • yes i have read that and yes i do have that aidl file. it was at the bottom of my code block, i seperated and labeled each aidl files contents with file names – Aaron Czajka Aug 06 '18 at 19:33
  • LOCAL_AIDL_INCLUDES := $(call all-Iaidl-files-under, aidl) This will only include I aidl files not your MyMetadata.aidl file. – kiran Biradar Aug 07 '18 at 06:53
  • thats by design, the AIDL documentation from google says: "If you are using a custom build process, do not add the .aidl file to your build. Similar to a header file in the C language, this .aidl file isn't compiled." but i have tried hardcoding the absolute path and it still doesnt compile, same errors – Aaron Czajka Aug 07 '18 at 13:31
  • Did you ever solve this? I am getting the same error. – Matt Mar 02 '20 at 18:47
  • sorry monkeyking, i dont remember what the solution was. i imagine i solved it but i am no longer at that job and i cant look at the code anymore to see what is different – Aaron Czajka Mar 03 '20 at 18:57

2 Answers2

0

Was stumbled upon this as well, but managed to find a workaround.

TL;DR just make sure all your aidl filenames start with letter 'I'.

It looks like the core build system will only pick up aidl files whose name begins with letter 'I'.

For instance, in the original author's situation, his IMetadataCallback.aidl and IMyManager.aidl were compiled, but not his MyMetadata.aidl. I've found out the same with my project.

I am guessing the build system was designed this way to ensure all aidl files were named properly, but it was not updated afterwards to fully support the custom parcelable types that are defined directly in aidl files starting in Android 10.

Endor
  • 404
  • 3
  • 14
0
  1. LOCAL_AIDL_INCLUDES must be prefixed by $(LOCAL_PATH) and must refer to the directory containing your AIDL package, not each file individually
  2. On the other hand, LOCAL_SRC_FILES must list each *.aidl and *.java file individually

So given the following structure:

.
├── Android.mk
└── src
    ├── aidl
    │   └── com
    │       └── example
    │           └── application
    │               ├── IAnotherInterface.aidl
    │               └── IOneInterface.aidl
    └── java
        └── com
            └── example
                └── application
                    └── OneClass.java

The directives would be:

LOCAL_AIDL_INCLUDES := $(LOCAL_PATH)/src/aidl
LOCAL_SRC_FILES := \
    src/aidl/com/example/application/IAnotherInterface.aidl \
    src/aidl/com/example/application/IOneInterface.aidl \
    src/java/com/example/application/OneClass.java

or:

LOCAL_AIDL_INCLUDES := $(LOCAL_PATH)/src/aidl
LOCAL_SRC_FILES := \
    $(call all-Iaidl-files-under, src/aidl) \
    $(call all-java-files-under, src/java)
Jim
  • 416
  • 2
  • 4
  • 16