Android 串口通讯实现,附带Modbus
ndk.dir=D\:\\Android_Studio_2021\\Sdk\\ndk\\25.2.9519653
android{
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
repositories {
maven { url 'https://jitpack.io' }
google { url "https://maven.aliyun.com/repository/google" }
mavenCentral { url "https://maven.aliyun.com/repository/public" }
}
./gradlew makeJar
\build\outputs\aar\
android{
buildTypes {
release {
//开启混淆
minifyEnabled true
// 移除无用的resource文件,与 minifyEnabled 一起使用
//shrinkResources true//Error:Resource shrinker cannot be used for libraries.
//Zipalign优化,让安装包的资源按4字节对齐,减少应用在运行时的内存消耗
zipAlignEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
-keep class android.serialport.*{*;}
android{
//Copy类型
task makeJar(type: Copy) {
//删除存在的
delete 'build/libs/serialport.jar'
//设置拷贝的文件
//from('build/intermediates/bundles/release/')
from('build/intermediates/aar_main_jar/release/')
//打进jar包后的文件目录
into('build/libs/')
//将classes.jar放入build/libs/目录下
//include ,exclude参数来设置过滤
//(我们只关心classes.jar这个文件)
include('classes.jar')
//重命名
rename ('classes.jar', 'serialport.jar')
}
makeJar.dependsOn(build)
//在终端执行生成JAR包
// ./gradlew makeJar
}