VS Real Machine Debug Android native app (take COCOS2DX hand tour for example)

Source: Internet
Author: User

0. Although the use of hand-tour for example, but applicable to any native C + + NDK compilation method.

1. first talk about the project background, COCOS2DX hand tour, development generally in Windows vs under the development of debugging,IOS using Xcode can also be very convenient debugging, but Android is not so lucky, general debugging rely on log to analyze the problem, always feel inefficient. Debugging native android programs adb, Cygwin gdb-ndk,ecplise under the Android native app has also been done, but it is not very convenient, and can debug success still depends on RP, is really difficult to debug, and the line and cherish . Just want to be able to debug the Android program in vs and the configuration is relatively simple.

2. on the net G A find an artifact called visualgdb, see can be used to debug Linux and android programs, so you want to try this is reliable.

The tools you need

1.vs2010 or

2.visualGDB This tool is charged, the attachment to a cracked version

3. One is root , and there are /data and /data/data directory permissions, that is, the adb needs to be able to root Login. Otherwise, when you start debugging, you will find that the gdbserver file cannot be copied to the /data directory and cannot be debugged

4. Android NDk

5. Android SDK

6. Ant

7. Java-jdk

3. installation configuration visualgdb

1. after installation on the vs menu More items android- àset sdk/ndk location open the following interface to set your own

Sdk ndk ant jdk related paths

2 Create a new project for visualgdb Start Visual Studio. Select file->new project->visualgdb->android App Wizard.

You can see that after installing the visualgdb , there is one more item in the new project, and we need to create a new project like this.

3 Import Our project, select the last import existing from ecplise or ant

4. Choose Android Project, this is the directory where Androidmanifest.xml is located

When creating the project, the target chooses android-18

Add android:debuggable= "true" in androidmanifest.xml to generate a so with debug information

You can start compiling the package now (you need to ensure that the android.mk file ant 's build.xml is no problem, at least it can be compiled under the ecplise build can pass).

4. after the compilation is complete, the ant is automatically packaged into an apk, and if you see the generated apk in the bin directory is successful, start debugging below

Menu ->android->debug Android app, the following interface will appear, in fact, the tool is also used by the adb to complete the debugging.

Our project in the debugging time will be in this interface longer, generally around 200s , prompted to see the project may be too large, too many files caused.

PS: a few days ago at the time of the native ecplise compile, in the time of link to report a very strange error

At Link Time reported a CreateProcess no such file or dir error, at that time do not know what reason, at least G A, see a person asked the same question, It could be that the number of files is too large.

The number of our files is 796 , and we suspect that the parameters are too long in link .

It was like making a general-purpose independent so, or . a. But this also only solved the current problem, in case later in the more up or the same, just want to android.mk There is no choice to provide support

Find an option below and it's OK .

Successfully started debugging

Creash can also directly see the stack, very convenient

5. several pits encountered

1. device is not recognized, in the input Adb.exe devices device display is ? No.

If the display is

? Devices

This indicates a problem with USB Open, drive successful Android, so start debugging will prompt "The path has illegal characters" error

adb devices question mark the device does not recognize a lot of reasons, I am in the machine settings select the USB connection mode Select the "Media Settings (MTP)" Connection is good.

2. sdk\platforms Select android-18when creating the project, or you may report a armeabi-7v error when debugging

3. In the Ant build Report an exception, which is due to the androidmanifest.xml and project.properties

Target=android-<value> values are not the same cause

[DX] unexpected top-level EXCEPTION:

1> [DX] Java.nio.BufferOverflowException
1> [DX] at Java.nio.Buffer.nextPutIndex (buffer.java:519)
1> [DX] at Java.nio.HeapByteBuffer.putShort (heapbytebuffer.java:315)

6. VISUALGDB Debug Startup process

adb–s device ID command

You can use the- s parameter to select when multiple devices are already connected to the host .

Get device information

E:\lccifter_FB\lucifter\adt-bundle-windows-x86-20130917\sdk\platform-tools\adb.exe devices

List of devices attached

00664bacf43f Device

View Current Process

E:\lccifter_FB\lucifter\adt-bundle-windows-x86-20130917\sdk\platform-tools\adb.exe-s 00664bacf43f Shell PS

USER PID PPID vsize RSS Wchan PC NAME

Root 1 0 368 ffffffff 00000000 S/init

Root 2 0 0 0 ffffffff 00000000 S kthreadd

Root 3 2 0 0 ffffffff 00000000 S ksoftirqd/0

...... N Multiple

E:\lccifter_FB\lucifter\adt-bundle-windows-x86-20130917\sdk\platform-tools\adb.exe-s 00664bacf43f Shell ID

uid=2000 (shell) gid=2000 (shell) groups=1003 (graphics), 1004 (input), 1007 (log), 1009 (Mount), 1011 (ADB), 1015 (SDCARD_RW ), 1028 (Sdcard_r), 3001 (Net_bt_admin), 3002 (NET_BT), 3003

(inet), 3006 (net_bw_stats)

Install apk,-R means reinstall

E:\lccifter_FB\lucifter\adt-bundle-windows-x86-20130917\sdk\platform-tools\adb.exe-s 00664bacf43f Install-r "e:\ Lc_fb_test\cocos2d-x-2.1.4\samples\cpp\hellocpp

\proj.android\bin\helloworld-debug.apk "

PKG:/data/local/tmp/helloworld-debug.apk

Success

3741 kb/s (1406256 bytes in 0.367s)

Launches an app path returned by pwd

E:\lccifter_FB\lucifter\adt-bundle-windows-x86-20130917\sdk\platform-tools\adb.exe-s 00664bacf43f Shell Run-as Org.cocos2dx.hellocpp/system/bin/sh-c pwd

/data/data/org.cocos2dx.hellocpp

Get CPU architecture Information

E:\lccifter_FB\lucifter\adt-bundle-windows-x86-20130917\sdk\platform-tools\adb.exe-s 00664bacf43f Shell Getprop Ro.product.cpu.abi

armeabi-v7a

Run a package named org.cocos2dx.hellocpp active activity hellocpp

E:\lccifter_FB\lucifter\adt-bundle-windows-x86-20130917\sdk\platform-tools\adb.exe-s 00664bacf43f Shell am start-n org.cocos2dx.hellocpp/. Hellocpp

starting:intent {cmp=org.cocos2dx.hellocpp/. Hellocpp}

E:\lccifter_FB\lucifter\adt-bundle-windows-x86-20130917\sdk\platform-tools\adb.exe-s 00664bacf43f Shell ls/data/ Data/org.cocos2dx.hellocpp/lib/gdbserver

/data/data/org.cocos2dx.hellocpp/lib/gdbserver

E:\lccifter_FB\lucifter\adt-bundle-windows-x86-20130917\sdk\platform-tools\adb.exe-s 00664bacf43f Shell PS

USER PID PPID vsize RSS Wchan PC NAME

Root 1 0 368 ffffffff 00000000 S/init

Root 2 0 0 0 ffffffff 00000000 S kthreadd

Root 3 2 0 0 ffffffff 00000000 S ksoftirqd/0

Forwarding Port

E:\lccifter_FB\lucifter\adt-bundle-windows-x86-20130917\sdk\platform-tools\adb.exe-s 00664bacf43f Forward TCP : 5039 tcp:5039

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.