0

I want to access all Android SDK classes in a Rust library, and perform some operations on the Android system. Here is the example list of classes/packages that I want to access

android.hardware.usb.* (UsbManager, UsbDevice)
android.content.BroadcastReceive
android.content.Context 

(And all files from content package) and so on...

In a nutshell, I want to access whole bunch of classes provided by Android SDK in a Rust library.

I have tried using bindgen crate to generate the bindings, but unfortunately no luck, as it needs header files to generate the bindings, and for Android SDK, there are no header files available inside the platforms folder.

I have used a JNI approach using Java reflection something like this -

env.get_static_method_id(class_ctx, "getApplicationContext",()Landroid/content/Context;").unwrap();
let usb_service = match env.get_static_field(class_ctx, "USB_SERVICE", "Ljava/lang/String;")

But this approach seems error prone and hard to maintain. Is there anything in Rust so that I can access all Android SDK classes inside a Rust lib?

0 Answers0