I am working on developing monitoring android app, using android studio. I would like to add android-serialport-api ( https://code.google.com/p/android-serialport-api/ ) as a library in my app and make serial communication possible in the project. I downlaod sources using SVN check out and using Cygwin. I was compiling NDK file and JNI File in serial port api then I copied all files and attached in the libraries file in my project. The project structure as below.
and then I included the build.gradle file in android-serial-api like this.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 15
targetSdkVersion 23
}
sourceSets {
main {
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
manifest.srcFile 'project/res/AndroidManifest.xml'
}
}
}
I included this in app/build.gradle
compile project(':libraries:android-serialport-api')
In settings.gradle I also included this.
include ':libraries:android-serialport-api'
androidmanifest.xml file is originally like this.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="android_serialport_api.sample"
android:versionCode="3"
android:versionName="1.2" >
<application
android:icon="@drawable/icon"
android:label="@string/app_name"
android:name="Application" >
<activity
android:label="@string/app_name"
android:name="MainMenu" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="SerialPortPreferences" >
</activity>
<activity android:name="ConsoleActivity" >
</activity>
<activity android:name="LoopbackActivity" >
</activity>
<activity android:name="Sending01010101Activity"></activity>
</application>
<uses-sdk android:minSdkVersion="3" />
</manifest>
However, when I make the project. there are lots of error. So erased most of the codes. so now androidmanifest.xml in library is like this.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="android_serialport_api.sample"
android:versionCode="3"
android:versionName="1.2" >
<uses-sdk android:minSdkVersion="3" />
</manifest>
After erasing them, I can make the project and gradle sycronized. But I don't know how to use serial.c sources from library I imported. How can I fix the program? There are some messages in the todo list.
Please help me!!
use this : Hello Jni
install ndk from android sdk
but when in loop send data, file close!!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.