Looking-Glass / JoyconLib

Joy-Con library for Unity.
MIT License
467 stars 91 forks source link

Support for Android Builds #21

Open PancreasMonster opened 5 years ago

PancreasMonster commented 5 years ago

Hey, first I have to say; great project, felt good to use the Joycons immediately.

However, I'm wondering if there's way I could use this on a mobile device. I have built for android and it doesn't seem to work. I don't know much about Plugins but I'm assuming this is because androids don't support the Hidapi DLL. Sorry if this is an obvious solution, but is there anyway I can use an android compatible plugin instead, and if yes, how would I go about it? Thanks.

TheBricktop commented 4 years ago

well there is a way to build an android part of the plugin using libusb/hidapi from their repo

Ghostbird commented 2 years ago

well there is a way to build an android part of the plugin using libusb/hidapi from their repo

Could you elaborate? I assume I must build some sort of file structure in JoyconLib_plugins?

Ghostbird commented 2 years ago

I figured it out, here's the script.

Building on Android works fine this way, however, it doesn't find any joy cons:

2021/11/24 21:18:20.117 11664 11686 Info Unity No Joy-Cons found!
2021/11/24 21:18:20.117 11664 11686 Info Unity JoyconManager:Awake()

There's no crash, and it seems HIDapi.hid_enumerate(vendor_id, 0x0) is correctly called, but no joycons are found.

Ghostbird commented 2 years ago

I'm pretty sure it's a permissions problem, I found these two messages:

2021/11/24 22:27:18.831 17242 17242 Warn UnityMain type=1400 audit(0.0:34568): avc: denied { read } for name="/" dev="tmpfs" ino=15575 scontext=u:r:untrusted_app:s0:c190,c257,c512,c768 tcontext=u:object_r:device:s0 tclass=dir permissive=0
2021/11/24 22:27:18.831 17242 17242 Warn UnityMain type=1400 audit(0.0:34569): avc: denied { read } for name="devices" dev="sysfs" ino=22806 scontext=u:r:untrusted_app:s0:c190,c257,c512,c768 tcontext=u:object_r:sysfs:s0 tclass=dir permissive=0

UPDATE: I've found that HIDapi.hid_init() returns -1 indicating failure when called. I've verified that the libhidapi.so and libusb1.0.so are correctly packaged in the APK by Unity.