NDK问题总结

转自 这篇文章中不少东西!!:http://blog.chinaunix.net/uid-20746260-id-3910616.htmlhtml

1. 建立JNI头文件java

  在工程目录下输入:android

javah -classpath bin/classes -d jni com.example.rgbir.rgbirJNI

   遇到的问题c++

error: cannot access com.example.rgbir.rgbirJNI
class file for com.example.rgbir.rgbirJNI not found
javadoc: error - Class com.example.rgbir.rgbirJNI not found.
Error: No classes were specified on the command line. Try -help.

解决方法:点击运行工程,从新在命令行输入命令便可。网络

缘由: 从新生成class文件eclipse

 

2. 配置NDK路径函数

  参考文章: 建立eclipse针对NDK的联合编译环境。post

 

3. 屏蔽语法检查错误ui

对代码分析(code analysis)进行屏蔽url

位置: project-> properties ->c/c++ general ->code analysis

在选择“using project setting”下面的syntax and semantic error 进行屏蔽

 

4. 解决JNI层函数头文件《jni.h》 下的黄线

  由于CDT索引器没有找到路径,而NDK知道。

  进入项目属性页面,“c/c++ general” -》 “Paths and symbols”,右边“add...” 输入JNI相关头文件所在目录。好比“${env_var:Android_NDK}/platforms/android-18/arch-arm/usr/include”.

 

5 C++包含。h头文件

JNI文件夹下的c++程序包含。h文件, 。h文件中全部函数声明必须在以下宏中,不然会报 undefined reference to 的错误。

 

#ifdef __cplusplus 
extern "C" { 
#endif

//一段代码

#ifdef __cplusplus 
} 
#endif

 

6. java.lang.UnsatisfiedLinkError:Native method not found

 so文件编译生成后,运行时,有时候会遇到java.lang.UnsatisfiedLinkError: Native method not found问题。
   a. JNI方法头部大小写问题     
      在C++中,方法名:Java_com_XXX,而不是java_com_XXX。建议直接从生成的.h头文件直接复制方法名到C或者C++文件中。
   b. C++文件问题
        若是是C++文件(.cpp或者.cc),要使用extern "C" {   } 把本地方法括进去
   c. 往JNI方法中传值问题
         如,调用native方法sendSomeThing(Object object),若是传入的object为null,有可能会报上面错误。

 

7. SD卡中建立文件、写入文件、删除文件操做的支持

 在AndroidManifest.xml中加入访问SDCard的权限.若是支持网络, 麦克风等同样处理

相关文章
相关标签/搜索