Skip to content

Commit

Permalink
发布到jcenter
Browse files Browse the repository at this point in the history
  • Loading branch information
licheedev committed Aug 26, 2020
1 parent 0ba13aa commit 6661aad
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 76 deletions.
19 changes: 3 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -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'
}
```

Expand All @@ -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 //
Expand Down
11 changes: 6 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}

Expand All @@ -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"
}
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
30 changes: 0 additions & 30 deletions jitpack.gradle

This file was deleted.

11 changes: 6 additions & 5 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android {
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
buildTypes {
release {
Expand All @@ -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'
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
1 change: 1 addition & 0 deletions serialport/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/build
.externalNativeBuild
.cxx
86 changes: 86 additions & 0 deletions serialport/bintray.gradle
Original file line number Diff line number Diff line change
@@ -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
}
}
6 changes: 3 additions & 3 deletions serialport/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -34,5 +34,5 @@ dependencies {
// testCompile 'junit:junit:4.12'
}

apply from: '../jitpack.gradle'
apply from: './bintray.gradle'

12 changes: 3 additions & 9 deletions serialport/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
<manifest package="android.serialport"

xmlns:android="http://schemas.android.com/apk/res/android">

<application android:allowBackup="true" android:label="@string/app_name"
android:supportsRtl="true">

</application>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="android.serialport">

</manifest>
36 changes: 32 additions & 4 deletions serialport/src/main/java/android/serialport/SerialPort.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6661aad

Please sign in to comment.