Install the android development environment in Eclipse: ndk and CDT
(This article is based on Internet data collected and verified by the author)
Cheungmine
This article records how to build the development environment of Android JDK and ndk in the latest eclipse version Helios. It also provides methods to integrate ndk and cygwin. To enable users to compile ndk code without switching to the cygwin command line, the ndk environment under eclipse is configured. Finally, it shows how to configure the C/C ++ development environment-CDT on Eclipse. This article also provides a simple example to illustrate how to use ndk.
Key words: Eclipse, Android, Android SDK, cygwin, ndk, CDT
1 Preparation 1.1 Windows XP 32-bit PC, access to broadband Internet. 1.2 install JDK
:
Https://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/ViewProductDetail-Start? Productref = jdk-6u12-oth-JPR @ CDS-CDS_Developer
Download To get: jdk-6u12-windows-i586-p.exe. Install it. This example is installed on: D: \ javahome. After installation, the system environment variables should contain the following settings (assuming the directory is the same as this article ):
Java_home=...
D: \ javahome \ jdk1.6.0 _ 12
Classpath=...
% Java_home % \ bin ;.; % java_home % \ Lib; % java_home % \ Lib \ DT. jar; % java_home % \ Lib \ tools. jar; C: \ ProgramFiles \ Java \ jre6 \ Lib \ ext \ qtjava.zip; D: \ oraclient10g \ JDBC \ Lib \ classes12.zip
Path=
% Java_home %;.; % java_home % \ bin ;...
1.3 install eclipse (heilos)
: Http://www.eclipse.org/downloads/
Download:Eclipse IDE for Java eedevelopers, 206 MB
Get: eclipse-jee-helios-SR2-win32.zip
When the eclipseis not installed, decompress eclipse-jee-helios-sr2-win32.zip to: D: \ Helios.
Start: D: \ Helios \ eclipse.exe. Workspace: D: \ Helios \ Workspace
In this case, you can update Eclipse:
Open eclipse; menu help-> check for updates, and then check for updates. Select the necessary components to update eclipse.
2 install Android Development Tool 2.1 install Android SDK
Download In the address below: android-sdk_r04-windows.zip
Http://rghost.net/download/817413/e08025da54d8e38f7e97bcdce6117620a33c054e/android-sdk_r04-windows.zip
Decompress android-sdk_r04-windows.zip to: D: \ Helios \ Android-SDK-Windows.
Update Android-SDK to the latest version:
Eclipse menu help-> check for updates for necessary updates.
Eclipse menu help-> install new software:
Work:
Http://dl-ssl.google.com/android/eclipse/site.xml
Click [select all].
Click [next>].
2.2 configure the android SDK
1) set reference:
Eclipse menu-> window-> preferences:
Select + android on the left and enter:
SDK location: D: \ Helios \ Android-SDK-Windows
Click [apply].
2) Update the android SDK:
Eclipse menu-> window-> Android SDK and AVD Manager
The SDK location: D: \ Helios \ Android-SDK-Windows
Click "available packages" on the left and select the package to be updated.
Click installed packages on the left and press [updated all...] to update all installed packages.
2.3 create an android VM:
Eclipse menu-> window-> Android SDK andavd manager, select on the left:
Availabledevices, click [New...] on the right side to bring up the create new Android virtualdevice (AVD) dialog box:
Name: HTC-G7
Target: Android 2.2-API Level 8
SD card:
Size = 1000 MIB
Click [Create AVD. This AVD should be started before each deployment (eclipse menu-> window-> Android SDK andavd manager, select availabledevices on the left, select HTC-G7 on the right, press [start...] start AVD .)
2.3 configure cygwin and Android ndk
In the past, it was very troublesome to use GCC to write programs to arm. Its cross-compilation environment needs to be run in Linux. Many other tools have to be used in windows, so people have to switch back and forth the operating system, which is very troublesome and wastes a lot of valuable time. The emergence of cygwin finally solved this problem.
Cygwin is a Linux operating environment in a Windows operating system, including a DLL used to provide Linux APIs and a series of Linux tools. Download the latest version at http://cygwin.com.
Download the cygwininstaller setup.exe, which can be installed. Before installation, make sure that the drive you want to install has 3 GB space. When installing cygwin, you can choose to directly install the installation package from the network, download the installation package, and install it locally. I chose to download the installation package, download the required items to the local disk, and then install them locally, next, select the installation location, set the network connection mode, and select the download site. Then, select the package to be installed. There are four installation statuses: Default, install, reinstall, and uninstall, if you are not sure about the environment you need, set the status on all to install and select all to install.
1) install cygwin
Download: http://www.cygwin.com/setup.exe. Select All during installation to avoid missing tools such as GCC. After a long wait (based on the network speed, maybe overnight), cygwin has been downloaded. Decompress the package to: D: \ cygwin. Then manually configure the Windows environment variables and add D: \ cygwin; D: \ cygwin \ bin to path:
Path =...; D: \ cygwin \ bin
Verify: Call out command window cmd, Type COMMAND: cygwin press enter, start cygwin tool window, run:
Make-V
Verify if cygwin is correct:
GNU make 3.81
Copyright (2006) Free Software fundation Inc.
...
Download the android-ndk-r4-windows.zip installation package ,:
Http://developer.android.com/sdk/ndk/index.html
Decompress to: D: \ Helios \ android-ndk-r4.
At the time of writing this article, there is already the latest: android-ndk-r6-windows.zip
If you are using a android-ndk-r6, pay attention to changing the path configuration.
2) Integrate cygwin and Android ndk
Edit the file: D: \ cygwin \ home \ Administrator \. bash_profile and add:
# Android ndk
Ndk =/cygdrive/D/Helios/android-ndk-r4
Export Path = "$ ndk: $ path"
Save and restart cygwin (START-> Run: cygwin ).
3) ndk compilation example:
Start cygwin;
Go to the D: \ Helios \ android-ndk-r4 \ samples \ hello-JNI \ JNI directory (or the directory where the *. C or *. cpp file of the corresponding project is located ):
# Cd/cygdrive/D/Helios/android-ndk-r4/samples/Hello-JNI/JNI
Execute ndk-build Compilation:
# Ndk-build
3 Android ndk engineering example
The following shows how to create a simple ndk project and integrate cygwin + ndk into eclipse.
1) Start eclipse, menu
File-> New-> Project-> + Android-androidproject
Create a project. Click [next>] to bring up the new Android project dialog box. Enter the following content:
Priject name: ndkfoo
Check Android 2.2
Applicationname: ndkfoo
Package name: COM. Mine. ndkfoo
Check "Create activity: ndkfooactivity ".
Min SDK version: 8
Click [finish.
2) create a JNI directory under the project ndkfoo (right-click the project and choose Project> New> folder ).
3) Create the Android. mk file under the JNI directory. The content is as follows:
Local_path: = $ (call my-DIR)
Include $ (clear_vars)
# Here we give our module name and sourcefile (s)
Local_module: = ndkfoo
Local_src_files: = ndkfoo. c
Include $ (build_shared_library)
4) Create the ndkfoo. c file under the JNI directory. The content is as follows:
#include <string.h>#include <jni.h>jstringJava_com_mine_ndkfoo_ndkfooActivity_invokeNativeFunction(JNIEnv* env, jobjectjavaThis) {return (*env)->NewStringUTF(env, "Hello from nativecode!");}
5) modify the ndkfooactivity. Java file (ndkfoo/src/COM. Mine. ndkfoo) as follows:
package com.mine.ndkfoo;import android.app.Activity;import android.app.AlertDialog;import android.os.Bundle;public class ndkfooActivity extendsActivity {//load the library - name matches jni/Android.mkstatic{System.loadLibrary("ndkfoo");}//declare the native code function - must match ndkfoo.cprivatenative String invokeNativeFunction();/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);// this is where we call the native codeString hello = invokeNativeFunction();newAlertDialog.Builder(this).setMessage(hello).show();}}
6) before compiling the ndkfoo project, you must use the ndk-build command line of cygwin to compile ndkfoo. C:
Start cygwin;
Go to the D: \ Helios \ workspace \ ndkfoo \ JNI directory:
# Cd/cygdrive/D/Helios/workspace/ndkfoo/JNI
Execute ndk-build Compilation:
# Ndk-build
Libndkfoo. So is compiled successfully.
7) return to eclipse and re-compile the ndkfoo project. Deploy on AVD (you must first start AVD-> HTC-G7 ). You can see that one of the simplest Android ndk programs runs correctly into the HTC-G7 virtual machine.
4 integrate ndk and eclipse
In eclipse, select the ndkfoo project created above and press Alt + enter to display the properties for ndkfoo window:
Select builders on the left and click [New...] on the right. In the pop-up dialog box, double-click the program icon and fill in the edit Configuration window:
Name: ndk_builder (this term is arbitrary)
Switch to the main tab:
Location:
D: \ cygwin \ bin \ bash.exe
Working directory:
D: \ cygwin \ bin
Arguments:
-- Login-c "CD/cygdrive/D/Helios/workspace/ndkfoo/JNI & $ ndk/ndk-build"
Switch to the refresh tab and check the following items:
Refresh resources upon completion.
The entire Workspace
Recursively include sub-folders
Switch to build options and check the following items:
Allocateconsole
After a clean
Buring manual builds
During Auto builds
During a clean
Spacify working set of relevant resources
In this way, we integrate ndk and eclipse. After changing the ndkfoo. c file, you do not need to switch to the cygwin command window to execute ndkfoo compilation.
5. Install the eclipse C/C ++ Development Kit CDT
This topic has little to do with ndk.
Go to the following address page:
Http://www.eclipse.org/cdt/downloads.php
You can see:
CDT 7.0.2 for eclipse Helios
Eclipse package: eclipsec/C ++ ide Helios sr2.
P2 software Repository: http://download.eclipse.org/tools/cdt/releases/helios.
Write down the URL:
Http://download.eclipse.org/tools/cdt/releases/helios
Open the eclipse menu window-> install new software,
Work:
Http://download.eclipse.org/tools/cdt/releases/helios
Click [select all] and [next>] to install and update the CDT. After that, you can create, edit, compile, and debug C/C ++ programs in eclipse (but such programs are not inherently Android ndk programs. More function options should be explored gradually ).