1、在搞安卓串口通讯时,主模块build.gradle中指定了cpu的so库必须为
ndk {
abiFilters 'armeabi'
}
然后串口模块是没有指定so库的, 默认情况下运行时不会生成armeabi架构对应的so,然后运行应用当调用串口模块相关的方法时报错,代码报错找不到serialport.so。
解决方法
在串口模块的builde中,加入
defaultConfig {
//省略
//生成对应so
externalNativeBuild {
cmake {
cppFlags ''
// 生成so库类型
abiFilters 'armeabi'
}
}
}
然后运行代码,构建失败了提示
ERROR: ABIs [armeabi] are not supported for platform. Supported ABIs are [arm64-v8a, armeabi-v7a, x86, x86_64].
原因
ndk17开始不在支持armeabl
1、首先下载低版本的ndk,目前可以再as中下载16版本的,然后再local.properties中更改为自己下载的sdk版本路径
ndk.dir=D\:\\xx\\16.1.4479499
2、串口模块的build.gradle中指定 ndkVersion '16.1.4479499'
android {
ndkVersion '16.1.4479499'
}
最后串口模块中的build.gradle如下
apply plugin: 'com.android.library'
android {
//省略
ndkVersion '16.1.4479499'
defaultConfig {
//省略
externalNativeBuild {
cmake {
cppFlags ''
// 生成so库类型
abiFilters 'armeabi'
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
这样重写运行项目即可正常使用了,不在提示找不到serialport.so