我使用的是Android Studio 0.6.1
我的src树包括:
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ ├── android_serial_api
│ │ │ ├── SerialPortFinder.java
│ │ │ └── SerialPort.java
│ │ └── com
│ │ └── elmit
│ │ └── bellusball
│ │ └── app
│ │ ├── Application.java
│ │ ├── ConsoleActivity.java
│ │ ├── LoopbackActivity.java
│ │ ├── MainMenu.java
│ │ ├── NOTUSED
│ │ │ └── MainActivity.java
│ │ ├── Sending01010101Activity.java
│ │ ├── SerialPortActivity.java
│ │ └── SerialPortPreferences.java
│ ├── jniLibs
│ │ ├── armeabi
│ │ │ └── libserial_port.so
│ │ ├── armeabi-v7a
│ │ │ └── libserial_port.so
│ │ └── x86
│ │ └── libserial_port.so
│ └── res
│ ├── drawable
在使用Gradle文件的Sync Project期间,我没有收到任何错误。 在构建期间我没有收到任何错误。
但是,当我在平板电脑上运行应用程序时,logcat报告:
06-25 18:48:28.816 400-400/com.elmit.bellusball.app D/dalvikvm﹕ Trying to load lib /data/app-lib/com.elmit.bellusball.app-2/libserial_port.so 0x411c9d98
06-25 18:48:28.817 400-400/com.elmit.bellusball.app D/dalvikvm﹕ Added shared lib /data/app-lib/com.elmit.bellusball.app-2/libserial_port.so 0x411c9d98
06-25 18:48:28.817 400-400/com.elmit.bellusball.app D/dalvikvm﹕ No JNI_OnLoad found in /data/app-lib/com.elmit.bellusball.app-2/libserial_port.so 0x411c9d98, skipping init
06-25 18:48:28.817 400-400/com.elmit.bellusball.app W/dalvikvm﹕ No implementation found for native Landroid_serial_api/SerialPort;.open:(Ljava/lang/String;II)Ljava/io/FileDescriptor;
06-25 18:48:28.819 400-400/com.elmit.bellusball.app D/AndroidRuntime﹕ Shutting down VM
06-25 18:48:28.819 400-400/com.elmit.bellusball.app W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x40f169a8)
06-25 18:48:28.823 400-400/com.elmit.bellusball.app E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.UnsatisfiedLinkError: Native method not found: android_serial_api.SerialPort.open:(Ljava/lang/String;II)Ljava/io/FileDescriptor;
at android_serial_api.SerialPort.open(Native Method)
at android_serial_api.SerialPort.<init>(SerialPort.java:61)
本机libserial_port.so在jniLibs中!
build.gradle包括:
dependencies {
compile fileTree(dir: "$buildDir/native-libs", include: 'native-libs.jar')
compile fileTree(dir: 'libs', include: ['*.jar'])
provided fileTree(dir: 'jniLibs', include: ['*.so'])
compile 'com.android.support:appcompat-v7:19.+'
}
task nativeLibsToJar(type: Jar, description: 'create a jar archive of the native libs') {
destinationDir file("$buildDir/native-libs")
baseName 'native-libs'
from fileTree(dir: 'libs', include: '**/*.so')
into 'lib/'
}
tasks.withType(Compile) {
compileTask -> compileTask.dependsOn(nativeLibsToJar)
我从哪里开始以及如何解决这个问题?