Professional Documents
Culture Documents
NDK Setup
NDK Setup
Download Eclipse Classic from http://www.eclipse.org/downloads/packages/eclipse-classic-362/heliossr2 Choose your operating system from the right hand side, then select a download link on the next page. (While you're waiting for it to download, you could also be downloading: the SDK and/or the NDK.) When the download has completed, go to the download location and unpack the contents to a directory of your choice. You can then open the Eclipse executable and it will run. (Eclipse is portable - there is no actual installation required.) Eclipse will ask you for a workspace. This is just folder where you store Eclipse projects. It is recommended that you choose your development folder if you have one.
Android SDK
Download the Android SDK Installer from http://developer.android.com/sdk/index.html Run the installer. If Java Development Kit (JDK) isn't installed, get it from http://www.oracle.com/technetwork/java/javase/downloads/jdk-6u26-download-400750.html Install to C:\Android\SDK When installation is complete, untick the box to start the AVD Manager (we will come back to this later), and click finish.
In Eclipse, Help -> Install New Software... In the Work with field, enter the site https://dl-ssl.google.com/android/eclipse/ When the site loads, there should be a category Developer Tools. Expand this by clicking the plus sign, then select Android Developer Tools:
Progress through the following screens, accepting the licence agreement, and the ADT will download. If at any point you get a security warning, choose to continue/click OK. When installation completes, you will be required to restart Eclipse. Once Eclipse has restarted, navigate to Preferences. (Windows/Linux: Window -> Preferences. OS X: Eclipse -> Preferences) Select Android on the left hand side. If asked about sending usage statistics to Google, pick an option and click Proceed. In the SDK Location field, enter the path where you installed the Android SDK (should be C:\Android\SDK\).
In Eclipse, Window -> Android SDK and AVD Manager. Select Available packages on the left, then expand Android Repository by clicking the plus*. From the list, select Android SDK Tools, Android SDK Platform-tools, and at least one platform. Android SDK 2.3.3 is recommended. Later versions may work but have not been tested. (If any of these are missing, it will be because you already have the latest version.)
Click Install Selected, accept the licence agreement(s), and click Install. *If you have problems with not being able to access the packages, open the SDK Manager outside of Eclipse (it is located in the Android SDK directory), click Settings on the left, and try with an http connection (as opposed to https). You may also have to set up your proxy settings in Eclipse (in Window (Eclipse if on OS X) -> Preferences -> General -> Network Connections).
Android NDK
Download the NDK from http://developer.android.com/sdk/ndk/index.html Select your operating system from the table, and your download will begin.
Once the download has finished, unpack the contents to C:\Android\NDK. In Eclipse, navigate to Window (Eclipse if on OS X) -> Preferences -> Android -> Native Development, and enter your NDK path in the NDK Location field.
In Eclipse, Help -> Install New Software In the Work with field, enter http://download.eclipse.org/sequoyah/updates/1.1 Then deselect the Group items by category option, and select Sequoyah Android Native Code Support:
Click next, and Eclipse will add the CDT package as a requirement for Sequoyah. Continue, accept the agreement, and install the packages.
Installing Cygwin
Cygwin is a Linux emulator, required to run the build and debugging scripts for Android NDK.
Download the Cygwin tool from http://www.cygwin.com/setup.exe Click next, select Install from Internet, and click next again. The recommended Root Directory is C:\Cygwin. If you can, choose Install For All Users. On the next screen, choose a folder where Cygwin can store temporary files while it downloads packages. Next, enter your proxy settings (if you can access the internet through Internet Explorer, and you are not sure about your proxy settings, choose Use Internet Explorer Proxy Settings. Then, choose a mirror. Any should be fine, but if you get errors, check your proxy settings and/or choose another mirror. If, at any point, you are shown a warning about previous versions of Cygwin, it can be ignored (unless you have installed Cygwin before, in which case follow the instructions).
When shown the Select Packages screen, leave the selection at default, then make the following changes:
Search for make. It is located at All->Devel and you need the one that has a description starting with make: The GNU version... Search for gcc. It is located at All->Devel and you need gcc-core and gcc-g++. Cygwin will automatically calculate and add any dependencies.
When you are done, click next, make sure recommended packages are selected, then click next and Cygwin will download and install the packages. When it is done, click next and follow the prompts.
Cygwin Tips
Adding an alias
An alias is a user-defined command that you can type in Cygwin to perform a set of custom commands. A recommended alias for this project is to have a command (e.g. dev) that takes you straight to your development folder. To do this:
Open your .bashrc. This is located in C:\cygwin\home\USERNAME (replace C:\cygwin with your path if you changed it from the default). It can be edited in any good text editor (see Developer Tools). Add this line to the file: alias dev='cd "/cygdrive/c/PATH_TO_DEVELOPMENT_FOLDER". (This assumes your development folder is stored on the C drive, change the c in the path to the correct drive letter if this is not the case.)
Open your .bashrc. This is located in C:\cygwin\home\USERNAME (replace C:\cygwin with your path if you changed it from the default). It can be edited in any good text editor (see Developer Tools). Add the following lines to the file (replace the paths with the correct ones for your setup):
The platform used for debugging must be Android 2.2 (API version 8) or later. If debugging multi-threaded applications, it will need to be at least Android 2.3. In AndroidManifest.xml, set Debuggable to true under Application. Build your project using ndk-build in a terminal/Cygwin in your projects root directory. Create a default Android Application debug configuration by going to Run->Debug Configurations, give it a name that tells you it is the Java/Android one, and run it. When it has loaded, launch ndk-gdb from your projects root directory. When successful, you can stop the application. Right click your project in Project Explorer, and select Android Tools Add native support. Create a new C/C++ Application debug configuration, giving it a name that indicates it is the C/C++ one, with the following settings:
o o o o o o
Main tab: C/C++ Application: <project_path>/obj/local/armeabi/app_process Disable auto build. Using Standard Create Process Launcher (selected at the bottom). Debugger tab: Debugger: gdbserver Deselect "Stop on startup at" Main sub-tab: GDB debugger: <NDK_path>/toolchains/arm-eabi-<gccversion>/prebuilt/<architecture>/bin/arm-eabi-gdb.exe
E.g.: C:\Android\android-ndk\android-ndk-r5b\toolchains\arm-eabi4.4.0\prebuilt\windows\bin\arm-eabi-gdb.exe GDB command file: (will be created later) <project_path>/obj/local/armeabi/gdb2.setup Verbose console mode: optional
Use full file path to set breakpoints: deselect if using Windows Connection sub-tab: Type: TCP Host name or IP address: localhost Port number: 5039
Configure gdb
Open the ndk-gdb script (found in your NDK directory) and comment out the line near the bottom that starts with $GDBCLIENT x. This step needs to be done only once, not per project. In your <project_path>/obj/local/armeabi directory, create a copy of gdb.setup and call it gdb2.setup. In this file, remove the line which reads target remote:5039.
Debugging process
Add an initial breakpoint in your Java code, after all System.loadLibrary calls. Tip: Add your two debuggers to your "favourites" by clicking on the arrow next to the Debug icon (the bug) and clicking Organize Favourites...
Issues
Then click Add and select your two debug configurations. You can now start these debuggers from that dropdown menu next to the bug.
Clean (Project -> Clean...) your project (sometimes if you change native code, Eclipse doesn't think it needs to rebuild/reinstall the apk). Start your Android debugger. When its loaded and Eclipse has stopped at the breakpoint, run ndk-gdb --force in your projects root directory.. When that has completed, start your C/C++ debugger. Once it has launched, you can continue to debug both Java and native code.
If you ever encounter the error where Eclipse complains that it can't find the source files of the breakpoints, make sure your gdb2.setup file is up to date with the relevant paths.