Monday, June 7, 2010

Android NDK Development

Some remarks I would like to make while developing on Android NDK:
  • Package, class and function names in Java are specified by function name in C/C++
  • For all JNI wrapper functions, remember to add JNIEnv *env and jobject object to the front of the parameter list. They represent the environment pointer and the Java class object which calls this function.
  • Parameters are passed into wrapper functions by value. To the best of my knowledge, there is no way to pass in parameters by reference.
  • If the wrapper source is in cpp, remember to include all function prototypes in
  • Include all source files in subdirectory src: LOCAL_SRC_FILES := $(addprefix src/,$(notdir $(wildcard $(LOCAL_PATH)/src/*.cpp $(LOCAL_PATH)/src/*.c)))
  • Make use of include $(call all-subdir-makefiles) to make a recursive building hierarchy
  • While using variable LOCAL_STATIC_LIBRARIES, try putting the highest level libraries in the front to prevent linking error
  • In order tot check the output of stdout and stderr, you have to set by using adb (included in Android SDK), and then you can view them using ./adb logcat
    ./adb shell stop
    ./adb shell setprop log.redirect-stdio true
    ./adb shell start
    Update: Stopping and starting the shell may cause the whole emulator hangs now. To redirect stdout/stderr, add "log.redirect-stdio=true" to /data/local.prop on the device (create one if the file does not exist) and restart the device
  • STL library is not included in NDK. If you need to use STL library in your NDK code, you have to use stlport
  • DO NOT create thread inside NDK
  • Directory /tmp DOES NOT exist in Android. I have tried to search for it for hours without any luck. According to what I found, applications should manage their own files (temp or non-temp) within the local filesystem sandbox on their own
  • There is a script to let you build a NDK toolchain since NDK revision 5
  • Linking with "-lpthread" is not required, including that will cause error

No comments:

Post a Comment