1

Android O, AOSP. I'm trying to use an HIDL java library inside an application in frameworks/base.

According to the documentation, I've added the HIDL to Android.mk file:

LOCAL_JAVA_LIBRARIES := vendor.myvendor.mylibrary-V1.0-java

In the MainActivity.java, I include it and try to use:

import vendor.myvendor.mylibrary.V1_0.IGood;

public class MainActivity extends Activity {

    public void onCreate(Bundle b) {
        super.onCreate(b);
        IGood service;
    }
}

This code compiles without any errors. But when I try to access some methods, e.g.:

import vendor.myvendor.mylibrary.V1_0.IGood;

public class MainActivity extends Activity {

    public void onCreate(Bundle b) {
        super.onCreate(b);
        IGood service = IGood.getService();
    }
}

I get an error:

error: cannot access IBase
            IGood server = IGood.getService();
                                ^
class file for android.hidl.base.V1_0.IBase not found
Vitalii Dmitriev
  • 739
  • 1
  • 8
  • 18

1 Answers1

0

The solution is to add to the Android.mk following line:

LOCAL_STATIC_JAVA_LIBRARIES := android.hidl.base-V1.0-java-static

Also, after that I've got another error: it didn't compile because of proguard. In my case I had to disable it:

LOCAL_PROGUARD_ENABLED := disabled

Otherwise, it is needed to create a proguard config and add all .jars, related to HIDL.

After that everything works.

Vitalii Dmitriev
  • 739
  • 1
  • 8
  • 18
  • Do you understand why this works? Why does the hidl library need to be included as a static lib? – Matt Mar 11 '20 at 14:55