2013年9月3日 星期二

Debug Cocos2d in C + Android NDK + Eclipse in Ubuntu

Ubuntu Linux Version

//////////////////////////////////////////////////////
Ref.
http://blog.plicatibu.com/how-to-debug-cocos2d-x-and-java-code-using-eclipse
http://ibeyond.blog.51cto.com/1988404/1109559
http://developer.android.com/guide/developing/device.html
http://blog.csdn.net/luoshengyang/article/details/6768304
////////////////////////////////////////////////////////

Concept:
begin break point in java debug first
then start ndk-gdb-eclipse server
use MOTODEV C++ debug > arm-linux-androideabi-gdb connect it
and continue java debug

1.JDK 6
make sure your linux have jre jdk
or
apt-get install openjdk-6-jre openjdk-6-jdk
or
apt-add-repository ppa:webupd8team/java
apt-get update
apt-get install oracle-java6-installer

2.Android Sdk
http://developer.android.com/sdk/index.html
Linux-32bit

3.MOTODEV Eclipse
http://developer.motorola.com/docstools/motodevstudio/download/
Full Installer: Includes Eclipse environment Linux-32
chmod -x MOTODEV_Studio_for_Android_3.1.0_linux_x86.bin
#./MOTODEV_Studio_for_Android_3.1.0_linux_x86.bin
@Motodev last version is 5.0 please refer to my project in blog http://www.wretch.cc/blog/fatalfeel/857768

4.Download componentes
MOTODEV > Download componentes > SDK
SDK Location: /opt/android-sdk-linux

5.MOTODEV > Download componentes > SDK
click -download platforms, add-ons, samples-
enable follows
Android sdk tools
Android sdk platform-tools
at least api 10:
Android 2.1 API 10->sdk platform checked only

6.MOTODEV CDT
MOTODEV > Download componentes >native support
checked in Enable native support
auto setting JDK Path: /usr/lib/jvm/java-6-openjdk

7.New AVD
MOTODEV> new android virtual device
Android API 10

8.Ndk 7
get correct NDK version to debug
http://www.crystax.net/
download file android-ndk-r7-crystax-5.beta2-linux-x86.tar.bz2

9. NDK Location
after Enable native support
window > preferences > android > NDK
NDK Location: /opt/android-ndk-r7-crystax-5.beta2

10.edit ndk-gdb
gedit /opt/android-ndk-r7-crystax-5.beta2/ndk-gdb
remove last line
$GDBCLIENT -x `native_path $GDBSETUP`
save as ndk-gdb-eclipse

11.Path
gedit /etc/environment
add
/opt/android-sdk-linux/platform-tools:
/opt/android-ndk-r7-crystax-5.beta2:
/opt/MOTODEV

reboot system

12.Add -DGL_GLEXT_PROTOTYPES=1 in c:\cocos2d-0.99.5-x-0.8.2\cocos2dx\Android.mk
LOCAL_CFLAGS := -DUSE_FILE32API -DGL_GLEXT_PROTOTYPES=1

13.modify c:\cocos2d-0.99.5-x-0.8.2\HelloWorld\android\build_native.sh
ANDROID_NDK_ROOT=/opt/android-ndk-r7-crystax-5.beta2
COCOS2DX_ROOT=/root/cocos2d-0.99.5-x-0.8.2

14. cd /root/cocos2d-0.99.5-x-0.8.2/HelloWorld/android
./build_native.sh

15.MOTODEV
*un-mount usb device first*
File->New [Android Project]
Create project from existing source
Location: /root/cocos2d-0.99.5-x-0.8.2/HelloWorld/android
debug as > [Android Application using MOTODEV Studio]
AndroidManifest.xml -> android:installLocation="internalOnly"
after install application
exit application

16.ndk-gdb
/root/cocos2d-0.99.5-x-0.8.2/HelloWorld/android# ndk-gdb --start
then press q, press y
get 2 files
/root/cocos2d-0.99.5-x-0.8.2/HelloWorld/android/obj/local/armeabi/app_process
/root/cocos2d-0.99.5-x-0.8.2/HelloWorld/android/obj/local/armeabi/gdb.setup

17.edit gdb.setup
gedit /root/cocos2d-0.99.5-x-0.8.2/HelloWorld/android/obj/local/armeabi/gdb.setup
remove -target remote :5039
save as gdb_eclipse.setup

18. convert c/c++
right click file > new > other
convert c/c++
makefile project = android gcc
only MOTODEV have android gcc

19.check andorid gdb version
/root/cocos2d-0.99.5-x-0.8.2/HelloWorld/android/#./build_native.sh --just-print
match
arm-linux-androideabi-4.4.3
or
arm-linux-androideabi-4.6.3

20.build c++ debug
properties > c/c++ build
uncheck [use defaultbuild command]
[build command] =ndk-build NDK_DEBUG=1 V=1

21. Debugger menu popup for gdbserver
Debug As->Debug configurations, double click [C/C++ Application]
click into bottom line -Select other...-
enable [Use configuration specific settings]
select [Standard Create Process Launcher]
(Linux => [Legacy Create Process Launcher])

22.[C/C++ Application] Debugger setting
(1)[Main] > [C/C++ Application:] /root/cocos2d-0.99.5-x-0.8.2/HelloWorld/android/obj/local/armeabi/app_process
(2)[Debugger:] GdbServer
(3)[Stop on starup at:] Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit
(4)[GDB debugger:] /opt/android-ndk-r7-crystax-5.beta2/toolchains/arm-linux-androideabi-4.6.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gdb
(5)[GDB command file:] /root/cocos2d-0.99.5-x-0.8.2/HelloWorld/android/obj/local/armeabi/gdb_eclipse.setup
(6)[Verbose console mode] enable it. For watching running text
(7)[Connection] > [Type:] TCP
(8)[Host name or Ip address:] localhost
(9)[Port number:] 5039

23.break point
super.onCreate(savedInstanceState) set break point;
execute java debug
when break on

24.open console mode
/root/cocos2d-0.99.5-x-0.8.2/HelloWorld/android/# ndk-gdb-eclipse

25.c++ debug
execute [c/c++ application] debug
continue java debug
then will see break in main.c
in Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit

26.redo error
if problem window show error
select all error message and delete then debug java again
or
properties > c/c++ general > code analysis
enable -use project settings-
disable all -syntax and semantic errors-

//////////////////////////////////////////////////////
Ubuntu Linux USB Hardware setting

1.list
#lsusb
Bus 002 Device 004: ID 0bb4:0c01
Vendor ID is 0bb4 , Product ID is 0c01

2.xx-android.rules
#gedit /etc/udev/rules.d/51-android.rules
add HTC all device
SUBSYSTEM=="usb", ATTRS{idVendor}=="0bb4", MODE="0666"
save then
#chmod 0666 /etc/udev/rules.d/51-android.rules

3.start device
#restart udev
#reboot

4. maybe need restart adb
#adb kill-server
#adb start-server

5.Show in MOTODEV
click item "MOTODEV STUDIO For Android"
show andorid handset in Device window

沒有留言:

張貼留言