最近由于公司的需要,需要对代码的操作 ,因为以前没有接触过串口 ,所以上网查了很多的资料,但是那些资料都是有点太老,因为现在大多是android studio 所以我也用AS开发,但是在开发过程中都没有办法调用到.so文件,经过我一番努力,终于在AS上成功运行,和雷达串口交互。闲话少说,直接上方法。
首先 AS是正式版,我用的是AS-1.51正式版,其他版本我也试过,其中测试版的不行,所以最好用正式版。
1、首先是配置gradle
distributionUrl=https://services.gradle.org/distributions/gradle-2.10-all.zip
gradle必须是2.10的版本,其他版本应该不行,所以要注意。
2、配置项目中的build.gradle
dependencies {
classpath ‘com.android.tools.build:gradle-experimental:0.7.0-alpha3’
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
这个版本就是谷歌用来测试ndk的 这个必须要改的 不然怎么编译都不会通过的
3、接下来要配置module里面的build.gradle
这个改的有点多
apply plugin: ‘com.android.model.application’
model {
android {
compileSdkVersion 23
buildToolsVersion “23.0.3”
defaultConfig {
applicationId "项目的包名"
minSdkVersion.apiLevel 15
targetSdkVersion.apiLevel 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles.add(file('proguard-rules.pro'))
}
}
ndk {
moduleName "SerialPort" //生成.so的名字
ldLibs.add('log')
}
}
}
dependencies {