Download Debugging Android Native Applications

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Debugging Android Native Applications
This document is composed of eleven sections:
1) Prerequisites
2) Start A New Project with a C/C++ Nature
3) Converting to a Native Project via Android Tools
4) Converting to a Native Project via File → New
5) Adding A Native Code Debug Configuration (NOT RECOMMENDED)
6) Android Virtual Device Emulation
7) Adding a Library Reference to an Android Project
8) Adding Add-On Sites to the Android SDK Manager
9) Connecting to the Kindle Fire for Debugging (1'st Generation API level 10)
10) Connecting to the Kindle Fire HD for Debugging (API level 15)
11) References
Prerequisites
This tutorial provides instructions for debugging native (C/C++) source code in an
Android native application project.
The ADT bundle (Android SDK with Eclipse IDE, ADT plugin, CDT, etc.) must be
installed, as well as the Android Native Development Kit (NDK). The version of the
Android SDK used in this tutorial is:
Build: v21.0.1-543035
Set the Android NDK path via Window → Preferences in Eclipse:
Set the debuggable option in the application section of the Android manifest to "true":
Create a new C/C++ project, or convert an existing project to one with native support
either via adding native support, or selecting to convert an existing project after selecting
File → New.
Start a New Project with a C/C++ Nature
From the menu, select File → New. Select C or C++ Project:
Converting to a Native Project via Android Tools
You may have the option of right-clicking on the project in the package explorer, then
selecting Android Tools → Add Native Support.
Converting to a Native Project via File → New
Select to convert to a C/C++ project.
Select the Android GCC Toolchain.
Adding A Native Code Debug Configuration
THIS IS NOT RECOMMENDED, AS IT SHOULD NOT BE NECESSARY. SKIP
THIS SECTION IF YOU ARE ALREADY ABLE TO DEBUG NATIVE CODE WITH
THE DEFAULT PROJECT DEBUG CONFIGURATION.
If the default debug configuration does not permit you to debug native code, in order to
add the ability to debug native code (insert breakpoints, single-step execution, watch
variables, etc.), select the project to debug, and press Alt → Enter to open the project
properties. Confirm that ndk-build is set as the build command:
Prior to creating a debug configuration, the project must first be built. This will generate
a gdb.setup command file in the library directory. Under Window → Preferences, and
then the Run/Debug selection, the default launchers should all default to the GDB process
launcher.
Next, under Run → Debug Configurations, create a new Android Native Application
debug configuration:
Select the project, and then open the Debugger tab.
Select the prebuilt GDB debugger executable in the Android NDK toolchain. Then select
the gdb.setup file built by your project:
The project should now load symbols for the C/C++ source files, and allow you to debug
them and place breakpoints, etc.
To debug the project, you can either select Debug As → Android Native Application
from the project context menu, or the Run menu in the Eclipse menu bar.
Android Virtual Device Emulation
When setting up an Android Virtual Device (AVD) for emulation, you may have to
manually edit the config.ini for the AVD to fix the RAM size, which must have MB
appended to it:
hw.ramSize=1024MB
config.ini is located in:
\\Users\<user>\.android\avd\<avd-profile-name>.avd\config.ini
or
\\Documents and Settings\<user>\.android\avd\<avd-profile-name>.avd\config.ini
The keyboard, button support, and direction pad options should also be edited directly in
the config.ini file, as these options currently do not work via the configuration window.
Adding a Library reference to an Android Project
In the project properties, add the following line (after the android target API level):
android.library.reference.1=../AndModPlugLib
Right-click on the project, and select Build Path → Configure Build Path:
Select Java Build Path, then the Libraries tab, and add JARs:
Adding Add-On Sites to the Android SDK Manager
Open the Android SDK Manager located in the android installation directory in the adtbundle-windows-x86 folder. Select Tools → Manage Add-on Sites from the menu:
Under User Defined Sites, include web addresses for Add-on sites that provide tools to
the SDK. For the Kindle Fire, add:
http://kindle-sdk.s3.amazonaws.com/addon.xml
Under Extras, select the Kindle Fire Device Definitions and the Kindle Fire USB Driver
packages and install them.
Connecting to the Kindle Fire for Debugging
http://mobile.tutsplus.com/tutorials/android/getting-started-with-kindle-fire-development/
[Windows]
Step 1: Editing Files
On a Windows development machine, you’ll need to edit two files and then ensure that
the connected Kindle Fire device is using the correct driver. You can edit these files
using your favorite text editor. Because locations vary, we’ll reference the file locations
with a general description of the location, but you’ll have to ultimately find the file for
yourself.
First, edit the adb_usb.ini file found in the .android folder of your user directory. Add
one line (the vendor ID, 0x1949) to the bottom of the file:
Second, edit the android_winusb.inf file found in the \sdk\extras\google\usb_driver\
folder of your Android SDK installation directory. You may need to edit the permissions
of the file before modifications will be allowed. Add the following two lines (and the
comment, if you wish) to both the [Google.NTx86] and [Google.NTamd64] sections:
;Kindle Fire
%SingleAdbInterface%
= USB_Install, USB\VID_1949&PID_0006
%CompositeAdbInterface% = USB_Install, USB\VID_1949&PID_0006&MI_01
Now you’re ready to plug the cable in and configure the USB driver.
Step 2: Using the Google USB Driver
Now when you connect your Kindle Fire, your computer will be ready. Once connected,
you’ll have to manually choose to use the Google USB driver. You do this from the
system’s Device Manager, as with any USB device. In brief, from the Device Manager,
find the Kindle device, choose Update Driver Software, choose Browse for driver, find
the android_winusb.inf file, and install it. Once done, the Kindle device will show up
under Android Phones, Android Composite ADB Interface.
To connect Kindle on the ADB (android debug bridge), you may have to enable ADB on
the Kindle. Go to Settings → Security and Enable ADB.
To build applications for the 1'st generation Kindle, use API level 10 (Gingerbread). For
everything else, use API level 15 (Ice Cream Sandwich). DO NOT use Google APIs, as
they are not supported by the Kindle - there are Amazon APIs for things like in-app
purchases, etc.
Connecting to the Kindle Fire HD for Debugging
Note that the Kindle Fire extras must be installed via the Android SDK Manager. Refer
to the Adding Add-On Sites to the Android SDK Manager portion of this document.
In your Android installation folder, navigate to the following folder:
adt-bundle-windows-x86\sdk\extras\amazon\kindle_fire_usb_driver
Run the program KindleDrivers.exe located in this folder to install the Kindle Fire and
Kindle Fire HD USB drivers:
Then, you can connect your Kindle Fire to your PC via USB.
If you have a Kindle Fire HD (Android API level 15), you must manually enable the
ADB debugging interface via your device settings. On the first generation Kindle Fire
(API level 10), it is enabled by default.
References
The Android SDK (Software Development Kit):
http://developer.android.com/sdk/index.html
The Android NDK (Native Development Kit):
http://developer.android.com/tools/sdk/ndk/index.html
The Android Developer Reference:
http://developer.android.com/reference/packages.html
Kindle Fire Development Resources
https://developer.amazon.com/sdk/fire.html
Setting Up the Kindle Fire for Android Development:
https://developer.amazon.com/sdk/fire/setup.html