From 92499e2500237b4a4c37cab2324d57c74777ccff Mon Sep 17 00:00:00 2001 From: licheedev Date: Mon, 17 Jun 2024 16:26:47 +0800 Subject: [PATCH 1/2] =?UTF-8?q?2.1.4=20=E4=BF=AE=E5=A4=8D=E5=9B=A0?= =?UTF-8?q?=E4=B8=BA=E4=B8=B2=E5=8F=A3=E4=B8=8D=E5=AD=98=E5=9C=A8=EF=BC=8C?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E5=BC=80=E5=90=AF=E4=B8=B2=E5=8F=A3=E6=97=B6?= =?UTF-8?q?=E4=B8=80=E7=9B=B4=E9=98=BB=E5=A1=9E=E7=BA=BF=E7=A8=8B=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E8=B7=B3=E5=87=BA=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C?= =?UTF-8?q?=E7=8E=B0=E5=9C=A8=E4=BC=9A=E5=85=88=E5=88=A4=E6=96=AD=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E8=B7=AF=E5=BE=84=E6=98=AF=E5=90=A6=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=EF=BC=8C=E4=B8=8D=E5=AD=98=E5=9C=A8=E5=88=99=E7=9B=B4=E6=8E=A5?= =?UTF-8?q?=E6=8A=9B=E5=87=BA=E5=BC=82=E5=B8=B8=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- build.gradle | 2 +- .../java/android/serialport/SerialPort.java | 20 ++++++++++++++----- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index d05c6d4..23a96ba 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ allprojects { } dependencies { - implementation 'com.licheedev:android-serialport:2.1.3' + implementation 'com.licheedev:android-serialport:2.1.4' } ``` diff --git a/build.gradle b/build.gradle index 68e717a..3af971e 100644 --- a/build.gradle +++ b/build.gradle @@ -33,5 +33,5 @@ ext { targetSdkVersion = 29 versionCode = 2 - versionName = "2.1.3" + versionName = "2.1.4" } \ No newline at end of file diff --git a/serialport/src/main/java/android/serialport/SerialPort.java b/serialport/src/main/java/android/serialport/SerialPort.java index 8d4b53d..a07b705 100644 --- a/serialport/src/main/java/android/serialport/SerialPort.java +++ b/serialport/src/main/java/android/serialport/SerialPort.java @@ -82,8 +82,10 @@ public static String getSuPath() { * @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; @@ -92,6 +94,10 @@ public SerialPort(@NonNull File device, int baudrate, int dataBits, int parity, this.stopBits = stopBits; this.flags = flags; + if (!device.exists()) { + throw new IOException("SerialPort(" + device.getAbsolutePath() + ") not exists"); + } + /* Check access permission */ if (!device.canRead() || !device.canWrite()) { try { @@ -112,7 +118,9 @@ public SerialPort(@NonNull File device, int baudrate, int dataBits, int parity, mFd = open(device.getAbsolutePath(), baudrate, dataBits, parity, stopBits, flags); if (mFd == null) { Log.e(TAG, "native open returns null"); - throw new IOException(); + throw new IOException("native open" + + "SerialPort(" + device.getAbsolutePath() + + ") returns null"); } mFileInputStream = new FileInputStream(mFd); mFileOutputStream = new FileOutputStream(mFd); @@ -188,8 +196,10 @@ 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(); From 0768a6bbb9bfb9cace71253a5b1a4b1c5e9f541b Mon Sep 17 00:00:00 2001 From: licheedev Date: Fri, 6 Sep 2024 11:26:40 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E9=80=82=E9=85=8D16KB=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 +++ build.gradle | 6 +++--- gradle/wrapper/gradle-wrapper.properties | 4 ++-- sample/build.gradle | 4 ++-- serialport/CMakeLists.txt | 10 ++++++++-- serialport/build.gradle | 6 ++++++ 6 files changed, 24 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 23a96ba..f54c0ec 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,10 @@ allprojects { } dependencies { + // 传统4KB内存页面版本 implementation 'com.licheedev:android-serialport:2.1.4' + // 适配16KB页面版本,https://developer.android.google.cn/guide/practices/page-sizes?hl=zh-cn + implementation 'com.licheedev:android-serialport:2.1.5' } ``` diff --git a/build.gradle b/build.gradle index 3af971e..a47094e 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:4.0.1' + classpath 'com.android.tools.build:gradle:4.2.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' @@ -32,6 +32,6 @@ ext { minSdkVersion = 8 targetSdkVersion = 29 - versionCode = 2 - versionName = "2.1.4" + versionCode = 3 + versionName = "2.1.5" } \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e95cacb..3ed5e54 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 +#Fri Sep 06 10:04:58 CST 2024 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip diff --git a/sample/build.gradle b/sample/build.gradle index f2834ca..00bc09a 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -27,6 +27,6 @@ dependencies { }) implementation 'androidx.appcompat:appcompat:1.2.0' testImplementation 'junit:junit:4.13' - implementation project(':serialport') - //implementation 'com.licheedev:android-serialport:2.1.3' + //implementation project(':serialport') + implementation 'com.licheedev:android-serialport:2.1.5' } diff --git a/serialport/CMakeLists.txt b/serialport/CMakeLists.txt index f16cb32..80def00 100644 --- a/serialport/CMakeLists.txt +++ b/serialport/CMakeLists.txt @@ -2,7 +2,7 @@ # This ensures that a certain set of CMake features is available to # your build. -cmake_minimum_required(VERSION 3.4.1) +cmake_minimum_required(VERSION 3.18.1) # Specifies a library name, specifies whether the library is STATIC or # SHARED, and provides relative paths to the source code. You can @@ -35,4 +35,10 @@ target_link_libraries( # Specifies the target library. # Links the target library to the log library # included in the NDK. - ${log-lib} ) \ No newline at end of file + ${log-lib} ) + +target_link_options( + serial_port + PRIVATE + "-Wl,-z,max-page-size=16384" +) \ No newline at end of file diff --git a/serialport/build.gradle b/serialport/build.gradle index f9f8f28..b5a36b4 100644 --- a/serialport/build.gradle +++ b/serialport/build.gradle @@ -21,6 +21,12 @@ android { externalNativeBuild { cmake { path 'CMakeLists.txt' + version "3.18.1" + } + } + packagingOptions { + jniLibs { + useLegacyPackaging true } } }