2010年4月27日星期二

Part I - Build Android VNC server with Android NDK on windows 7

As a record how I compile and build libandroidvncserver with android ndk on windows 7 :
1. system : windows 7 64 bits pro
2. packages needed :
• android ndk r3 for windows
• android sdk and tools r5
• cygwin installed
• to build with ndk, the easiest way is to put your source codes under ndk-home/apps
• download android vnc server from google developer site (android-vnc-server - Project Hosting on Google Code)
• check the Application.mk file under ndk-home/apps/androidvncserver/

APP_PROJECT_PATH := $(call my-dir)/project
APP_MODULES := androidvncserver

• check the Android.mk file under ndk-home/apps/androidvncserver/project/jni/

#
# excutable, which will depend on and include the first one
#

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= \
fbvncserver.c \
LibVNCServer-0.9.7/libvncserver/main.c \
LibVNCServer-0.9.7/libvncserver/rfbserver.c \
LibVNCServer-0.9.7/libvncserver/rfbregion.c \
LibVNCServer-0.9.7/libvncserver/auth.c \
LibVNCServer-0.9.7/libvncserver/sockets.c \
LibVNCServer-0.9.7/libvncserver/stats.c \
LibVNCServer-0.9.7/libvncserver/corre.c \
LibVNCServer-0.9.7/libvncserver/hextile.c \
LibVNCServer-0.9.7/libvncserver/rre.c \
...............

LOCAL_C_INCLUDES := \
$(LOCAL_PATH) \
$(LOCAL_PATH)/LibVNCServer-0.9.7/libvncserver \
$(LOCAL_PATH)/LibVNCServer-0.9.7 \
external/zlib \
external/jpeg

# all of zlib head files should be ndk-home/external/zlib
# all of jpeg head files should be ndk-home/external/jpeg
# or set LOCAL_CLAGS := -I/usr/include that compiler can find those *.h files

LOCAL_SHARED_LIBRARIES := libz
LOCAL_STATIC_LIBRARIES := libjpeg
LOCAL_MODULE:= androidvncserver
include $(BUILD_EXECUTABLE)


• Then go to the ndk-home to make by input "make APP=appname" where appname is the folder name under apps and the APP_MODULES defined in the Application.mk.
e.g. make APP=androidvncserver [V=1] ; [V=1] is an option for verbose mode

• You may get error message like make: *** No rule to make target out/apps/androidvncserver/armeabi/libjpeg.a', needed by out/apps/androidvncserver/armeabi/androidvncserver'. Stop.

Solution I (reference http://blog.sina.com.cn/s/blog_4a0a39c30100ckzd.html)

1. Download jpeg source and directly build the libjpeg.a (http://www.ijg.org/files/jpegsrc.v6b.tar.gz, ftp://ftp.simtel.net/pub/simtelnet/msdos/graphics/jpegsr6.zip)
2. Copy makefile.ansi to be makefile and change the contents :
#line 09:CC= arm-eabi-gcc
i.e. change the cc compiler environmental variable as the ndk arm gcc compiler
#line 12:CFLAGS= -O2
Optimization
3. #line 17:LDFLAGS= -s -static
Android Native static lib must use -static,and -s to minimize lib size by removing debug message?
#line 33:AR= arm-eabi-ar rc
#line 35:AR2= arm-eabi-ranlib

Change AR and AR2 to be Android Native's ar and ranlib for building the static lib
4. If you can find jconfig.h on your system than copy it to the jpeg lib source code directory or you can rename jconfig.doc (under the jpeg lib source directory) to jconfig.h
5. then type make
6. if all things OK,you will get libjpeg.a and Andorid Native executable files:cjpeg, djpeg, jpegtran, rdjpgcom, wrjpgcom. cjpeg is a jpeg file compressor to convert other file format to a jpeg file, djpeg is a decompressor,and you can use adb push to upload them to your Android Emulator!
For example (“>” window command prompt mode,“#” is the prompt on the emulator)

>adb push cjpeg /dev/sample/cjpeg
>adb push myimg.bmp /dev/sample/myimg.bmp
>adb shell
#cd /dev/sample
#chmod 777 cjpeg
#./cjpeg -quality 90 -outfile myimg.jpg myimg.bmp
#exit
>adb pull /dev/sample/myimg.jpg myimg.jpg

Then on your PC you can use any jpeg viewer to read the jpeg file
• If the testing is OK, copy the libjpeg.a and libz.so (from Android NDK native like ndk-source\build\platforms\android-5\arch-arm\usr\lib)file to out/apps/androidvncserver/armeabi
• Now, make APP=androidvncserver
BINGO !You should get an Android native binary androidvncserver under out/apps/androidvncserver/armeabi

> adb push androidvncserver /data/vncsvr ; push it to your emulator
> adb shell chmod 755 /data/vncsvr ; change to executable mode
> adb shell /data/vncsvr -k /dev/input/event0 -t /dev/input/event0 ; specify the -k (keyboard) and -t (mouse) event device

Now, need to forward port 5900 to 5901

> telnet localhost 5554 ; 5554 is the port of your emulator
> redir list ; list existing port forwarding
> redir add tcp:5900:5901
> redir list ; now you should see tcp:5900 is forwarding to 5901

• Now run vncviewer (you can get free download from ultravnc) and should see your emulator screen on the vnc client
KNOWN ISSUES : for non-rooted device, the mouse and keyboard will not work, but i knew someone had hacked it successfully.

Solution II : use of android source code and ndk to build libjpeg.a and libz.so (post later)

0 意見:

最酷的Web相片欣賞工具 CoolIris