From 6661aadcf8c5e97794490f0fcf313586f21f6999 Mon Sep 17 00:00:00 2001 From: licheedev Date: Wed, 26 Aug 2020 17:47:00 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E5=8F=91=E5=B8=83=E5=88=B0jcenter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 19 +--- build.gradle | 11 +-- gradle.properties | 2 + gradle/wrapper/gradle-wrapper.properties | 4 +- jitpack.gradle | 30 ------- sample/build.gradle | 11 +-- .../sample/ExampleInstrumentedTest.java | 4 +- serialport/.gitignore | 1 + serialport/bintray.gradle | 86 +++++++++++++++++++ serialport/build.gradle | 6 +- serialport/src/main/AndroidManifest.xml | 12 +-- .../java/android/serialport/SerialPort.java | 36 +++++++- 12 files changed, 146 insertions(+), 76 deletions(-) delete mode 100644 jitpack.gradle create mode 100644 serialport/bintray.gradle diff --git a/README.md b/README.md index aa0afce..96bb425 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,12 @@ # Android-SerialPort-API -[![](https://jitpack.io/v/licheedev/Android-SerialPort-API.svg)](https://jitpack.io/#licheedev/Android-SerialPort-API) - **Gradle 引用** -1. 在根build.gradle中添加 - -``` -allprojects { - repositories { - ... - maven { url 'https://jitpack.io' } - } -} -``` - -2. 子module添加依赖 +添加依赖 ``` dependencies { - implementation 'com.github.licheedev:Android-SerialPort-API:2.0.0' + implementation 'com.licheedev:android-serialport:2.1.1' } ``` @@ -39,7 +26,7 @@ SerialPort.setSuPath("/system/xbin/su"); ```java // 默认8N1(8数据位、无校验位、1停止位) -SerialPort serialPort = SerialPort.newBuilder(path, baudrate).build(); +SerialPort serialPort = new SerialPort(path, baudrate); // 7E2(7数据位、偶校验、2停止位) SerialPort serialPort = SerialPort // diff --git a/build.gradle b/build.gradle index 4b0c6dd..f73582b 100644 --- a/build.gradle +++ b/build.gradle @@ -6,10 +6,11 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.2.1' - classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' + classpath 'com.android.tools.build:gradle:4.0.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files + classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' + classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' } } @@ -25,11 +26,11 @@ task clean(type: Delete) { } ext { - compileSdkVersion = 28 + compileSdkVersion = 29 minSdkVersion = 8 - targetSdkVersion = 28 + targetSdkVersion = 29 versionCode = 2 - versionName = "2.0.0" + versionName = "2.1.1" } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index aa62a10..567806c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,4 +13,6 @@ # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true #Mon Sep 18 19:30:46 CST 2017 +android.enableJetifier=true +android.useAndroidX=true org.gradle.jvmargs=-Xmx1536m diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 8afa263..e95cacb 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Jul 03 10:00:36 CST 2019 +#Wed Aug 26 17:00:59 CST 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip diff --git a/jitpack.gradle b/jitpack.gradle deleted file mode 100644 index 3e87c62..0000000 --- a/jitpack.gradle +++ /dev/null @@ -1,30 +0,0 @@ -apply plugin: 'com.github.dcendents.android-maven' - -group = 'com.github.licheedev' - -tasks.withType(JavaCompile) { - options.encoding = "UTF-8" -} - -task sourcesJar(type: Jar) { - from android.sourceSets.main.java.srcDirs - classifier = 'sources' -} - -task javadoc(type: Javadoc) { - failOnError false - source = android.sourceSets.main.java.sourceFiles - classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) - classpath += configurations.compile -} - - -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.destinationDir -} - -artifacts { - archives sourcesJar - archives javadocJar -} \ No newline at end of file diff --git a/sample/build.gradle b/sample/build.gradle index 85a2529..167098d 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -10,7 +10,7 @@ android { versionCode 1 versionName "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' } buildTypes { release { @@ -22,10 +22,11 @@ android { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { + androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', { exclude group: 'com.android.support', module: 'support-annotations' }) - implementation 'com.android.support:appcompat-v7:27.1.1' - testImplementation 'junit:junit:4.12' - implementation project(':serialport') + implementation 'androidx.appcompat:appcompat:1.2.0' + testImplementation 'junit:junit:4.13' +// implementation project(':serialport') + implementation 'com.licheedev:android-serialport:2.1.1' } diff --git a/sample/src/androidTest/java/android/serialport/sample/ExampleInstrumentedTest.java b/sample/src/androidTest/java/android/serialport/sample/ExampleInstrumentedTest.java index b65e8d8..a7501ea 100644 --- a/sample/src/androidTest/java/android/serialport/sample/ExampleInstrumentedTest.java +++ b/sample/src/androidTest/java/android/serialport/sample/ExampleInstrumentedTest.java @@ -1,8 +1,8 @@ package android.serialport.sample; import android.content.Context; -import android.support.test.InstrumentationRegistry; -import android.support.test.runner.AndroidJUnit4; +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/serialport/.gitignore b/serialport/.gitignore index a222170..968c49e 100644 --- a/serialport/.gitignore +++ b/serialport/.gitignore @@ -1,2 +1,3 @@ /build .externalNativeBuild +.cxx diff --git a/serialport/bintray.gradle b/serialport/bintray.gradle new file mode 100644 index 0000000..fbb21ef --- /dev/null +++ b/serialport/bintray.gradle @@ -0,0 +1,86 @@ +//在根build.gradle中加入 +//classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' +//classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' + +//在module的build.gradle末位加入 +//apply from: './bintray.gradle' + +// 执行 ./gradlew clean bintrayUpload + +def toUpload = true // 配置是否上传 +if (toUpload) { + apply plugin: 'com.github.dcendents.android-maven' + apply plugin: 'com.jfrog.bintray' + + // 定义参数 + // 依赖信息 + def groupIdDefined = "com.licheedev" + def artifactIdDefined = "android-serialport" + def versionDefined = rootProject.ext.versionName + // 其他信息 + def siteUrl = "https://github.com/licheedev" + def gitUrl = "https://github.com/licheedev/Android-SerialPort-API.git" + def libName = "$artifactIdDefined" + + // 待发布项目的groupId和version。android-maven-gradle-plugin插件需要这么配置。 + group = "$groupIdDefined" + version = "$versionDefined" + + // bintray平台信息配置 + bintray { + user = BINTRAY_USER + key = BINTRAY_KEY + + println "user=${user},key=${key}" + + configurations = ['archives'] + publish = true + pkg { + repo = "maven" + name = libName + licenses = [" Apache-2.0"] + websiteUrl = siteUrl + vcsUrl = gitUrl + version { + name = "$versionDefined" + } + } + } + + // pom文件信息配置 + install { + repositories.mavenInstaller { + pom.project { + groupId "$groupIdDefined" + artifactId "$artifactIdDefined" + version "$versionDefined" + packaging 'aar' + } + } + } + + // 生成sourceJar和javaDocJar + task sourcesJar(type: Jar) { + from android.sourceSets.main.java.srcDirs + classifier = 'sources' + } + + task javadoc(type: Javadoc) { + failOnError false + source = android.sourceSets.main.java.sourceFiles + options { + encoding = "utf-8" + } + classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) + classpath += configurations.compile + } + task javadocJar(type: Jar, dependsOn: javadoc) { + classifier = 'javadoc' + from javadoc.destinationDir + } + + artifacts { + archives sourcesJar + archives javadocJar + } +} diff --git a/serialport/build.gradle b/serialport/build.gradle index 7f171a1..06aed47 100644 --- a/serialport/build.gradle +++ b/serialport/build.gradle @@ -7,10 +7,10 @@ android { defaultConfig { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode rootProject.ext.versionCode + versionCode 1 versionName rootProject.ext.versionName - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' } buildTypes { release { @@ -34,5 +34,5 @@ dependencies { // testCompile 'junit:junit:4.12' } -apply from: '../jitpack.gradle' +apply from: './bintray.gradle' diff --git a/serialport/src/main/AndroidManifest.xml b/serialport/src/main/AndroidManifest.xml index 808f2ee..6c1ed51 100644 --- a/serialport/src/main/AndroidManifest.xml +++ b/serialport/src/main/AndroidManifest.xml @@ -1,10 +1,4 @@ - - - - - - + + diff --git a/serialport/src/main/java/android/serialport/SerialPort.java b/serialport/src/main/java/android/serialport/SerialPort.java index 7633b3c..641e2bd 100644 --- a/serialport/src/main/java/android/serialport/SerialPort.java +++ b/serialport/src/main/java/android/serialport/SerialPort.java @@ -66,14 +66,14 @@ public static String getSuPath() { * * @param device 串口设备文件 * @param baudrate 波特率 - * @param dataBits 数据位,默认8 - * @param parity 奇偶校验位,默认0(无校验) - * @param stopBits 停止位,默认1 + * @param dataBits 数据位;默认8,可选值为5~8 + * @param parity 奇偶校验;0:无校验位(NONE,默认);1:奇校验位(ODD);2:偶校验位(EVEN) + * @param stopBits 停止位;默认1;1:1位停止位;2:2位停止位 * @param flags 默认0 * @throws SecurityException * @throws IOException */ - private SerialPort(File device, int baudrate, int dataBits, int parity, int stopBits, int flags) + public SerialPort(File device, int baudrate, int dataBits, int parity, int stopBits, int flags) throws SecurityException, IOException { /* Check access permission */ @@ -102,6 +102,34 @@ private SerialPort(File device, int baudrate, int dataBits, int parity, int stop mFileOutputStream = new FileOutputStream(mFd); } + /** + * 串口,默认的8n1 + * + * @param device 串口设备文件 + * @param baudrate 波特率 + * @throws SecurityException + * @throws IOException + */ + public SerialPort(File device, int baudrate) throws SecurityException, IOException { + this(device, baudrate, 8, 0, 1, 0); + } + + /** + * 串口 + * + * @param device 串口设备文件 + * @param baudrate 波特率 + * @param dataBits 数据位;默认8,可选值为5~8 + * @param parity 奇偶校验;0:无校验位(NONE,默认);1:奇校验位(ODD);2:偶校验位(EVEN) + * @param stopBits 停止位;默认1;1:1位停止位;2:2位停止位 + * @throws SecurityException + * @throws IOException + */ + public SerialPort(File device, int baudrate, int dataBits, int parity, int stopBits) + throws SecurityException, IOException { + this(device, baudrate, dataBits, parity, stopBits, 0); + } + // Getters and setters public InputStream getInputStream() { return mFileInputStream; From f66b63276f917fefd0c9e0756e7b6440e0a6b86e Mon Sep 17 00:00:00 2001 From: licheedev Date: Thu, 22 Oct 2020 11:44:13 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E8=8E=B7=E5=8F=96SerialPort=E7=9A=84=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- build.gradle | 2 +- serialport/build.gradle | 3 + .../java/android/serialport/SerialPort.java | 79 +++++++++++++++++-- 4 files changed, 79 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 96bb425..5fb6410 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ ``` dependencies { - implementation 'com.licheedev:android-serialport:2.1.1' + implementation 'com.licheedev:android-serialport:2.1.2' } ``` diff --git a/build.gradle b/build.gradle index f73582b..fd36fc3 100644 --- a/build.gradle +++ b/build.gradle @@ -32,5 +32,5 @@ ext { targetSdkVersion = 29 versionCode = 2 - versionName = "2.1.1" + versionName = "2.1.2" } \ No newline at end of file diff --git a/serialport/build.gradle b/serialport/build.gradle index 06aed47..874cafa 100644 --- a/serialport/build.gradle +++ b/serialport/build.gradle @@ -32,6 +32,9 @@ dependencies { // }) // compile 'com.android.support:appcompat-v7:25.3.0' // testCompile 'junit:junit:4.12' + + + api "androidx.annotation:annotation:1.1.0" } apply from: './bintray.gradle' diff --git a/serialport/src/main/java/android/serialport/SerialPort.java b/serialport/src/main/java/android/serialport/SerialPort.java index 641e2bd..8d4b53d 100644 --- a/serialport/src/main/java/android/serialport/SerialPort.java +++ b/serialport/src/main/java/android/serialport/SerialPort.java @@ -17,6 +17,8 @@ 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; @@ -32,13 +34,19 @@ public final class SerialPort { public static final String DEFAULT_SU_PATH = "/system/bin/su"; private static String sSuPath = DEFAULT_SU_PATH; + private File device; + private int baudrate; + private int dataBits; + private int parity; + private int stopBits; + private int flags; /** * Set the su binary path, the default su binary path is {@link #DEFAULT_SU_PATH} * * @param suPath su binary path */ - public static void setSuPath(String suPath) { + public static void setSuPath(@Nullable String suPath) { if (suPath == null) { return; } @@ -50,6 +58,7 @@ public static void setSuPath(String suPath) { * * @return */ + @NonNull public static String getSuPath() { return sSuPath; } @@ -73,8 +82,15 @@ public static String getSuPath() { * @throws SecurityException * @throws IOException */ - public SerialPort(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; + this.dataBits = dataBits; + this.parity = parity; + this.stopBits = stopBits; + this.flags = flags; /* Check access permission */ if (!device.canRead() || !device.canWrite()) { @@ -110,7 +126,7 @@ public SerialPort(File device, int baudrate, int dataBits, int parity, int stopB * @throws SecurityException * @throws IOException */ - public SerialPort(File device, int baudrate) throws SecurityException, IOException { + public SerialPort(@NonNull File device, int baudrate) throws SecurityException, IOException { this(device, baudrate, 8, 0, 1, 0); } @@ -125,26 +141,79 @@ public SerialPort(File device, int baudrate) throws SecurityException, IOExcepti * @throws SecurityException * @throws IOException */ - public SerialPort(File device, int baudrate, int dataBits, int parity, int stopBits) + public SerialPort(@NonNull File device, int baudrate, int dataBits, int parity, int stopBits) throws SecurityException, IOException { this(device, baudrate, dataBits, parity, stopBits, 0); } // Getters and setters + @NonNull public InputStream getInputStream() { return mFileInputStream; } + @NonNull public OutputStream getOutputStream() { return mFileOutputStream; } + /** 串口设备文件 */ + @NonNull + public File getDevice() { + return device; + } + + /** 波特率 */ + public int getBaudrate() { + return baudrate; + } + + /** 数据位;默认8,可选值为5~8 */ + public int getDataBits() { + return dataBits; + } + + /** 奇偶校验;0:无校验位(NONE,默认);1:奇校验位(ODD);2:偶校验位(EVEN) */ + public int getParity() { + return parity; + } + + /** 停止位;默认1;1:1位停止位;2:2位停止位 */ + public int getStopBits() { + return stopBits; + } + + public int getFlags() { + return flags; + } + // JNI private native FileDescriptor open(String absolutePath, int baudrate, int dataBits, int parity, int stopBits, int flags); public native void close(); + /** 关闭流和串口,已经try-catch */ + public void tryClose() { + try { + mFileInputStream.close(); + } catch (IOException e) { + //e.printStackTrace(); + } + + try { + mFileOutputStream.close(); + } catch (IOException e) { + //e.printStackTrace(); + } + + try { + close(); + } catch (Exception e) { + //e.printStackTrace(); + } + } + static { System.loadLibrary("serial_port"); } From 41363314102df54d67b3577e0cf7a32e45ba5e1a Mon Sep 17 00:00:00 2001 From: Eyal Yoli Abs Date: Wed, 21 Apr 2021 11:37:35 +0300 Subject: [PATCH 3/9] Update README.md + translate to english + add better usage code --- README.md | 57 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 5fb6410..653b98d 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,12 @@ # Android-SerialPort-API +Fork自Google开源的Android串口通信Demo,修改成Android Studio项目 +This lib is a fork of the Android serial port communication Demo open sourced by Google. -**Gradle 引用** +## Installation & Usage +**Gradle** -添加依赖 +添加依赖: +Add the dependency: ``` dependencies { @@ -10,29 +14,54 @@ dependencies { } ``` -**修改`su`路径** +**Import** +```java +import android.serialport.SerialPort; +``` + +**`su` path** + +In order to read/write to a serial port in Android you'll need `su` binary installed on device (this can be done by rooting the device). Usually Android devices that has the ability to communicate with serial ports have `su` installed on the default path `"/system/bin/su"`. To change this use: ```java // su默认路径为 "/system/bin/su" +// The default path of su is "/system/bin/su" // 可通过此方法修改 +// If the path is different then change it using this SerialPort.setSuPath("/system/xbin/su"); ``` -**可选配置数据位、校验位、停止位** - -实现方式参考 -> https://juejin.im/post/5c010a19e51d456ac27b40fc +**Usage** ```java - // 默认8N1(8数据位、无校验位、1停止位) +// Default 8N1 (8 data bits, no parity bit, 1 stop bit) SerialPort serialPort = new SerialPort(path, baudrate); -// 7E2(7数据位、偶校验、2停止位) -SerialPort serialPort = SerialPort // - .newBuilder(path, baudrate) // 串口地址地址,波特率 - .parity(2) // 校验位;0:无校验位(NONE,默认);1:奇校验位(ODD);2:偶校验位(EVEN) - .dataBits(7) // 数据位,默认8;可选值为5~8 - .stopBits(2) // 停止位,默认1;1:1位停止位;2:2位停止位 +// 可选配置数据位、校验位、停止位 - 7E2(7数据位、偶校验、2停止位) +// or with builder (with optional configurations) - 7E2 (7 data bits, even parity, 2 stop bits) +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) +// 数据位,默认8;可选值为5~8 +// Data bit, default 8; optional value is 5~8 +// .dataBits(7) +// 停止位,默认1;1:1位停止位;2:2位停止位 +// Stop bit, default 1; 1:1 stop bit; 2: 2 stop bit +// .stopBits(2) .build(); + +// read/write to serial port - needs to be in different thread! +InputStream in = serialPort.getInputStream(); +OutputStream out = serialPort.getOutputStream(); + +// close +serialPort.tryClose(); ``` + +实现方式参考 +Implementation reference +> Check (sample project)[https://github.com/licheedev/Android-SerialPort-API/tree/master/sample] +> https://juejin.im/post/5c010a19e51d456ac27b40fc From acb2c63a9a263fa2fda4ad33220c1cd44afd62d6 Mon Sep 17 00:00:00 2001 From: Eyal Yoli Abs Date: Wed, 21 Apr 2021 11:39:24 +0300 Subject: [PATCH 4/9] Update README.md fix styles --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 653b98d..19e5d0f 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,13 @@ # Android-SerialPort-API Fork自Google开源的Android串口通信Demo,修改成Android Studio项目 + This lib is a fork of the Android serial port communication Demo open sourced by Google. ## Installation & Usage **Gradle** 添加依赖: + Add the dependency: ``` @@ -15,6 +17,7 @@ dependencies { ``` **Import** + ```java import android.serialport.SerialPort; ``` @@ -62,6 +65,7 @@ serialPort.tryClose(); ``` 实现方式参考 + Implementation reference -> Check (sample project)[https://github.com/licheedev/Android-SerialPort-API/tree/master/sample] -> https://juejin.im/post/5c010a19e51d456ac27b40fc +1. Check [sample project](https://github.com/licheedev/Android-SerialPort-API/tree/master/sample) +2. https://juejin.im/post/5c010a19e51d456ac27b40fc From 0bb2ea97793b06f424a10792e2690b7d9c1d7e86 Mon Sep 17 00:00:00 2001 From: Eyal Yoli Abs Date: Wed, 21 Apr 2021 11:40:37 +0300 Subject: [PATCH 5/9] Update README.md add fork links --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 19e5d0f..29769a0 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Android-SerialPort-API -Fork自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 of the Android serial port communication Demo open sourced by Google. +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. ## Installation & Usage **Gradle** From 1bf895044ba83b50b017bb695aafd6249b9e638b Mon Sep 17 00:00:00 2001 From: Eyal Yoli Abs Date: Wed, 21 Apr 2021 11:41:08 +0300 Subject: [PATCH 6/9] Update README.md fix urls --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 29769a0..83f21a5 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # 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. +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. ## Installation & Usage **Gradle** From 0e329bec294043c8c47e0ba7a8a9c0e5f732ef2b Mon Sep 17 00:00:00 2001 From: licheedev Date: Tue, 1 Jun 2021 11:46:48 +0800 Subject: [PATCH 7/9] 2.1.3 migrate from Jcenter to MavenCentral --- README.md | 10 ++- build.gradle | 7 +- maven_publish.gradle | 130 ++++++++++++++++++++++++++++++++++++++ sample/build.gradle | 4 +- serialport/bintray.gradle | 86 ------------------------- serialport/build.gradle | 2 +- 6 files changed, 146 insertions(+), 93 deletions(-) create mode 100644 maven_publish.gradle delete mode 100644 serialport/bintray.gradle diff --git a/README.md b/README.md index 83f21a5..d05c6d4 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,16 @@ This lib is a [fork](https://code.google.com/archive/p/android-serialport-api/) Add the dependency: ``` +allprojects { + repositories { + ... + jcenter() + mavenCentral() // since 2.1.3 + } +} + dependencies { - implementation 'com.licheedev:android-serialport:2.1.2' + implementation 'com.licheedev:android-serialport:2.1.3' } ``` diff --git a/build.gradle b/build.gradle index fd36fc3..68e717a 100644 --- a/build.gradle +++ b/build.gradle @@ -4,13 +4,13 @@ buildscript { repositories { google() jcenter() + mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:4.0.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files - classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' - classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' + classpath 'org.jetbrains.dokka:dokka-gradle-plugin:1.4.32' } } @@ -18,6 +18,7 @@ allprojects { repositories { google() jcenter() + mavenCentral() } } @@ -32,5 +33,5 @@ ext { targetSdkVersion = 29 versionCode = 2 - versionName = "2.1.2" + versionName = "2.1.3" } \ No newline at end of file diff --git a/maven_publish.gradle b/maven_publish.gradle new file mode 100644 index 0000000..e8a2281 --- /dev/null +++ b/maven_publish.gradle @@ -0,0 +1,130 @@ +// 依赖信息 +def groupIdDefined = "com.licheedev" +def artifactIdDefined = "android-serialport" +// 如果是测试版,版本号后面加上 -SNAPSHOT +def versionDefined = rootProject.ext.versionName +// 其他信息 +def gitUrl = "https://github.com/licheedev/Android-SerialPort-API" + +// 配置是否上传 +def toUpload = true + +//在根build.gradle中加入,最新版本号参考 https://github.com/Kotlin/dokka#using-dokka +//classpath 'org.jetbrains.dokka:dokka-gradle-plugin:1.4.32' + +//在module的build.gradle末位加入 +//apply from: '../maven_publish.gradle' + +if (toUpload) { + apply plugin: 'signing' + apply plugin: 'maven-publish' + apply plugin: 'org.jetbrains.dokka' + + // + // 打包源码 + task sourcesJar(type: Jar) { + from android.sourceSets.main.java.srcDirs + classifier = 'sources' + } + + task javadoc(type: Javadoc) { + failOnError false + source = android.sourceSets.main.java.sourceFiles + options { + encoding = "utf-8" + charSet 'UTF-8' + } + classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) + classpath += configurations.compile + } + + // 打包javadoc + task javadocJar(type: Jar, dependsOn: javadoc) { + classifier = 'javadoc' + from javadoc.destinationDir + } + + // 打包包含kotlin源码的javadoc + task kotlinDocJar(type: Jar, dependsOn: dokkaHtml) { + classifier = 'javadoc' + from dokkaHtml.outputDirectory + } + // + + afterEvaluate { + + publishing { + publications { + mavenAndroid(MavenPublication) { + from components.release + + groupId "$groupIdDefined" + artifactId "$artifactIdDefined" + version "$versionDefined" + // 上传source + artifact sourcesJar + // 上传javadoc + if (project.plugins.hasPlugin('kotlin-android')) { + artifact kotlinDocJar + } else { + artifact javadocJar + } + + pom { + name = 'Android-SerialPort-API' + description = 'Android-SerialPort-API' + url = "$gitUrl" + + //licenses { + // license { + // name = 'The MIT License' + // url = 'https://opensource.org/licenses/MIT' + // } + //} + + licenses { + license { + name = 'The Apache License, Version 2.0' + url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' + } + } + + developers { + developer { + id = 'licheedev' + name = 'John Lee' + email = 'licheedev@foxmail.com' + } + } + scm { + connection = "$gitUrl" + developerConnection = "${gitUrl}.git" + url = "$gitUrl" + } + } + } + } + + repositories { + + maven { + // 依赖发布地址 + def releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" + def snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/" + url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl + + // 配置账号密码 + println "user=${ossrhUsername},key=${ossrhPassword}" + credentials { + username "${ossrhUsername}" + password "${ossrhPassword}" + } + } + } + } + + signing { + sign publishing.publications.mavenAndroid + } + } +} \ No newline at end of file diff --git a/sample/build.gradle b/sample/build.gradle index 167098d..f2834ca 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.1' + implementation project(':serialport') + //implementation 'com.licheedev:android-serialport:2.1.3' } diff --git a/serialport/bintray.gradle b/serialport/bintray.gradle deleted file mode 100644 index fbb21ef..0000000 --- a/serialport/bintray.gradle +++ /dev/null @@ -1,86 +0,0 @@ -//在根build.gradle中加入 -//classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' -//classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' - -//在module的build.gradle末位加入 -//apply from: './bintray.gradle' - -// 执行 ./gradlew clean bintrayUpload - -def toUpload = true // 配置是否上传 -if (toUpload) { - apply plugin: 'com.github.dcendents.android-maven' - apply plugin: 'com.jfrog.bintray' - - // 定义参数 - // 依赖信息 - def groupIdDefined = "com.licheedev" - def artifactIdDefined = "android-serialport" - def versionDefined = rootProject.ext.versionName - // 其他信息 - def siteUrl = "https://github.com/licheedev" - def gitUrl = "https://github.com/licheedev/Android-SerialPort-API.git" - def libName = "$artifactIdDefined" - - // 待发布项目的groupId和version。android-maven-gradle-plugin插件需要这么配置。 - group = "$groupIdDefined" - version = "$versionDefined" - - // bintray平台信息配置 - bintray { - user = BINTRAY_USER - key = BINTRAY_KEY - - println "user=${user},key=${key}" - - configurations = ['archives'] - publish = true - pkg { - repo = "maven" - name = libName - licenses = [" Apache-2.0"] - websiteUrl = siteUrl - vcsUrl = gitUrl - version { - name = "$versionDefined" - } - } - } - - // pom文件信息配置 - install { - repositories.mavenInstaller { - pom.project { - groupId "$groupIdDefined" - artifactId "$artifactIdDefined" - version "$versionDefined" - packaging 'aar' - } - } - } - - // 生成sourceJar和javaDocJar - task sourcesJar(type: Jar) { - from android.sourceSets.main.java.srcDirs - classifier = 'sources' - } - - task javadoc(type: Javadoc) { - failOnError false - source = android.sourceSets.main.java.sourceFiles - options { - encoding = "utf-8" - } - classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) - classpath += configurations.compile - } - task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.destinationDir - } - - artifacts { - archives sourcesJar - archives javadocJar - } -} diff --git a/serialport/build.gradle b/serialport/build.gradle index 874cafa..f9f8f28 100644 --- a/serialport/build.gradle +++ b/serialport/build.gradle @@ -37,5 +37,5 @@ dependencies { api "androidx.annotation:annotation:1.1.0" } -apply from: './bintray.gradle' +apply from: '../maven_publish.gradle' From 92499e2500237b4a4c37cab2324d57c74777ccff Mon Sep 17 00:00:00 2001 From: licheedev Date: Mon, 17 Jun 2024 16:26:47 +0800 Subject: [PATCH 8/9] =?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 9/9] =?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 } } }