My goal is to use libnl in an Android Application to fetch a list of beacon frames received in the latest network scan and print (display) the associated metadata such as AP SSID, AP BSSID etc...
Following basic tutorials and guidelines, the approach seems to be:
- Cross compile libnl for all supported Android ABIs since libnl comes with its own
./configure
andMakefile
- Import the compiled archives in my Native C/C++ code as
PREBUILT_STATIC_LIBRARY
or aPREBUILT_SHARED_LIBRARY
- Use libnl methods in native code
Dev Environment and Configuration:
- IDE: Android Studio 3.1.2
- NDK Version: Android NDK revision 17b
- External Tools: Gradle, CMake
- MinSDK Version: API 14
- Targeted SDK Version: API 21
- Library Source: Libnl 3.2.25 - link
- OS: Ubuntu 18.04 LTS
Cross Compiling:
I have been able to successfully cross compile libnl for all the ABIs (armeabi-v7a
,arm64-v8a
,x86
,x86_64
) using the NDK Standalone Toolchains method documented here. This gives me.a
compiled files for the library.Importing the Libraries and Compiling:
This was done closely following the code samples from Google (github) - specifically the "hello-libs" example.
NOTE: I infer that step 1 and 2 are done correctly because the library gets linked successfully with my C/C++ source code when I compile and run the app. Further, I am able to call libnl methods from my C/C++ source code. I get no UnsatisfiedLinkError
or Undefined Reference to ...
.
Using libnl methods as in Linux
I have debugged the issue to the statement using the libnl methodgenl_ctrl_resolve
to get driverId fornl80211
driver. This returns error code-12
meaning "Object not found."... struct nl_sock *socket = init_socket(); driver_id = genl_ctrl_resolve(socket, "nl80211"); ...
My specific doubts are:
- Is my approach correct? If not, any help or insight is appreciated.
- Is there any alternative approach?
- Does my application require
root
access to get the driver id? - Any good resources for learning more about Native Android Development.
Any help is appreciated. Thank you in anticipation.
PS..
- I have gone through the Android Developer's Website
- I have been referring
Android NDK Beginner's Guide by Sylvain Ratabouil
andPro Android Apps Performance Optimization by Herve´ Guihot
- Also tried building the project from scratch using Eclipse (ADT) and older SDK (r24.4.1), NDK (r10e)