{"id":24510153,"url":"https://github.com/scavanger/libusb_android","last_synced_at":"2026-05-20T09:31:19.539Z","repository":{"id":254922341,"uuid":"848001897","full_name":"Scavanger/libusb_android","owner":"Scavanger","description":"A dart ffi wrapper around libusb for Android.","archived":false,"fork":false,"pushed_at":"2024-08-27T01:19:41.000Z","size":60,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-15T09:30:04.606Z","etag":null,"topics":["android","dart","libusb"],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Scavanger.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-27T00:25:43.000Z","updated_at":"2024-11-11T07:50:00.000Z","dependencies_parsed_at":"2024-08-27T01:48:02.635Z","dependency_job_id":null,"html_url":"https://github.com/Scavanger/libusb_android","commit_stats":null,"previous_names":["scavanger/libusb_android"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/Scavanger/libusb_android","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Scavanger%2Flibusb_android","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Scavanger%2Flibusb_android/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Scavanger%2Flibusb_android/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Scavanger%2Flibusb_android/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Scavanger","download_url":"https://codeload.github.com/Scavanger/libusb_android/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Scavanger%2Flibusb_android/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33253749,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-20T04:48:54.280Z","status":"ssl_error","status_checked_at":"2026-05-20T04:48:10.851Z","response_time":356,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","dart","libusb"],"created_at":"2025-01-22T00:27:30.918Z","updated_at":"2026-05-20T09:31:19.504Z","avatar_url":"https://github.com/Scavanger.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Push Validation](https://github.com/scavanger/libusb_android/actions/workflows/dart.yml/badge.svg)\n# Libusb android\n\nA ffi wrapper around `libusb` for Android.\nUseful if you need more advanced USB functions than the native Java/Kotlin API in Android offers.\n\nCredits:\nDart wrapper via `libusb` [https://github.com/woodemi/libusb.dart](https://github.com/woodemi/libusb.dart)\n\n\u003e [!IMPORTANT]\n\u003e libusb has the restriction on (unrooted) Android that no USB devices can be listed and found.\n\u003e Functions like `libusb_get_list_devices` will not find any devices. \n\u003e See [libusb android readme](https://github.com/libusb/libusb/blob/master/android/README)\n\nThe devices must be listed and opened via the native Java/Kotlin API in order to obtain a native handle with which libusb can continue to work. \nYou can use [libusb_android_helper](https://pub.dev/packages/libusb_android_helper) for this \n\n## Getting Started\n\nAdd a dependency to your pubspec.yaml\n\n```dart\ndependencies:\n\tlibusb_android: ^1.0.0\n```\n\ninclude the libusb_android_helper package at the top of your dart file.\n\n```dart\nimport 'package:libusb_android_/libusb_android.dart';\n```\n\nIf libusb_android_helper is not used, you have to write custom platform-specific code with Java or Kotlin:\n\nObtain USB permissions over the android.hardware.usb.UsbManager class\n```java\nusbManager = (UsbManager) getSystemService(Context.USB_SERVICE);\nHashMap\u003cString, UsbDevice\u003e deviceList = usbManager.getDeviceList();\nfor (UsbDevice usbDevice : deviceList.values()) {\n    usbManager.requestPermission(usbDevice, mPermissionIntent);\n}\n```\n\nGet the native FileDescriptor of the UsbDevice and transfer it to libusb_android\n```java\nUsbDeviceConnection usbDeviceConnection = usbManager.openDevice(device);\nint fileDescriptor = usbDeviceConnection.getFileDescriptor();\n```\n\nFor the use of `libusb_android_helper` see the readme there.\n\nInitialize libusb:\n```dart\nconst String _libName = 'libusb_android';\nfinal DynamicLibrary _dynamicLibrary = () {\n  if (Platform.isAndroid) {\n    return DynamicLibrary.open('lib$_libName.so');\n  }\n  throw UnsupportedError('Unsupported platform: ${Platform.operatingSystem}');\n}();\nfinal LibusbAndroidBindings _bindings = LibusbAndroidBindings(_dynamicLibrary);\nfinal Pointer\u003cPointer\u003clibusb_context\u003e\u003e _libusbContext = calloc\u003cPointer\u003clibusb_context\u003e\u003e();\n// ...\nvoid initLibusb() {\n  int result = _bindings.libusb_set_option(_libusbContext.value, libusb_option.LIBUSB_OPTION_NO_DEVICE_DISCOVERY);\n  if (result \u003c 0) {\n      throw StateError(\"Unable to set libusb option\");\n  }\n  result =_bindings.libusb_init(_libusbContext);\n  if (result \u003c 0) {\n      throw StateError(\"Unable to init libusb\");\n  }\n}\n// ...\ncalloc.free(_libusbContext);\n```\n\nGet libusb_device_handle:\n```dart\nPointer\u003cPointer\u003clibusb_device_handle\u003e\u003e deviceHandle = calloc\u003cPointer\u003clibusb_device_handle\u003e\u003e();\nint result = _bindings.libusb_wrap_sys_device(_libusbContext.value, handle_from_native_android_api, deviceHandle);\nif (result \u003c 0) {\n    throw StateError(\"Unable to set device handle\");\n}\nPointer\u003clibusb_device\u003e device = _bindings.libusb_get_device(deviceHandle.value);\n// ...\ncalloc.free(deviceHandle);\n```\n\nNow the libusb functions can be used normally.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscavanger%2Flibusb_android","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscavanger%2Flibusb_android","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscavanger%2Flibusb_android/lists"}