8

Trying to compile AIDL files found in the Android repo along with my Android project to use some of the built-in interfaces.

However, whenever I get to an inner type, I get the following error:

ITuner.aidl

aidl E 01-12 17:32:41 59280 1006000 type_namespace.cpp:129] In file ./app/src/main/aidl/android/hardware/radio/ITuner.aidl line 32 parameter config (argument 1):
aidl E 01-12 17:32:41 59280 1006000 type_namespace.cpp:129]     unknown type
aidl E 01-12 17:32:41 59280 1006000 type_namespace.cpp:107] In file ./app/src/main/aidl/android/hardware/radio/ITuner.aidl line 34 return type RadioManager.BandConfig:
aidl E 01-12 17:32:41 59280 1006000 type_namespace.cpp:107]     unknown type
aidl E 01-12 17:32:41 59280 1006000 type_namespace.cpp:107] In file ./app/src/main/aidl/android/hardware/radio/ITuner.aidl line 66 return type RadioManager.ProgramInfo:
aidl E 01-12 17:32:41 59280 1006000 type_namespace.cpp:107]     unknown type
aidl E 01-12 17:32:41 59280 1006000 type_namespace.cpp:107] In file ./app/src/main/aidl/android/hardware/radio/ITuner.aidl line 83 return type List<RadioManager.ProgramInfo>:
aidl E 01-12 17:32:41 59280 1006000 type_namespace.cpp:107]     unknown type

This happens for all inner types. What am I doing wrong?

Other things:

  • I copied all of the AIDL files in my project in the correct directory structures
  • All of the AIDL files build except the ones with inner classes. Inner classes give unknown type errors.
  • I am using the AIDL executable in the API 27 platform directory.
Jason
  • 13,563
  • 15
  • 74
  • 125

1 Answers1

1

These AIDL files and their backing services/classes are hidden from the public API, meaning they are not stable/consistent for all versions of Android. You will not be able to directly use them in your code to access built-in services of the system. You'd have to rely on reflection to gain access to other hidden classes in order to then get access to the underlying binder object of the system provided service. Not a portable or easy solution. If you are trying to re-create the system services within your app and your app will only use your version, then it will make sense to pull these files into your app.

All of that being said, if you are trying to create these services are part of your app, there's more than just the AIDL needed. The AIDL defines the interface a service implements, which in turn generates some Java boilerplate code for you. The missing dependencies you are seeing are because those are not other service interfaces, but classes which are Parcelable, allowing them to be passed as arguments or returned from binder IPC methods. As an example, the missing dependency for RadioManager.BandConfig is an inner class defined in RadioManager.java. You would need this class in your project as well.

Larry Schiefer
  • 15,687
  • 2
  • 27
  • 33
  • but the type is defined in `RadioManager.aidl` which is also in the project. Shouldn't it know the type from there? – Jason Jan 19 '18 at 16:11
  • It's not really defined in `RadioManager.aidl`, it's declared as `Parcelable` so that AIDL could generate the correct templates. You are correct in thinking that this *should* be enough for the `aidl` executable to do its work, but it may not be. Are the java files also in the same directory? – Larry Schiefer Jan 19 '18 at 16:21
  • The aidl files are in their correct package directories in the /aidl directory. I just tried copying all the files (Java, header, etc.) in their correct packages to the java directory. Gradle runs the aidl step first before trying to compile the java files, so it should be able to process aidl independently of the java code. – Jason Jan 19 '18 at 16:40
  • I just did a quick manual test here with the same basic structure of AIDL files: a top level file which refers to an inner class which is parcelable. Works just fine. – Larry Schiefer Jan 19 '18 at 17:25
  • class in Java or class defined in aidl? – Jason Jan 19 '18 at 19:00
  • You have to have both. The .aidl file declares the class as `parcelable`, but the actual implementation is in a .java. – Larry Schiefer Jan 19 '18 at 19:10
  • I'm almost sure that is false, as the `RadioManager` requires `IRadioService` (from the AIDL) to compile. Adding the Java files does not get it to compile – Jason Jan 19 '18 at 20:19
  • Agree that the .java file is not required to build the aidl file, but you will need the .java file to build your project which is using the .aidl. My simple test setup I dropped two .aidl files in the same package hierarchy. One is the interface, the other is a parcelable inner class. The aidl builds ok. So it's go to be something in your project hierarchy. – Larry Schiefer Jan 19 '18 at 20:32