From ecd21b93a86994ac16ea0953bd1ef38ecb84a603 Mon Sep 17 00:00:00 2001 From: Key Date: Fri, 25 Feb 2022 10:55:40 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E4=BF=AE=E6=94=B9so=E5=BA=93=E5=91=BD?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 70 +++++++++++++++++++ README.md | 6 ++ build.gradle | 10 +-- .../main/res/xml/serial_port_preferences.xml | 16 +++-- serialport/CMakeLists.txt | 6 +- serialport/build.gradle | 7 +- serialport/src/main/cpp/SerialPort.c | 2 +- .../java/android/serialport/SerialPort.java | 11 +-- 8 files changed, 108 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index a222420..bc2319e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,73 @@ +# Built application files +*.apk +*.ap_ + +# Files for the ART/Dalvik VM +*.dex + +# Java class files +*.class + +# Generated files +bin/ +gen/ +out/ + +# Gradle files +.gradle/ +build/ + +# Local configuration file (sdk path, etc) +local.properties + +# Proguard folder generated by Eclipse +proguard/ + +# Log Files +*.log + +# Android Studio Navigation editor temp files +.navigation/ + +# Android Studio captures folder +captures/ + +# Intellij +*.iml +*.ipr +*.iws +.idea/ + +# Keystore files +#*.jks + +# External native build folder generated in Android Studio 2.2 and later +.externalNativeBuild + +# Google Services (e.g. APIs or Firebase) +google-services.json + +# Freeline +freeline.py +freeline/ +freeline_project_description.json + +# fastlane +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots +fastlane/test_output +fastlane/readme.md + +# Eclipse project files +.classpath +.projec + +# Windows clutter +Thumbs.db +# Mac OS +.DS_Store + *.iml .gradle /local.properties diff --git a/README.md b/README.md index d05c6d4..38c707a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,9 @@ +# Fork后修改 + * 修改so库名,防止和项目中其他依赖了Google原生库的重名问题 + > 因为Google库open是三个参数,本库为6个参数,同名后忽略一个so会导致,open函数找不到入口 + * so库改名为:`libserial_port_ext.so` + * loadLibrary为:`serial_port_ext` + # Android-SerialPort-API [Fork](https://code.google.com/archive/p/android-serialport-api/)自Google开源的Android串口通信Demo,修改成Android Studio项目 diff --git a/build.gradle b/build.gradle index 68e717a..2056b69 100644 --- a/build.gradle +++ b/build.gradle @@ -7,10 +7,10 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:4.0.1' + classpath 'com.android.tools.build:gradle:4.0.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files - classpath 'org.jetbrains.dokka:dokka-gradle-plugin:1.4.32' + //classpath 'org.jetbrains.dokka:dokka-gradle-plugin:1.4.32' } } @@ -27,11 +27,11 @@ task clean(type: Delete) { } ext { - compileSdkVersion = 29 + compileSdkVersion = 31 minSdkVersion = 8 - targetSdkVersion = 29 + targetSdkVersion = 31 versionCode = 2 - versionName = "2.1.3" + versionName = "3.0.0" } \ No newline at end of file diff --git a/sample/src/main/res/xml/serial_port_preferences.xml b/sample/src/main/res/xml/serial_port_preferences.xml index b79e2c5..9840224 100644 --- a/sample/src/main/res/xml/serial_port_preferences.xml +++ b/sample/src/main/res/xml/serial_port_preferences.xml @@ -1,6 +1,14 @@ - - - + + + diff --git a/serialport/CMakeLists.txt b/serialport/CMakeLists.txt index f16cb32..1db4a17 100644 --- a/serialport/CMakeLists.txt +++ b/serialport/CMakeLists.txt @@ -11,14 +11,14 @@ cmake_minimum_required(VERSION 3.4.1) # automatically packages shared libraries with your APK. add_library( # Specifies the name of the library. - serial_port + serial_port_ext # Sets the library as a shared library. SHARED # Provides a relative path to your source file(s). src/main/cpp/SerialPort.c ) - + find_library( # Sets the name of the path variable. log-lib @@ -31,7 +31,7 @@ find_library( # Sets the name of the path variable. # build script, prebuilt third-party libraries, or system libraries. target_link_libraries( # Specifies the target library. - serial_port + serial_port_ext # Links the target library to the log library # included in the NDK. diff --git a/serialport/build.gradle b/serialport/build.gradle index f9f8f28..c062711 100644 --- a/serialport/build.gradle +++ b/serialport/build.gradle @@ -11,6 +11,9 @@ android { versionName rootProject.ext.versionName testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' + ndk { + moduleName = "serial_port_ext" + } } buildTypes { release { @@ -34,8 +37,8 @@ dependencies { // testCompile 'junit:junit:4.12' - api "androidx.annotation:annotation:1.1.0" + compileOnly("androidx.annotation:annotation:1.3.0") } -apply from: '../maven_publish.gradle' +//apply from: '../maven_publish.gradle' diff --git a/serialport/src/main/cpp/SerialPort.c b/serialport/src/main/cpp/SerialPort.c index 07049cb..5215899 100644 --- a/serialport/src/main/cpp/SerialPort.c +++ b/serialport/src/main/cpp/SerialPort.c @@ -26,7 +26,7 @@ #include "android/log.h" -static const char *TAG = "serial_port"; +static const char *TAG = "serial_port_ext"; #define LOGI(fmt, args...) __android_log_print(ANDROID_LOG_INFO, TAG, fmt, ##args) #define LOGD(fmt, args...) __android_log_print(ANDROID_LOG_DEBUG, TAG, fmt, ##args) #define LOGE(fmt, args...) __android_log_print(ANDROID_LOG_ERROR, TAG, fmt, ##args) diff --git a/serialport/src/main/java/android/serialport/SerialPort.java b/serialport/src/main/java/android/serialport/SerialPort.java index 8d4b53d..2cc1a15 100644 --- a/serialport/src/main/java/android/serialport/SerialPort.java +++ b/serialport/src/main/java/android/serialport/SerialPort.java @@ -29,11 +29,12 @@ public final class SerialPort { - private static final String TAG = "SerialPort"; + private static final String TAG = "SerialPortExt"; - public static final String DEFAULT_SU_PATH = "/system/bin/su"; + public static final String BIN_SU_PATH = "/system/bin/su"; + public static final String XBIN_SU_PATH = "/system/xbin/su"; - private static String sSuPath = DEFAULT_SU_PATH; + private static String sSuPath = XBIN_SU_PATH; private File device; private int baudrate; private int dataBits; @@ -42,7 +43,7 @@ public final class SerialPort { private int flags; /** - * Set the su binary path, the default su binary path is {@link #DEFAULT_SU_PATH} + * Set the su binary path, the default su binary path is {@link #BIN_SU_PATH} {@link #XBIN_SU_PATH} * * @param suPath su binary path */ @@ -215,7 +216,7 @@ public void tryClose() { } static { - System.loadLibrary("serial_port"); + System.loadLibrary("serial_port_ext"); } public static Builder newBuilder(File device, int baudrate) { From 5373c0575b679a7668c72321f6158e8df3f8061e Mon Sep 17 00:00:00 2001 From: Key Date: Fri, 25 Feb 2022 11:12:42 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=E4=BF=AE=E6=94=B9so=E5=BA=93=E5=91=BD?= =?UTF-8?q?=E5=90=8D=EF=BC=8C=E4=B8=8A=E4=BC=A0maven=EF=BC=8C=E7=89=88?= =?UTF-8?q?=E6=9C=AC3.0.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- {serialport => library-serial-port-ext}/.gitignore | 0 {serialport => library-serial-port-ext}/CMakeLists.txt | 0 {serialport => library-serial-port-ext}/build.gradle | 8 ++++---- .../proguard-rules.pro | 0 .../src/main/AndroidManifest.xml | 0 .../src/main/cpp/SerialPort.c | 0 .../src/main/cpp/SerialPort.h | 0 .../src/main/cpp/gen_SerialPort_h.sh | 0 .../src/main/java/android/serialport/SerialPort.java | 0 .../main/java/android/serialport/SerialPortFinder.java | 0 .../src/main/res/values/strings.xml | 0 sample/build.gradle | 4 ++-- settings.gradle | 2 +- 13 files changed, 7 insertions(+), 7 deletions(-) rename {serialport => library-serial-port-ext}/.gitignore (100%) rename {serialport => library-serial-port-ext}/CMakeLists.txt (100%) rename {serialport => library-serial-port-ext}/build.gradle (85%) rename {serialport => library-serial-port-ext}/proguard-rules.pro (100%) rename {serialport => library-serial-port-ext}/src/main/AndroidManifest.xml (100%) rename {serialport => library-serial-port-ext}/src/main/cpp/SerialPort.c (100%) rename {serialport => library-serial-port-ext}/src/main/cpp/SerialPort.h (100%) rename {serialport => library-serial-port-ext}/src/main/cpp/gen_SerialPort_h.sh (100%) rename {serialport => library-serial-port-ext}/src/main/java/android/serialport/SerialPort.java (100%) rename {serialport => library-serial-port-ext}/src/main/java/android/serialport/SerialPortFinder.java (100%) rename {serialport => library-serial-port-ext}/src/main/res/values/strings.xml (100%) diff --git a/serialport/.gitignore b/library-serial-port-ext/.gitignore similarity index 100% rename from serialport/.gitignore rename to library-serial-port-ext/.gitignore diff --git a/serialport/CMakeLists.txt b/library-serial-port-ext/CMakeLists.txt similarity index 100% rename from serialport/CMakeLists.txt rename to library-serial-port-ext/CMakeLists.txt diff --git a/serialport/build.gradle b/library-serial-port-ext/build.gradle similarity index 85% rename from serialport/build.gradle rename to library-serial-port-ext/build.gradle index c062711..31acabb 100644 --- a/serialport/build.gradle +++ b/library-serial-port-ext/build.gradle @@ -1,18 +1,18 @@ apply plugin: 'com.android.library' - +ext.libVersion = "3.0.0" android { compileSdkVersion rootProject.ext.compileSdkVersion defaultConfig { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 1 - versionName rootProject.ext.versionName testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' ndk { moduleName = "serial_port_ext" + // 不要x86了,只留下arm + abiFilters "arm64-v8a", "armeabi-v7a" } } buildTypes { @@ -39,6 +39,6 @@ dependencies { compileOnly("androidx.annotation:annotation:1.3.0") } - +apply from: "../../public/KeyLibraryMavenCentralUploader.gradle" //apply from: '../maven_publish.gradle' diff --git a/serialport/proguard-rules.pro b/library-serial-port-ext/proguard-rules.pro similarity index 100% rename from serialport/proguard-rules.pro rename to library-serial-port-ext/proguard-rules.pro diff --git a/serialport/src/main/AndroidManifest.xml b/library-serial-port-ext/src/main/AndroidManifest.xml similarity index 100% rename from serialport/src/main/AndroidManifest.xml rename to library-serial-port-ext/src/main/AndroidManifest.xml diff --git a/serialport/src/main/cpp/SerialPort.c b/library-serial-port-ext/src/main/cpp/SerialPort.c similarity index 100% rename from serialport/src/main/cpp/SerialPort.c rename to library-serial-port-ext/src/main/cpp/SerialPort.c diff --git a/serialport/src/main/cpp/SerialPort.h b/library-serial-port-ext/src/main/cpp/SerialPort.h similarity index 100% rename from serialport/src/main/cpp/SerialPort.h rename to library-serial-port-ext/src/main/cpp/SerialPort.h diff --git a/serialport/src/main/cpp/gen_SerialPort_h.sh b/library-serial-port-ext/src/main/cpp/gen_SerialPort_h.sh similarity index 100% rename from serialport/src/main/cpp/gen_SerialPort_h.sh rename to library-serial-port-ext/src/main/cpp/gen_SerialPort_h.sh diff --git a/serialport/src/main/java/android/serialport/SerialPort.java b/library-serial-port-ext/src/main/java/android/serialport/SerialPort.java similarity index 100% rename from serialport/src/main/java/android/serialport/SerialPort.java rename to library-serial-port-ext/src/main/java/android/serialport/SerialPort.java diff --git a/serialport/src/main/java/android/serialport/SerialPortFinder.java b/library-serial-port-ext/src/main/java/android/serialport/SerialPortFinder.java similarity index 100% rename from serialport/src/main/java/android/serialport/SerialPortFinder.java rename to library-serial-port-ext/src/main/java/android/serialport/SerialPortFinder.java diff --git a/serialport/src/main/res/values/strings.xml b/library-serial-port-ext/src/main/res/values/strings.xml similarity index 100% rename from serialport/src/main/res/values/strings.xml rename to library-serial-port-ext/src/main/res/values/strings.xml diff --git a/sample/build.gradle b/sample/build.gradle index f2834ca..b6c8070 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -5,7 +5,7 @@ android { defaultConfig { applicationId "android.serialport.sample" - minSdkVersion 15 + minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion versionCode 1 versionName "1.0" @@ -27,6 +27,6 @@ dependencies { }) implementation 'androidx.appcompat:appcompat:1.2.0' testImplementation 'junit:junit:4.13' - implementation project(':serialport') + implementation project(':library-serial-port-ext') //implementation 'com.licheedev:android-serialport:2.1.3' } diff --git a/settings.gradle b/settings.gradle index 30d1be0..b04a490 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':serialport', ':sample' +include ':library-serial-port-ext', ':sample' From 89fcf7cf45a6d46ab9264a8e66ffaf92ecc8314d Mon Sep 17 00:00:00 2001 From: Key Date: Fri, 25 Feb 2022 11:42:16 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=80=82=E9=85=8D?= =?UTF-8?q?=E5=8E=9F=E7=89=883=E5=8F=82=E7=9A=84=E6=9E=84=E9=80=A0?= =?UTF-8?q?=EF=BC=8C=E6=96=B9=E4=BE=BF=E5=85=B6=E4=BB=96=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E6=94=B9=E9=80=A0,=20v3.0.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library-serial-port-ext/build.gradle | 2 +- .../java/android/serialport/SerialPort.java | 74 ++++++++++++++----- 2 files changed, 57 insertions(+), 19 deletions(-) diff --git a/library-serial-port-ext/build.gradle b/library-serial-port-ext/build.gradle index 31acabb..6c25347 100644 --- a/library-serial-port-ext/build.gradle +++ b/library-serial-port-ext/build.gradle @@ -1,6 +1,6 @@ apply plugin: 'com.android.library' -ext.libVersion = "3.0.0" +ext.libVersion = "3.0.1" android { compileSdkVersion rootProject.ext.compileSdkVersion diff --git a/library-serial-port-ext/src/main/java/android/serialport/SerialPort.java b/library-serial-port-ext/src/main/java/android/serialport/SerialPort.java index 2cc1a15..c69e74e 100644 --- a/library-serial-port-ext/src/main/java/android/serialport/SerialPort.java +++ b/library-serial-port-ext/src/main/java/android/serialport/SerialPort.java @@ -17,8 +17,10 @@ package android.serialport; import android.util.Log; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; + import java.io.File; import java.io.FileDescriptor; import java.io.FileInputStream; @@ -74,17 +76,21 @@ public static String getSuPath() { /** * 串口 * - * @param device 串口设备文件 + * @param device 串口设备文件 * @param baudrate 波特率 * @param dataBits 数据位;默认8,可选值为5~8 - * @param parity 奇偶校验;0:无校验位(NONE,默认);1:奇校验位(ODD);2:偶校验位(EVEN) + * @param parity 奇偶校验;0:无校验位(NONE,默认);1:奇校验位(ODD);2:偶校验位(EVEN) * @param stopBits 停止位;默认1;1:1位停止位;2:2位停止位 - * @param flags 默认0 + * @param flags 默认0 * @throws SecurityException * @throws IOException */ - public SerialPort(@NonNull File device, int baudrate, int dataBits, int parity, int stopBits, - int flags) throws SecurityException, IOException { + public SerialPort(@NonNull File device, + int baudrate, + int dataBits, + int parity, + int stopBits, + int flags) throws SecurityException, IOException { this.device = device; this.baudrate = baudrate; @@ -122,7 +128,7 @@ public SerialPort(@NonNull File device, int baudrate, int dataBits, int parity, /** * 串口,默认的8n1 * - * @param device 串口设备文件 + * @param device 串口设备文件 * @param baudrate 波特率 * @throws SecurityException * @throws IOException @@ -131,19 +137,35 @@ public SerialPort(@NonNull File device, int baudrate) throws SecurityException, this(device, baudrate, 8, 0, 1, 0); } + /** + * 适配原版的3参,默认的8n1 + * + * @param device 串口设备文件 + * @param baudrate 波特率 + * @param flags + * @throws SecurityException + * @throws IOException + */ + public SerialPort(@NonNull File device, int baudrate, int flags) throws SecurityException, IOException { + this(device, baudrate, 8, 0, 1, flags); + } + /** * 串口 * - * @param device 串口设备文件 + * @param device 串口设备文件 * @param baudrate 波特率 * @param dataBits 数据位;默认8,可选值为5~8 - * @param parity 奇偶校验;0:无校验位(NONE,默认);1:奇校验位(ODD);2:偶校验位(EVEN) + * @param parity 奇偶校验;0:无校验位(NONE,默认);1:奇校验位(ODD);2:偶校验位(EVEN) * @param stopBits 停止位;默认1;1:1位停止位;2:2位停止位 * @throws SecurityException * @throws IOException */ - public SerialPort(@NonNull File device, int baudrate, int dataBits, int parity, int stopBits) - throws SecurityException, IOException { + public SerialPort(@NonNull File device, + int baudrate, + int dataBits, + int parity, + int stopBits) throws SecurityException, IOException { this(device, baudrate, dataBits, parity, stopBits, 0); } @@ -158,28 +180,38 @@ public OutputStream getOutputStream() { return mFileOutputStream; } - /** 串口设备文件 */ + /** + * 串口设备文件 + */ @NonNull public File getDevice() { return device; } - /** 波特率 */ + /** + * 波特率 + */ public int getBaudrate() { return baudrate; } - /** 数据位;默认8,可选值为5~8 */ + /** + * 数据位;默认8,可选值为5~8 + */ public int getDataBits() { return dataBits; } - /** 奇偶校验;0:无校验位(NONE,默认);1:奇校验位(ODD);2:偶校验位(EVEN) */ + /** + * 奇偶校验;0:无校验位(NONE,默认);1:奇校验位(ODD);2:偶校验位(EVEN) + */ public int getParity() { return parity; } - /** 停止位;默认1;1:1位停止位;2:2位停止位 */ + /** + * 停止位;默认1;1:1位停止位;2:2位停止位 + */ public int getStopBits() { return stopBits; } @@ -189,12 +221,18 @@ public int getFlags() { } // JNI - private native FileDescriptor open(String absolutePath, int baudrate, int dataBits, int parity, - int stopBits, int flags); + private native FileDescriptor open(String absolutePath, + int baudrate, + int dataBits, + int parity, + int stopBits, + int flags); public native void close(); - /** 关闭流和串口,已经try-catch */ + /** + * 关闭流和串口,已经try-catch + */ public void tryClose() { try { mFileInputStream.close(); From 1f0d1e44cab56f76e2db9c88c9dd37aec5d85ecb Mon Sep 17 00:00:00 2001 From: Key Date: Sat, 2 Apr 2022 17:46:34 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E6=B3=A2=E7=89=B9=E7=8E=87=E6=9C=89=E6=95=88=E6=80=A7=E7=9A=84?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 21 +++++-- build.gradle | 4 -- gradle/wrapper/gradle-wrapper.properties | 6 +- library-serial-port-ext/build.gradle | 4 +- .../android/serialport/SerialPortUtil.java | 55 +++++++++++++++++++ .../src/main/res/values/strings.xml | 3 - settings.gradle | 2 +- 7 files changed, 76 insertions(+), 19 deletions(-) create mode 100644 library-serial-port-ext/src/main/java/android/serialport/SerialPortUtil.java delete mode 100644 library-serial-port-ext/src/main/res/values/strings.xml diff --git a/README.md b/README.md index 38c707a..ff72b02 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,20 @@ # Fork后修改 + * 修改so库名,防止和项目中其他依赖了Google原生库的重名问题 > 因为Google库open是三个参数,本库为6个参数,同名后忽略一个so会导致,open函数找不到入口 + * so库改名为:`libserial_port_ext.so` + * loadLibrary为:`serial_port_ext` + * so只保留了"arm64-v8a", "armeabi-v7a"两种架构 + + * 新增一个波特率有效性的判断方法,在SerialPortUtil中,因为SerialPort.c中判断了常规的波特率 + + + # Android-SerialPort-API -[Fork](https://code.google.com/archive/p/android-serialport-api/)自Google开源的Android串口通信Demo,修改成Android Studio项目 +[Fork](https://code.google.com/archive/p/android-serialport-api/)自Google开源的Android串口通信Demo,修改成Android Studio项目 This lib is a [fork](https://code.google.com/archive/p/android-serialport-api/) of the Android serial port communication Demo open sourced by Google. @@ -57,19 +66,19 @@ SerialPort serialPort = new SerialPort(path, baudrate); // 可选配置数据位、校验位、停止位 - 7E2(7数据位、偶校验、2停止位) // or with builder (with optional configurations) - 7E2 (7 data bits, even parity, 2 stop bits) -SerialPort serialPort = SerialPort +SerialPort serialPort = SerialPort .newBuilder(path, baudrate) // 校验位;0:无校验位(NONE,默认);1:奇校验位(ODD);2:偶校验位(EVEN) // Check bit; 0: no check bit (NONE, default); 1: odd check bit (ODD); 2: even check bit (EVEN) -// .parity(2) +// .parity(2) // 数据位,默认8;可选值为5~8 // Data bit, default 8; optional value is 5~8 -// .dataBits(7) +// .dataBits(7) // 停止位,默认1;1:1位停止位;2:2位停止位 // Stop bit, default 1; 1:1 stop bit; 2: 2 stop bit -// .stopBits(2) +// .stopBits(2) .build(); - + // read/write to serial port - needs to be in different thread! InputStream in = serialPort.getInputStream(); OutputStream out = serialPort.getOutputStream(); diff --git a/build.gradle b/build.gradle index 2056b69..6c23673 100644 --- a/build.gradle +++ b/build.gradle @@ -28,10 +28,6 @@ task clean(type: Delete) { ext { compileSdkVersion = 31 - minSdkVersion = 8 targetSdkVersion = 31 - - versionCode = 2 - versionName = "3.0.0" } \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e95cacb..09f77e7 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Aug 26 17:00:59 CST 2020 +#Mon Mar 07 17:19:04 CST 2022 distributionBase=GRADLE_USER_HOME +distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.2-bin.zip distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip +zipStoreBase=GRADLE_USER_HOME diff --git a/library-serial-port-ext/build.gradle b/library-serial-port-ext/build.gradle index 6c25347..a55ca19 100644 --- a/library-serial-port-ext/build.gradle +++ b/library-serial-port-ext/build.gradle @@ -1,6 +1,6 @@ apply plugin: 'com.android.library' -ext.libVersion = "3.0.1" +ext.libVersion = "3.0.2" android { compileSdkVersion rootProject.ext.compileSdkVersion @@ -39,6 +39,6 @@ dependencies { compileOnly("androidx.annotation:annotation:1.3.0") } -apply from: "../../public/KeyLibraryMavenCentralUploader.gradle" +apply from: "../../public/zxslLibraryMavenUploader.gradle" //apply from: '../maven_publish.gradle' diff --git a/library-serial-port-ext/src/main/java/android/serialport/SerialPortUtil.java b/library-serial-port-ext/src/main/java/android/serialport/SerialPortUtil.java new file mode 100644 index 0000000..3e9bdc6 --- /dev/null +++ b/library-serial-port-ext/src/main/java/android/serialport/SerialPortUtil.java @@ -0,0 +1,55 @@ +package android.serialport; + +/** + * @author Key + * Time: 2022/04/02 17:30 + * Description: + */ +class SerialPortUtil { + + /** + * 是否是常用波特率,因为c代码那边是有控制的,所以虽然波特率可以随意,但是输入不常用的,那边只会返回-1,所以还是提前检测好比较好 + * 从SerialPort.c复制过来的,跟写个List.contains()也没差 + * + * @param baudRate + * @return + */ + public static boolean isValidBaudRete(int baudRate) { + switch (baudRate) { + case 0: + case 50: + case 75: + case 110: + case 134: + case 150: + case 200: + case 300: + case 600: + case 1200: + case 1800: + case 2400: + case 4800: + case 9600: + case 19200: + case 38400: + case 57600: + case 115200: + case 230400: + case 460800: + case 500000: + case 576000: + case 921600: + case 1000000: + case 1152000: + case 1500000: + case 2000000: + case 2500000: + case 3000000: + case 3500000: + case 4000000: + return true; + default: + return false; + } + } +} diff --git a/library-serial-port-ext/src/main/res/values/strings.xml b/library-serial-port-ext/src/main/res/values/strings.xml deleted file mode 100644 index 46804bf..0000000 --- a/library-serial-port-ext/src/main/res/values/strings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - SerialPortSource - diff --git a/settings.gradle b/settings.gradle index b04a490..b249709 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':library-serial-port-ext', ':sample' +include ':library-serial-port-ext' From a888a1c9f891dc862dafc00dacd340dadf9173fa Mon Sep 17 00:00:00 2001 From: Key Date: Sat, 2 Apr 2022 17:46:34 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E6=B3=A2=E7=89=B9=E7=8E=87=E6=9C=89=E6=95=88=E6=80=A7=E7=9A=84?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 21 +++++-- build.gradle | 4 -- gradle/wrapper/gradle-wrapper.properties | 6 +- library-serial-port-ext/build.gradle | 4 +- .../android/serialport/SerialPortUtil.java | 55 +++++++++++++++++++ .../src/main/res/values/strings.xml | 3 - settings.gradle | 2 +- 7 files changed, 76 insertions(+), 19 deletions(-) create mode 100644 library-serial-port-ext/src/main/java/android/serialport/SerialPortUtil.java delete mode 100644 library-serial-port-ext/src/main/res/values/strings.xml diff --git a/README.md b/README.md index 38c707a..ff72b02 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,20 @@ # Fork后修改 + * 修改so库名,防止和项目中其他依赖了Google原生库的重名问题 > 因为Google库open是三个参数,本库为6个参数,同名后忽略一个so会导致,open函数找不到入口 + * so库改名为:`libserial_port_ext.so` + * loadLibrary为:`serial_port_ext` + * so只保留了"arm64-v8a", "armeabi-v7a"两种架构 + + * 新增一个波特率有效性的判断方法,在SerialPortUtil中,因为SerialPort.c中判断了常规的波特率 + + + # Android-SerialPort-API -[Fork](https://code.google.com/archive/p/android-serialport-api/)自Google开源的Android串口通信Demo,修改成Android Studio项目 +[Fork](https://code.google.com/archive/p/android-serialport-api/)自Google开源的Android串口通信Demo,修改成Android Studio项目 This lib is a [fork](https://code.google.com/archive/p/android-serialport-api/) of the Android serial port communication Demo open sourced by Google. @@ -57,19 +66,19 @@ SerialPort serialPort = new SerialPort(path, baudrate); // 可选配置数据位、校验位、停止位 - 7E2(7数据位、偶校验、2停止位) // or with builder (with optional configurations) - 7E2 (7 data bits, even parity, 2 stop bits) -SerialPort serialPort = SerialPort +SerialPort serialPort = SerialPort .newBuilder(path, baudrate) // 校验位;0:无校验位(NONE,默认);1:奇校验位(ODD);2:偶校验位(EVEN) // Check bit; 0: no check bit (NONE, default); 1: odd check bit (ODD); 2: even check bit (EVEN) -// .parity(2) +// .parity(2) // 数据位,默认8;可选值为5~8 // Data bit, default 8; optional value is 5~8 -// .dataBits(7) +// .dataBits(7) // 停止位,默认1;1:1位停止位;2:2位停止位 // Stop bit, default 1; 1:1 stop bit; 2: 2 stop bit -// .stopBits(2) +// .stopBits(2) .build(); - + // read/write to serial port - needs to be in different thread! InputStream in = serialPort.getInputStream(); OutputStream out = serialPort.getOutputStream(); diff --git a/build.gradle b/build.gradle index 2056b69..6c23673 100644 --- a/build.gradle +++ b/build.gradle @@ -28,10 +28,6 @@ task clean(type: Delete) { ext { compileSdkVersion = 31 - minSdkVersion = 8 targetSdkVersion = 31 - - versionCode = 2 - versionName = "3.0.0" } \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e95cacb..09f77e7 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Aug 26 17:00:59 CST 2020 +#Mon Mar 07 17:19:04 CST 2022 distributionBase=GRADLE_USER_HOME +distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.2-bin.zip distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip +zipStoreBase=GRADLE_USER_HOME diff --git a/library-serial-port-ext/build.gradle b/library-serial-port-ext/build.gradle index 6c25347..a55ca19 100644 --- a/library-serial-port-ext/build.gradle +++ b/library-serial-port-ext/build.gradle @@ -1,6 +1,6 @@ apply plugin: 'com.android.library' -ext.libVersion = "3.0.1" +ext.libVersion = "3.0.2" android { compileSdkVersion rootProject.ext.compileSdkVersion @@ -39,6 +39,6 @@ dependencies { compileOnly("androidx.annotation:annotation:1.3.0") } -apply from: "../../public/KeyLibraryMavenCentralUploader.gradle" +apply from: "../../public/zxslLibraryMavenUploader.gradle" //apply from: '../maven_publish.gradle' diff --git a/library-serial-port-ext/src/main/java/android/serialport/SerialPortUtil.java b/library-serial-port-ext/src/main/java/android/serialport/SerialPortUtil.java new file mode 100644 index 0000000..3719316 --- /dev/null +++ b/library-serial-port-ext/src/main/java/android/serialport/SerialPortUtil.java @@ -0,0 +1,55 @@ +package android.serialport; + +/** + * @author Key + * Time: 2022/04/02 17:30 + * Description: + */ +public class SerialPortUtil { + + /** + * 是否是常用波特率,因为c代码那边是有控制的,所以虽然波特率可以随意,但是输入不常用的,那边只会返回-1,所以还是提前检测好比较好 + * 从SerialPort.c复制过来的,跟写个List.contains()也没差 + * + * @param baudRate + * @return + */ + public static boolean isValidBaudRete(int baudRate) { + switch (baudRate) { + case 0: + case 50: + case 75: + case 110: + case 134: + case 150: + case 200: + case 300: + case 600: + case 1200: + case 1800: + case 2400: + case 4800: + case 9600: + case 19200: + case 38400: + case 57600: + case 115200: + case 230400: + case 460800: + case 500000: + case 576000: + case 921600: + case 1000000: + case 1152000: + case 1500000: + case 2000000: + case 2500000: + case 3000000: + case 3500000: + case 4000000: + return true; + default: + return false; + } + } +} diff --git a/library-serial-port-ext/src/main/res/values/strings.xml b/library-serial-port-ext/src/main/res/values/strings.xml deleted file mode 100644 index 46804bf..0000000 --- a/library-serial-port-ext/src/main/res/values/strings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - SerialPortSource - diff --git a/settings.gradle b/settings.gradle index b04a490..b249709 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':library-serial-port-ext', ':sample' +include ':library-serial-port-ext' From 55ef74431bf1f3b66093c84f9c9acb6e4a2ce569 Mon Sep 17 00:00:00 2001 From: Key Date: Sat, 2 Apr 2022 18:29:50 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E6=9C=80=E6=96=B0=E5=8F=AF=E7=94=A8=E4=B8=B2?= =?UTF-8?q?=E5=8F=A3=E5=88=97=E8=A1=A8=E7=9A=84=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library-serial-port-ext/build.gradle | 2 +- .../android/serialport/SerialPortFinder.java | 12 ++++++------ .../java/android/serialport/SerialPortUtil.java | 17 +++++++++++++++-- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/library-serial-port-ext/build.gradle b/library-serial-port-ext/build.gradle index a55ca19..bfe2126 100644 --- a/library-serial-port-ext/build.gradle +++ b/library-serial-port-ext/build.gradle @@ -1,6 +1,6 @@ apply plugin: 'com.android.library' -ext.libVersion = "3.0.2" +ext.libVersion = "3.0.4" android { compileSdkVersion rootProject.ext.compileSdkVersion diff --git a/library-serial-port-ext/src/main/java/android/serialport/SerialPortFinder.java b/library-serial-port-ext/src/main/java/android/serialport/SerialPortFinder.java index 229a984..355cda6 100644 --- a/library-serial-port-ext/src/main/java/android/serialport/SerialPortFinder.java +++ b/library-serial-port-ext/src/main/java/android/serialport/SerialPortFinder.java @@ -1,17 +1,17 @@ /* * Copyright 2009 Cedric Priscal - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License. + * limitations under the License. */ package android.serialport; @@ -40,7 +40,7 @@ public Vector getDevices() { if (mDevices == null) { mDevices = new Vector(); File dev = new File("/dev"); - + File[] files = dev.listFiles(); if (files != null) { @@ -61,7 +61,7 @@ public String getName() { } } - private static final String TAG = "SerialPort"; + private static final String TAG = "SerialPortExtFinder"; private Vector mDrivers = null; diff --git a/library-serial-port-ext/src/main/java/android/serialport/SerialPortUtil.java b/library-serial-port-ext/src/main/java/android/serialport/SerialPortUtil.java index 3719316..66ddb6c 100644 --- a/library-serial-port-ext/src/main/java/android/serialport/SerialPortUtil.java +++ b/library-serial-port-ext/src/main/java/android/serialport/SerialPortUtil.java @@ -1,5 +1,7 @@ package android.serialport; +import androidx.annotation.NonNull; + /** * @author Key * Time: 2022/04/02 17:30 @@ -11,8 +13,8 @@ public class SerialPortUtil { * 是否是常用波特率,因为c代码那边是有控制的,所以虽然波特率可以随意,但是输入不常用的,那边只会返回-1,所以还是提前检测好比较好 * 从SerialPort.c复制过来的,跟写个List.contains()也没差 * - * @param baudRate - * @return + * @param baudRate 波特率 + * @return 是否可用 */ public static boolean isValidBaudRete(int baudRate) { switch (baudRate) { @@ -52,4 +54,15 @@ public static boolean isValidBaudRete(int baudRate) { return false; } } + + /** + * 获取最新的所有串口地址列表 + * 原版的东西不要改,因为已经是历史API了,太多人太多地方调用 + */ + @NonNull + public static String[] getAvailablePorts() { + // 不单例,会缓存,直接匿名每次刷新 + SerialPortFinder serialPortFinder = new SerialPortFinder(); + return serialPortFinder.getAllDevicesPath(); + } } From 420b80b6cbb7e938efac4ac5cdb54f7be65f663d Mon Sep 17 00:00:00 2001 From: Key Date: Sat, 2 Apr 2022 20:01:29 +0800 Subject: [PATCH 7/9] add: isValidTtyPath() --- library-serial-port-ext/build.gradle | 2 +- .../main/java/android/serialport/SerialPortUtil.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/library-serial-port-ext/build.gradle b/library-serial-port-ext/build.gradle index bfe2126..11cb4ee 100644 --- a/library-serial-port-ext/build.gradle +++ b/library-serial-port-ext/build.gradle @@ -1,6 +1,6 @@ apply plugin: 'com.android.library' -ext.libVersion = "3.0.4" +ext.libVersion = "3.0.5" android { compileSdkVersion rootProject.ext.compileSdkVersion diff --git a/library-serial-port-ext/src/main/java/android/serialport/SerialPortUtil.java b/library-serial-port-ext/src/main/java/android/serialport/SerialPortUtil.java index 66ddb6c..e6f35e2 100644 --- a/library-serial-port-ext/src/main/java/android/serialport/SerialPortUtil.java +++ b/library-serial-port-ext/src/main/java/android/serialport/SerialPortUtil.java @@ -55,6 +55,18 @@ public static boolean isValidBaudRete(int baudRate) { } } + public static boolean isValidTtyPath(String ttyPath) { + boolean isValid = false; + String[] availablePorts = getAvailablePorts(); + for (String port : availablePorts) { + if (port.equals(ttyPath)) { + isValid = true; + break; + } + } + return isValid; + } + /** * 获取最新的所有串口地址列表 * 原版的东西不要改,因为已经是历史API了,太多人太多地方调用 From 8baecbd8ce79e66d2b15aaa253441941d42b0c33 Mon Sep 17 00:00:00 2001 From: Key Date: Wed, 6 Apr 2022 18:06:23 +0800 Subject: [PATCH 8/9] =?UTF-8?q?=E4=BF=AE=E6=94=B9su=E4=BD=8D=E7=BD=AE?= =?UTF-8?q?=EF=BC=8C=E8=87=AA=E9=80=82=E5=BA=94=E5=A4=9A=E7=A7=8D=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library-serial-port-ext/build.gradle | 2 +- .../src/main/java/android/serialport/SerialPort.java | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/library-serial-port-ext/build.gradle b/library-serial-port-ext/build.gradle index 11cb4ee..d185c20 100644 --- a/library-serial-port-ext/build.gradle +++ b/library-serial-port-ext/build.gradle @@ -1,6 +1,6 @@ apply plugin: 'com.android.library' -ext.libVersion = "3.0.5" +ext.libVersion = "3.0.6" android { compileSdkVersion rootProject.ext.compileSdkVersion diff --git a/library-serial-port-ext/src/main/java/android/serialport/SerialPort.java b/library-serial-port-ext/src/main/java/android/serialport/SerialPort.java index c69e74e..b2883aa 100644 --- a/library-serial-port-ext/src/main/java/android/serialport/SerialPort.java +++ b/library-serial-port-ext/src/main/java/android/serialport/SerialPort.java @@ -36,7 +36,10 @@ public final class SerialPort { public static final String BIN_SU_PATH = "/system/bin/su"; public static final String XBIN_SU_PATH = "/system/xbin/su"; - private static String sSuPath = XBIN_SU_PATH; + /** + * 默认地址改成软连接su,可以自适应位置 + */ + private static String sSuPath = "su"; private File device; private int baudrate; private int dataBits; @@ -105,7 +108,7 @@ public SerialPort(@NonNull File device, /* Missing read/write permission, trying to chmod the file */ Process su; su = Runtime.getRuntime().exec(sSuPath); - String cmd = "chmod 666 " + device.getAbsolutePath() + "\n" + "exit\n"; + String cmd = "chmod 666 " + device.getAbsolutePath() + "\nexit\n"; su.getOutputStream().write(cmd.getBytes()); if ((su.waitFor() != 0) || !device.canRead() || !device.canWrite()) { throw new SecurityException(); From ab251753e711ac744ec3e908d14675331c41ca64 Mon Sep 17 00:00:00 2001 From: Key Date: Thu, 28 Apr 2022 20:06:14 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=80=E4=B8=AAWrite?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 13 +++++----- build.gradle | 7 +---- gradle/wrapper/gradle-wrapper.properties | 4 +-- library-serial-port-ext/build.gradle | 2 +- .../java/android/serialport/SerialPort.java | 19 ++++++++++++++ sample/build.gradle | 12 +++------ .../sample/ExampleInstrumentedTest.java | 26 ------------------- sample/src/main/AndroidManifest.xml | 17 +++++++----- .../android/serialport/sample/MainMenu.java | 12 +++++---- .../serialport/sample/SerialPortActivity.java | 11 ++++---- .../serialport/sample/ExampleUnitTest.java | 17 ------------ settings.gradle | 2 +- 12 files changed, 58 insertions(+), 84 deletions(-) delete mode 100644 sample/src/androidTest/java/android/serialport/sample/ExampleInstrumentedTest.java delete mode 100644 sample/src/test/java/android/serialport/sample/ExampleUnitTest.java diff --git a/README.md b/README.md index ff72b02..030e7f8 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,16 @@ # Fork后修改 + * 修改so库名,防止和项目中其他依赖了Google原生库的重名问题 + > 因为Google库open是三个参数,本库为6个参数,同名后忽略一个so会导致,open函数找不到入口 - * 修改so库名,防止和项目中其他依赖了Google原生库的重名问题 - > 因为Google库open是三个参数,本库为6个参数,同名后忽略一个so会导致,open函数找不到入口 + * so库改名为:`libserial_port_ext.so` - * so库改名为:`libserial_port_ext.so` + * loadLibrary为:`serial_port_ext` - * loadLibrary为:`serial_port_ext` + * so只保留了"arm64-v8a", "armeabi-v7a"两种架构 - * so只保留了"arm64-v8a", "armeabi-v7a"两种架构 + * 新增一个波特率有效性的判断方法,在SerialPortUtil中,因为SerialPort.c中判断了常规的波特率 - * 新增一个波特率有效性的判断方法,在SerialPortUtil中,因为SerialPort.c中判断了常规的波特率 + * 新增一个write方法,方便使用,不用再在外部持有FileOutputStream diff --git a/build.gradle b/build.gradle index 6c23673..0195fdd 100644 --- a/build.gradle +++ b/build.gradle @@ -3,21 +3,16 @@ buildscript { repositories { google() - jcenter() mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:4.0.2' - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files - //classpath 'org.jetbrains.dokka:dokka-gradle-plugin:1.4.32' + classpath 'com.android.tools.build:gradle:7.1.3' } } allprojects { repositories { google() - jcenter() mavenCentral() } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 09f77e7..479aa78 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Mar 07 17:19:04 CST 2022 +#Thu Apr 28 14:51:12 CST 2022 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/library-serial-port-ext/build.gradle b/library-serial-port-ext/build.gradle index d185c20..80a062a 100644 --- a/library-serial-port-ext/build.gradle +++ b/library-serial-port-ext/build.gradle @@ -1,6 +1,6 @@ apply plugin: 'com.android.library' -ext.libVersion = "3.0.6" +ext.libVersion = "3.0.7" android { compileSdkVersion rootProject.ext.compileSdkVersion diff --git a/library-serial-port-ext/src/main/java/android/serialport/SerialPort.java b/library-serial-port-ext/src/main/java/android/serialport/SerialPort.java index b2883aa..2b07a05 100644 --- a/library-serial-port-ext/src/main/java/android/serialport/SerialPort.java +++ b/library-serial-port-ext/src/main/java/android/serialport/SerialPort.java @@ -256,6 +256,25 @@ public void tryClose() { } } + public boolean write(byte[] buffer) { + try { + if (this.mFileOutputStream == null) { + return false; + } else { + this.mFileOutputStream.write(buffer); + this.mFileOutputStream.flush(); + return true; + } + } catch (IOException exception) { + Log.e(TAG, "write bytes error", exception); + return false; + } + } + + public boolean write(String str) { + return this.write(str.getBytes()); + } + static { System.loadLibrary("serial_port_ext"); } diff --git a/sample/build.gradle b/sample/build.gradle index b6c8070..70319c2 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -5,12 +5,13 @@ android { defaultConfig { applicationId "android.serialport.sample" - minSdkVersion rootProject.ext.minSdkVersion + minSdkVersion 16 targetSdkVersion rootProject.ext.targetSdkVersion versionCode 1 versionName "1.0" - - testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' + ndk { + abiFilters "arm64-v8a", "armeabi-v7a" + } } buildTypes { release { @@ -22,11 +23,6 @@ android { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', { - exclude group: 'com.android.support', module: 'support-annotations' - }) - implementation 'androidx.appcompat:appcompat:1.2.0' - testImplementation 'junit:junit:4.13' implementation project(':library-serial-port-ext') //implementation 'com.licheedev:android-serialport:2.1.3' } diff --git a/sample/src/androidTest/java/android/serialport/sample/ExampleInstrumentedTest.java b/sample/src/androidTest/java/android/serialport/sample/ExampleInstrumentedTest.java deleted file mode 100644 index a7501ea..0000000 --- a/sample/src/androidTest/java/android/serialport/sample/ExampleInstrumentedTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package android.serialport.sample; - -import android.content.Context; -import androidx.test.platform.app.InstrumentationRegistry; -import androidx.test.ext.junit.runners.AndroidJUnit4; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import static org.junit.Assert.*; - -/** - * Instrumentation test, which will execute on an Android device. - * - * @see Testing documentation - */ -@RunWith(AndroidJUnit4.class) -public class ExampleInstrumentedTest { - @Test - public void useAppContext() throws Exception { - // Context of the app under test. - Context appContext = InstrumentationRegistry.getTargetContext(); - - assertEquals("android.serialport.sample", appContext.getPackageName()); - } -} diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index 185fb34..07a97ee 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -1,6 +1,6 @@ - + - + - - - - + + + + \ No newline at end of file diff --git a/sample/src/main/java/android/serialport/sample/MainMenu.java b/sample/src/main/java/android/serialport/sample/MainMenu.java index 4601962..45e3e2b 100644 --- a/sample/src/main/java/android/serialport/sample/MainMenu.java +++ b/sample/src/main/java/android/serialport/sample/MainMenu.java @@ -1,17 +1,17 @@ /* * Copyright 2009 Cedric Priscal - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License. + * limitations under the License. */ package android.serialport.sample; @@ -25,7 +25,9 @@ public class MainMenu extends Activity { - /** Called when the activity is first created. */ + /** + * Called when the activity is first created. + */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/sample/src/main/java/android/serialport/sample/SerialPortActivity.java b/sample/src/main/java/android/serialport/sample/SerialPortActivity.java index b8991e3..cf595c5 100644 --- a/sample/src/main/java/android/serialport/sample/SerialPortActivity.java +++ b/sample/src/main/java/android/serialport/sample/SerialPortActivity.java @@ -1,17 +1,17 @@ /* * Copyright 2009 Cedric Priscal - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License. + * limitations under the License. */ package android.serialport.sample; @@ -22,6 +22,7 @@ import android.content.DialogInterface.OnClickListener; import android.os.Bundle; import android.serialport.SerialPort; + import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -78,7 +79,7 @@ protected void onCreate(Bundle savedInstanceState) { mOutputStream = mSerialPort.getOutputStream(); mInputStream = mSerialPort.getInputStream(); - /* Create a receiving thread */ + /* Create a receiving thread */ mReadThread = new ReadThread(); mReadThread.start(); } catch (SecurityException e) { diff --git a/sample/src/test/java/android/serialport/sample/ExampleUnitTest.java b/sample/src/test/java/android/serialport/sample/ExampleUnitTest.java deleted file mode 100644 index 9069e42..0000000 --- a/sample/src/test/java/android/serialport/sample/ExampleUnitTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package android.serialport.sample; - -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Example local unit test, which will execute on the development machine (host). - * - * @see Testing documentation - */ -public class ExampleUnitTest { - @Test - public void addition_isCorrect() throws Exception { - assertEquals(4, 2 + 2); - } -} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index b249709..1216102 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':library-serial-port-ext' +include ':sample', ':library-serial-port-ext' \ No newline at end of file