Eclipse replaces ndk-gdb Breakpoint debugging Android NDK program

Source: Internet
Author: User
Tags android sdk manager

An overview:

Eclipse Debugging the NDK program is not difficult, but the environment is difficult to build. Installing eclipse alone has a lot of problems, and it's really a big mistake not to make it too small to keep it. On the Internet, there are already pioneers who have documented the eclipse breakpoints in debugging the Android NDK program:

Eclipse + ADT (including ndk Plugin) + CDT builds the Android NDK development environment
Website: http://blog.sina.com.cn/s/blog_48ed03c80101nhei.html


The situation I encountered was somewhat different from the above, and the "Android application development environment is relatively easy to build" is described above, but I have had problems with the development environment. I installed it three times in eclipse alone. I met a lot of questions that I didn't mention, probably because of a different platform (I'm on a Mac). I'll focus on what's not in the article below. In order to seek the coherence of the article, the text will also briefly mention some of the above important content, but only for the Dragonfly water-style introduction, so I also suggest you look at the above.


Description of two functional requirements

* (MAC) OS X Yosemite version 10.10.2

* Android SDK + android-ndk-r10e + ant + Eclipse + CDT + ADT

You can write and debug NDK programs (breakpoint debugging) in Eclipse. As follows:

Three implementation methods

3.1 How to solve the problem of environment construction

Download of 3.1.1 Android SDK

Because the JDK's website can be accessed directly, the JDK download and installation are quite smooth. The problem I encountered is the download of the Android SDK. I am looking for the Android SDK installation package on "Android Developer" (Android website). So the first problem comes: Baidu directly search out just "Android Developer" the old version of the image. Here are the "Android Developer" homepage that I found on both the Baidu and Bing engines, respectively.


This blue background is the "Android Developer" website found on Bing. From the URL, this is the real-time official website version of the site. It should be added that the network is not directly accessible to us. I use an agent to access it. Why not direct access to the cause, in fact, technology people are understand (^_^).

This white background, Baidu on the search out of the "Android Developer" official website. From the URL, it's not the "Android Developer" official website. But the content is actually "Android Developer" official website old version of content. And the net we can directly access (albeit a bit slow). So this is only a domestic mirror, its update speed must not be real official website so fast.

You are advised to download adnroid sdk,android NDK and ADT Tools on the real website. and download as much as possible using the download tool instead of downloading directly (I use "thunderbolt"). The reason is: the real official online version of the tools are relatively new, many download tools do not need to set up agents can also download resources abroad. Furthermore, my agent has a traffic limit. Use the tool to download, you can save traffic to check the problem.


3.1.2 Update for Android SDK

Updates to the Android SDK cannot be updated directly. This is the second question I have come across. I have wanted to use "thunder" to download. But found below this file, "Thunder" also can not download:

Had to go online to check the other method, the results found two ways to modify the local hosts mapped to the available IP.

Method One:

Add the following host settings to the/etc/hosts:

#第一组设置 #203.208.49.162 dl.google.com #203.208.49.162 dl-ssl.google.com# Two sets of settings 203.208.49.164 dl.google.com203.208.49.164 dl-ssl.google.com

The above two sets of settings, with a group on it. Two sets of IPs are not guaranteed to be valid for long periods. Complete the settings above and launch the Android SDK Manager to update successfully. This is the simplest method I have found. There is a problem with this approach: a small number of update packages will fail to download.


Method Two:

Use the "Power Unlimited" Android source. Please go to the following URL:

Http://www.sxrczx.com/pages/ubuntu.uestc.edu.cn/android/repository/index_1431450123772.html

Or Baidu: The Building Force Infinite Mirror Station-android mirror site use Help. Follow the instructions in the Web page. This method has a relatively few steps. The advantage is that the update package is available.


3.1.3 Eclipse Acquisition and installation

The official download URL for Eclipse is: http://www.eclipse.org/downloads/. The problem I encountered here is still the download failed. The official default download is the Eclipse Automatic installation program, the automatic installation program with "Thunderbolt" can be easily downloaded to. However, when you install eclipse with this automatic installer, the program downloads files to a foreign server, and the download fails. So we should download the package directly:

I downloaded the middle, the bottom one. Because that comes with the CDT. No additional installation is required. If you are downloading a non-CDT version, remember to install the CDT before installing ADT. And when I installed ADT, I entered the URL by the installation instructions, and then the download failed, so I went directly to the Android website to download its package. The downloaded page is: http://developer.android.com/intl/zh-cn/sdk/installing/installing-adt.html
Also use "Thunder" under. I met a scary warning when I installed ADT that there was a problem with the visa part of the file will be invalid or not installed. In fact, this need not be afraid, directly click "OK" just. Because this is what the Android website says:


3.2 Importing NDK projects and related settings

The method of directly creating the JNI tool has been described in more detail in the article "Eclipse + ADT (including ndk Plugin) + CDT build Android NDK development environment". Therefore, this article only describes the considerations when importing. I'm importing hellojni in NDK sample. Importing NDK works is the same as importing a normal Android engineering method. So not redundant, here is the emphasis on the post-import settings.

3.2.1 Set up Android SDK and Android NDK.

Use "Windows Key +," to enter the "Preferences" setting. For example, you will find a place to set up the SDK and the NDK


Above is the SDK, the following is the NDK:


3.2.2 Native Related Settings

Join native support. In the Package Explorer, select the Hellojni project you just imported, right-click android Tools->add Nativesupport., fill in the name of the imported dynamic library, This can be compared to the Local_module settings in the existing Android.mk file. Note that the "Add nativesupport ..." This operation will automatically generate some. mk files and. c files. It is possible that the original project conflicts with the import should be noted (back up important files before necessary operations). It is generally possible to delete automatically generated files to resolve conflict issues. Cannot omit "Add nativesupport." This step, otherwise eclipse will see an issue with the option to find a non-C + + menu.

Join the C + + header file path. In the Package Explorer, select the Hellojni project you just imported, and right-click Properties.


In essence I only imported a directory, as follows:

/users/apple/installed/android-ndk/android-ndk-r10e/platforms/android-14/arch-arm/usr/include

The other directories are imported automatically. The directory you import is related to the selected target API version. By the time we get here, Hellojni can compile.


3.2.2 Android Project Modification

Because the direct use of JDB debugging has a problem, that is, the program must be started, JDB can connect. This will "Miss" the code that the program started. I found a way to stop the program directly with the code: Add "Android.os.Debug.waitForDebugger ();"

public class Hellojni extends activity{... public void onCreate (Bundle savedinstancestate) {Super.onc         Reate (savedinstancestate);                 Is the following code can let the program stop waiting for JDB connection Android.os.Debug.waitForDebugger ();        TextView TV = new TextView (this);        Tv.settext (Stringfromjni ());    Setcontentview (TV); }     ......    }

Here it is possible to debug the NDK program with high breakpoints.

3.2.3 Last few questions

Problem: You can compile, but debug with "Unknown Application ABI" error. Workaround: Modify minsdkversion and targetsdkversion in Androidmanifest.xml to resolve (increase the point).

Issue: There is no setting option in the Device Selection window that pops up while debugging. Workaround: In fact, there is no device, just need to scroll the screen to see the options. Scroll up and down in the Prepare selection box to see the device options.

Problem: The breakpoint in the C code was set, but the program did not stop. Workaround: Check for "Android.os.Debug.waitForDebugger ();" Is there a procedure for joining this sentence? In addition, "Debug as" and "Android Native application" are required to set the test


Eclipse replaces ndk-gdb Breakpoint debugging Android NDK program

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.