-
Notifications
You must be signed in to change notification settings - Fork 287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Android Library Compatibility #133
Comments
I'm not sure if the issue I'm having should be posted here, or in a new issue (or in the jSerialComm issues at all), but I've used a previous version (1.4.0) of jSerialComm in a Xamarin.Android project for a couple of years now, and it's been working great. However, when trying to use the new 2.x.x jars, I'm getting a compile error from the Xamarin build system that says: 2>COMPILETODALVIK : PARSE error : I cannot find any info regarding this error, and it very well could just be a bug in Xamarin. But I was hoping someone could maybe tell me what might have changed since 1.4.0 that could cause such an error. I also wonder if this could point to an actual issue with the jar files, themselves. I attempted to compile myself using Android Studio (which I used successfully to build 1.4.0), but failed, as I am a novice when it comes to Android Studio and the gradle build system. Any help would be very much appreciated! |
Okay, I followed the instructions in issue #128 and created a test project in Android Studio to strip the Java9 stuff from the jar file, then I located the repackaged jar file in the build artifacts and used that file in my Xamarin project. This works! However, now I'm getting a "ClassNotFoundException" when I try to open a port, and it traces back to the cfmakeraw call in the OpenNativePort call in the .so file. Any thoughts on why this might happen? |
Having the same issue: 02-08 12:58:10.996 14495-14495/com.hasar.hasarmposdriver W/System.err: Could not locate or access the native jSerialComm shared library. |
The issue with the library not finding native function calls (like cmakeraw) in Android has now been resolved (available in 2.4.1); however, it still requires a rooted device to function since Android does not allow direct access to device ports on a non-rooted device. |
I looked around and couldn't find a solution. I'm able to use the library in my android studio 3 projects by including the gradle dependency, and, manually taking the "jSerialComm.jar/Android/*" files out, and putting them into the ".../app/src/main/jniLibs/" folder. If I don't manually copy the native libs then I get "can't find native method" errors at run-time. I was wondering if there was some way around this just so I can be more sure the .so's are always synced with the gradle dependency jar after updating it. Maybe some known gradle rule/repackage tasks or such for android? I do see that the jar contains "/Android, /Linux, /OSX, /Solaris, /Windows", however, the resulting Android Studio generated apk only has "/OSX, /Windows", and "/lib" if I manually copy to "jniLibs". If there is a gradle rule\hackary for android to fix the "manually copy to jniLibs" step, then, maybe it can even be edited to exclude "/OSX, /Windows" directories too since they are not that useful on android apk builds. Many thanks, sorry if this has already been asked/requested/etc, I checked the wiki as best as I could. |
Also, if it hasn't been suggested, jCenter/Maven allows owners to deploy "aar" packages to the project with the jar, and then users just reference the aar like "compile 'com.fazecast:jSerialComm:2.5.0@aar'". If this was done it'd be a lot easier for android users, and also woudln't affect non-android users in anyway. Also, packaging an aar will let you remove the "OSX/Windows/etc" binaries, include a proguard file for the library, and let android studio auto include any native library dependencies in the aar. It would be a great addition to the library since jSerialComm is basically the best native serial access library for android already. Thanks. |
Im getting this error on Android 7.1
Is there a way to use it on android? |
I would like to work on the AAR delivery. Easiest would be to convert the project to a multi-module project and include an |
I need that question too. How did you solve it? |
Android supports USB serial hardware in host mode (OTG), no root access required. IMHO, currently this is the only way that can be used to implement Android compatibility for jSerialComm in a user-friendly manner. Bluetooth serial communication can also be taken into account, but I think it's better to start with USB. As a result, jSerialComm users will be able to use almost all USB serial converters, e.g. FTDI, Prolific, Silabs and other devices implementing the USB CDC protocol. References: |
I have a rooted Android device. This is the first error I encountered -
Given solution didn't work. I remember of having some issues with the I ran
You can see that I have 2 ABI types and the When There is a work around you can think of so it would pick the Many thanks.. |
@orensharon, good catch! I missed that some of the Android architectures had become deprecated (and also that some of them no longer use the I've updated the library to correctly use the Android props now. If you have the ability to manually add a library to your project, you can test the following beta version of 2.9.0: https://www.dropbox.com/t/05S9zYWyedbs7RAN If not, this update will be in the next release. Thanks for bringing it to my attention! |
@hedgecrw, thank you for the response. I tried to load the JAR. Now the
BTW I also noticed that |
Ah yes, that's a new method in the upcoming release that's only halfway implemented right now. Apologies about that. The important thing is that the native library was chosen and (attempted to) load correctly. It should work fine in the next release. I'll post back here when that is made. Thanks for testing! |
This should be fully functional with today's release of v2.9.0. Thanks! |
Hello again, So I now I tried with the official
Log output:
|
Will do. I've been trying to get my own Android setup recreated so I can test this further, but it's become a bit of a nightmare because it looks like they've locked down their devices even more (even from a rooting perspective) in the long interim since this was initially working. With regards to the error you're seeing, my suspicion is that the Android NDK has been updated over the years so that it now adds a bunch of new runtime checks by default (like the https://www.dropbox.com/t/6hoybASQYqpJOtPY Ultimately though, I'm working to move away from using any of the native libraries on Android so that users can make use of this library without having to root their devices. |
Sounds great. Thank you for the efforts. Unfortunately it still fails on loading the native library file: The error:
|
Gotcha, at least it made it past the runtime checks Android was adding to an actual library function call. Here is a new version with that call removed for Android: |
Now we getting some good progress.... The only thing I notice at this point is a strange string in the logs:
|
Great! And thanks for the info from the log file - that's definitely a bug, and I see where it's coming from in the native code. I've patched it here: |
Now the logs looks good!
I will let you know if I will find anything else |
@orensharon, great, thanks for testing! As one more final test before releasing, could you please test this final beta4 version: https://www.dropbox.com/t/ywoycnP7qRGjZDCG I've moved native library initialization into JNI_OnLoad and want to make sure it still works for you under Android. |
Sure! I did the test, seems like everything is working well and the message
|
@orensharon |
Hey @orensharon, can you please say what Android hardware are you using? |
@gresolio |
I manually copied the so file to the Android libs directory; And I can also see the libjserialComm.so file in apk.armeabi-v7a but also got exceptions like this: i debug found this path: but cacheDir is empty, if i manual copy the libjSerialComm.so to jniLibs, it will be found in /data/user/0/com.queal.test/lib, or /data/user/0/com.queal.test/lib-main i try to set |
I had the same issue of @queal, adding the libjSerialComm.so file in the jniLibs/arm64-v8a folder seems to be not enough. |
I tried what has been written here, and I am getting the library to load. And when I run the app it does ask for root permission. So that seems to all work fine. But when I try to actually open the serial port SELinux just denies it. I am running this on a rooted Sony Xperia Hello - running Android 8.0. This is basically what I am trying:
And the resulting error:
Any ideas on what could be wrong? |
If somebody got |
Placeholder issue to track the status of Android compatibility within this library. Right now, rooting is required, and there appear to be a number of issues with including the library in Android Studio. Investigation forthcoming.
References #36 and #45.
The text was updated successfully, but these errors were encountered: