3

On Android NDK project we need to access bluetooth using a HAL interface. Our intention is to do something like this:

#include <hardware/hardware.h>
#include <hardware/bluetooth.h>
....

void load_Module(....)
{ 
hw_module_t* module;
hw_device_t* device;

bdt_log("Loading HAL lib + extensions");

err = hw_get_module(BT_HARDWARE_MODULE_ID, (hw_module_t const**)&module);
if (err == 0){
    err = module->methods->open(module, BT_HARDWARE_MODULE_ID, &device);
    if (err == 0) {
        bt_device = (bluetooth_device_t *)device;
        sBtInterface = bt_device->get_bluetooth_interface();
    }
  }
}

Everybody seems to do the same (in google example code). There appears to be a problem when we try to compile:

#include <hardware/hardware.h> no such file

We properly added a permission to manifest and properly added libraries at Android.mk

Do we need to add something more? Is there a working project that I can refer to?

Paradox
  • 4,602
  • 12
  • 44
  • 88
user1457291
  • 79
  • 2
  • 4

1 Answers1

3

You're trying to use libhardware on Android NDK project. libhardware is a part of Android framework, not a part of NDK.

https://github.com/android/platform_hardware_libhardware

So your project doesn't have true binary compatibility of Android if you can build your project with libhardware. It would work on some devices, some versions, but no guarantee.

From my experience, I believe you can build your code on AOSP. You need to modify Android.mk for AOSP not NDK.

Kazuki Sakamoto
  • 13,929
  • 2
  • 34
  • 96
  • 1
    hi, why can't we use any .so library with ndk (such as libhardware in this question) ? what do you mean by "binary compatibility" ? – ransh May 13 '16 at 15:17
  • 1
    you should read https://developer.android.com/preview/behavior-changes.html#ndk "NDK Apps Linking to Platform Libraries". – Kazuki Sakamoto May 13 '16 at 15:51
  • 1
    The previous comment's link as of 2020 is now: https://developer.android.com/about/versions/nougat/android-7.0-changes#ndk – Arto Bendiken Aug 09 '20 at 21:38