From 9f69245e10a7c1c6d229c8da908dea1065648ef4 Mon Sep 17 00:00:00 2001 From: Steven Broshar Date: Mon, 5 Jun 2023 17:33:42 -0500 Subject: [PATCH 1/3] Use more current SDK and enable NDK build --- libserial/.gitignore | 1 + libserial/build.gradle | 10 ++++++++++ sample/build.gradle | 6 +++--- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/libserial/.gitignore b/libserial/.gitignore index 684a7c8..17bc7cc 100644 --- a/libserial/.gitignore +++ b/libserial/.gitignore @@ -1,3 +1,4 @@ /build /.idea *.iml +/.cxx diff --git a/libserial/build.gradle b/libserial/build.gradle index 159736e..b686f05 100644 --- a/libserial/build.gradle +++ b/libserial/build.gradle @@ -22,6 +22,11 @@ android { targetSdkVersion 30 versionCode 1 versionName "1.0" + externalNativeBuild { + ndkBuild { + cppFlags '-fexceptions' + } + } } buildTypes { @@ -40,6 +45,11 @@ android { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } + externalNativeBuild { + ndkBuild { + path file('src/main/jni/Android.mk') + } + } } dependencies { diff --git a/sample/build.gradle b/sample/build.gradle index 58659e5..3bca0ef 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -1,13 +1,13 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 23 + compileSdkVersion 28 buildToolsVersion "23.0.2" defaultConfig { applicationId "serial.android.sample" - minSdkVersion 16 - targetSdkVersion 23 + minSdkVersion 28 + targetSdkVersion 28 versionCode 1 versionName "1.0" } From e4a042c02dfa4ff347722c58d8986480e84ee98a Mon Sep 17 00:00:00 2001 From: Steven Broshar Date: Mon, 5 Jun 2023 17:33:53 -0500 Subject: [PATCH 2/3] Prevent error if no ports found --- libserial/src/main/java/serial/Serial.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libserial/src/main/java/serial/Serial.java b/libserial/src/main/java/serial/Serial.java index f3b9ece..fd5926b 100644 --- a/libserial/src/main/java/serial/Serial.java +++ b/libserial/src/main/java/serial/Serial.java @@ -158,19 +158,17 @@ public class Serial implements Closeable { * @return an array of available ports. */ public static PortInfo[] listPorts() { - PortInfo[] ports; String[] portDescs = native_listPorts(); if (portDescs != null && portDescs.length > 0) { - ports = new PortInfo[portDescs.length]; + PortInfo[] ports = new PortInfo[portDescs.length]; int index = 0; for (String portDesc : portDescs) { String[] parts = FIELD_DELIM.split(portDesc); ports[index++] = new PortInfo(parts[0], parts[1], parts[2]); } - } else { - ports = null; + return ports; } - return ports; + return new PortInfo[0]; } /** From 186bd392e548c9ba6f55167a5431c33df8e75b18 Mon Sep 17 00:00:00 2001 From: Steven Broshar Date: Mon, 5 Jun 2023 17:44:48 -0500 Subject: [PATCH 3/3] readme --- README.md | 62 +++++++++++++++++++++---------------------------------- 1 file changed, 23 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 9f10eb3..e2f4c90 100644 --- a/README.md +++ b/README.md @@ -1,48 +1,43 @@ -# Serial Port communication library for Android (with Java API) +# Serial Port Comms for Android - Java -This is a serial port library for Android, with both JNI API and Java API. +This is a serial port communications library for Android with Java API on top of C++ implementation with JNI interface. -The Java API is bridged to JNI implementation, and not all of the API is strictly tested. Use it at your own risk. +The underlying implementation is wjwwood's cross-platform serial library https://github.com/wjwwood/serial. -This library is based on wjwwood's cross-platform serial library https://github.com/wjwwood/serial. +[TOC] -### NOT UNDERT MAINTIANCE -I'm too busy to maintain this open source project. -You can fork and made any changes whenever needed. +# Technology +* Android +* Native Development Kit (NDK) +* Java +* C++ -### Documentation +# Source Code -* Native API: See original C++ document at http://wjwwood.github.com/serial/ -* Java API: See javadoc in source files. + git clone https://github.com/stevebroshar/serial-android.git -### Dependencies +# Debug -* NDK r21e +Run in Android Studio. -### Install +# Consume -Get the code: +Add the source files to your project or import it as an Android Library project. - git clone https://github.com/chzhong/serial-android.git +# Contributors -Build Native Code: - -Android Studio NDK support is still in beta, so please build the so files using ndk-build: - - cd android/library/src/main/jni - ./build-jni.sh +William Woodall -Any change to native code it build with Android Studio are welcome. +John Harrison -NOTE: There might be some issue while building with different NDK revisions. +Cheng Zhong -Use: +Steve Broshar mister.broshar@gmail.com -* Use it directly in your native code. -* Import it as an Android Library project. +# License -### License +## wjwwood's cross-platform serial library The MIT License @@ -54,15 +49,4 @@ The above copyright notice and this permission notice shall be included in all c THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -### Authors - -William Woodall -John Harrison - -Cheng Zhong - -### Contact - -William Woodall - -Cheng Zhong +#