Wednesday, June 30, 2010

Windows Azure SDK Requirements

  • Windows Vista / Windows 7 / Windows Server 2008 / Windows Server 2008 R2
  • IIS 7.0 (with ASP.NET, WCF HTTP Activation, Static Content, and optionally CGI)
  • Microsoft Visual Studio 2010/ Microsoft Visual Web Developer 2010 Express / Microsoft Visual Studio 2008 SP1 / Microsoft Visual Web Developer 2008 Express Edition with SP1.
  • SQL Server 2005 Express Edition or above

Friday, June 11, 2010

Access Java Class Variables from NDK

Access Java class variables from NDK (non-static function) in C:

  • env and obj are the first two parameters of the NDK function
  • "Ljava/lang/String;" is called the field descriptor of type String

Field Descriptor of other Variable Types:

  • Remember the semi-colon
  • Replace "Get" by "Set" for Set Field Functions

Field Descriptor Type Get Field Function
Z boolean GetBooleanField
B byte GetByteField
C char GetCharField
S short GetShortField
I int GetIntField
J long GetLongField
F float GetFloatField
D double GetDoubleField
Ljava/lang/String; String GetObjectField
[I int[] GetObjectField, and then cast it to an array
jintArray *arr = reinterpret_cast<jintArray*>(&data);
[Ljava/lang/Object; object[] GetObjectField, and then cast it to an array

Wednesday, June 9, 2010

OSX C/C++ Header Differences with Linux

  • Header <mntent.h> does not exist
  • Header <linux/rtc.h> does not exist
  • Header <sys/sysinfo.h> does not exist
  • In <string.h>, function strndup() does not exist
  • In <unistd.h>, function ftruncate64() does not exist
  • In <netinet/in.h>, struct ip_mreqn does not exist
  • Struct statfs requires <sys/param.h> and <sys/mount.h>
  • Variable environ doest not exists, but you can "access" it using function _NSGetEnviron() defined in <crt_externs.h>
  • To retrieve full path of current executable, use function _NSGetExecutablePath() defined in <mach-o/dyld.h>

Android NDK Differences with Linux

  • C++ STL is not included Update: stlport is included since revision 5
  • In <mntent.h>, function setmntent() does not exist
  • In <dirent.h>, functions seekdir(), telldir() does not exist
  • Macro INET_ADDRSTRLEN is not defined in <netinet/in.h> Update: added since revision 5b
  • Macro PTHREAD_EXPLICIT_SCHED is not defined in <pthread.h>
  • Marcos WEXITSTATUS, WTERMSIG, WIFSIGNALED, etc are only defined in <sys/wait.h>  (One can also find them in <stdlib.h>  for Linux)
  • Although function ftruncate64() is included in header <unistd.h>, it is not included in the prebuilt libraries. Hence it causes linking error while this function is used
  • Although you can include <sys/sysinfo.h>, struct sysinfo does not exist (it is disabled in the header file). If you have to use it, try this way.

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