User Tools

Site Tools


android:android-jni

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
android:android-jni [2010/11/08 17:19] percyandroid:android-jni [2016/05/05 13:07] (current) – external edit 127.0.0.1
Line 1: Line 1:
 +====== Android JNI多线程相关 ======
 +  - http://android.wooyd.org/JNIExample/files/JNIExample.pdf
 +  - http://groups.google.com/group/android-ndk/browse_thread/thread/da092bd665ca9ff1
 +
 +
 ====== Android JNI相关 ====== ====== Android JNI相关 ======
 收集一些Android JNI的使用方法。 收集一些Android JNI的使用方法。
 +
 +====== JNA ======
 +
 +<code>
 +JNA provides Java programs easy access to native shared libraries without writing anything but Java code - no JNI or native code is required. This functionality is comparable to Windows' Platform/Invoke and Python's ctypes.
 +
 +JNA allows you to call directly into native functions using natural Java method invocation. The Java call looks just like the call does in native code. Most calls require no special handling or configuration; no boilerplate or generated code is required.
 +</code>
 +
 +  - https://github.com/twall/jna
 +  - https://github.com/twall/jna/blob/master/www/AndroidDevelopmentEnvironment.md
 ===== Android JNI介绍 ===== ===== Android JNI介绍 =====
   - Android JNI详述:参考http://hi.baidu.com/zhang_sg1984/blog/item/d0d7fcdd698916d58d1029af.html,讲得比较详细   - Android JNI详述:参考http://hi.baidu.com/zhang_sg1984/blog/item/d0d7fcdd698916d58d1029af.html,讲得比较详细
Line 7: Line 23:
   - JNI 返回结构体参数:http://andilyliao.javaeye.com/blog/496816 很不错的讲解结构体参数传递的教程。   - JNI 返回结构体参数:http://andilyliao.javaeye.com/blog/496816 很不错的讲解结构体参数传递的教程。
   - NDK 应用及扩展介绍:http://wenku.baidu.com/view/361c9a2d2af90242a895e516.html,讲解了如何NDK中如何使用so文件。   - NDK 应用及扩展介绍:http://wenku.baidu.com/view/361c9a2d2af90242a895e516.html,讲解了如何NDK中如何使用so文件。
 +  - JNI tutorial,老外写的教程,http://www.giamungo.com/JNI/JNI.html
 +  - JNI Examples for Android:http://android.wooyd.org/JNIExample/
  
 ====== NDK ====== ====== NDK ======
Line 14: Line 32:
   * 实例:   * 实例:
   - Porting curl to Android - A success story with NDK 1.6:http://curl.haxx.se/mail/lib-2009-12/0071.html   - Porting curl to Android - A success story with NDK 1.6:http://curl.haxx.se/mail/lib-2009-12/0071.html
 +
 +====== NDK Tips ======
 +  * NDK的默认Android.mk路径指定在project/jni目录下,如果我们需要将Android.mk提到上一级目录,需要修改文件NDK_ROOT\build\core\default-application.mk
 +  #APP_BUILD_SCRIPT := $(APP_PROJECT_PATH)/jni/Android.mk
 +  APP_BUILD_SCRIPT := $(APP_PROJECT_PATH)/Android.mk
 +  
 +  * undefined reference to `wcstombs'
 +默认的NDK,在用到wcstombs函数时(已经include <stdlib.h>),编译会报错,在网上找了一下,是NDK的问题:http://blog.sina.com.cn/s/blog_4b650d650100m07j.html
 +可以在这里下载打过patch的版本,http://www.crystax.net/android/ndk-r4.php
 +
 +
 +  
 +
  
 ====== Linux 网络编程 ====== ====== Linux 网络编程 ======
Line 25: Line 56:
 bash D:\android\ndk\android-ndk-r4-windows\android-ndk-r4-windows\android-ndk-r4\ndk-build bash D:\android\ndk\android-ndk-r4-windows\android-ndk-r4-windows\android-ndk-r4\ndk-build
 </code> </code>
 +====== NDK编译脚本For windows ======
 +简单写了一个脚本,调用ndk-build编译SO文件,
 +只支持两个参数
 +  nkdbuild build
 +  ndkbuild clean
 +[[android:android-jni:ndkbuild-bat-for-windows|Bat脚本for Windows]]
  
 +===== NDK编译脚本For Linux ======
 +1.支持编译静态库
  
 +2.解析Android.mk:支持指定编译后安装目录,支持编译前拷贝相关静态库到编译目录
  
 +[[android:android-jni:ndkbuild-shell-for-linux|NDK Shell For Linux]]
 +
 +
 +====== ndk-gdb调试 ======
 +利用ndk-gdb可以直接调试native code.
 +
 +命令:
 +  bash /cygdrive/d/android/ndk/android-ndk-r4-windows/android-ndk-r4/ndk-gdb --start --force --verbose
 +
 +但在cygwin下调试时遇到了一个问题,
 +<code>
 +D:\workspace\DDTui>bash /cygdrive/d/android/ndk/android-ndk-r4-windows/android-ndk-r4/ndk-gdb
 +GNU gdb 6.6
 +Copyright (C) 2006 Free Software Foundation, Inc.
 +GDB is free software, covered by the GNU General Public License, and you are
 +welcome to change it and/or distribute copies of it under certain conditions.
 +Type "show copying" to see the conditions.
 +There is absolutely no warranty for GDB.  Type "show warranty" for details.
 +This GDB was configured as "--host=i686-pc-cygwin --target=arm-elf-linux".
 +/cygdrive/d/workspace/DDTui/bin/ndk/local/armeabi/app_process: No such file or directory.
 +</code>
 +找不到app_process文件,Google了一下,
 +找到类似的问题:http://code.google.com/p/android/issues/detail?id=8894
 +
 +方法是修改ndk-gdb:
 +<code>
 +# Get the app_server binary from the device
 +APP_PROCESS=$APP_OUT/app_process
 +#run adb pull /system/bin/app_process $APP_PROCESS
 +
 +#Add by Jianqing Peng,20101122
 +if [ -s "${COMSPEC}" ] ; then
 +    run adb pull /system/bin/app_process  "`cygpath -w $APP_PROCESS`"
 +else
 +    run adb pull /system/bin/app_process  $APP_PROCESS
 +fi
 +
 +</code>
  
 +====== native crash log分析 ======
 +[[android:android-jni:android-ndk-stacktrace-analyzer|native crash log分析]]
  
  
/var/www/dokuwiki/wiki/data/attic/android/android-jni.1289207975.txt.gz · Last modified: 2016/05/05 13:06 (external edit)