Build a win7 Android ndk Development Environment

Source: Internet
Author: User

Key words: JNI, win7, Android SDK, Android ndk, cygwin, Eclipse, JDK

 

1.download and install the latest cygwinsetup.exe
Note that you need to select devel @ install, which is required to simulate the Linux environment ,,,,SelectHttp://mirrors.163.comFast download speed
After installation, open make-V and GCC-V to test whether the installation is successful.

2.download and install jdk-7u2-windows-i586.exe
Problems that may occur later: When javah.exeis used in the pathsystem runtime to generate a JNI header file using javah.exe, the system will prompt that javah is not valid.Program

3.download android-ndk-r7-windows.zip, such as D:/tools/vs2008/handphone/android-ndk-r7
After decompression, use the text to open the XXX \ cygwin \ home \ Administrator \. bash_profile file, and add (the above path, remove :),,,Use ue to open the file without using notepad or WordPad
Ndk =/cygdrive/D/tools/vs2008/handphone/android-ndk-r7
Export ndk
After saving and exiting, run cygwin and enter CD $ ndk. If you enter the folder you set, the setting is successful.

Possible problems to be used later: If Android ndk: Host 'awk' tool is outdated when used later. Then you can delete awk.exe in XXX \ android-ndk-r7 \ prebuilt \ windows \ bin.

4.download and install andriod_sdk_installer_r16-windows.exe. The installation path is c: \ Program Files \ android.
① After installation, open the c: \ Program Files \ Android-SDK \ platforms \ Android-8 folder, which contains an andriod. copy the JAR file and change the suffix to zip. decompress the package to the current directory to obtain an android folder.
② Add a valid path to the classpath system path, for example, c: \ Program Files \ Android-SDK \ platforms \ Android-8 \ android
Problems that may occur later: if you do not set this step, you will be prompted during the javah operation.
Error: unable to access Android. App. Activity
Android. App. Activity Class file not found

5. The following are related plug-ins developed based on Eclipse, C ++, and andriod.
① Download and decompress eclipse
② Download the corresponding C ++ development plug-in CDT, the following CDT is as follows:

Http://www.eclipse.org/downloads/download.php? File =/tools/CDT/releases/Helios/Dist/cdt-master-8.0.1.zip, do not unzip.

In eclipse, help-> install new software...
Click the Add button and enter a name such as CDT in name. Select the downloaded CDT file in archive.
Remove the "Contact all update sites during install to find required software" check box, because it is still online to obtain information, slow and dead. If you find the error, you can just remove the package.
③ Install the android development plug-in
Open eclipse and choose help> install new software on the menu bar.
Click the Add button, name to enter andriod, and then the URL to fill in the https://dl-ssl.google.com/android/eclipse/ (if an error occurs, please change HTTPS to HTTP), the error to cancel that
After the installation is successful, the andriod SDK manager and AVD manager are displayed in the window menu of eclipse, and you can create an andriod project in file-> New-> Other.
④ It should be noted that the uninstall plug-in is also connected to the "avaliable web site" on the help-> install new software page, which can be blocked and detachable. You can also click installation detail in help-> about eclipse to uninstall it.

6. OK, if the above is complete, create an andriod project below to try (you can directly create a myfirstjni project in XXX \ android-ndk-r7 \ samples)
①Code(Note the package name ):
Package com.cn. test;

Import android. app. activity;
Import android. OS. bundle;
Import android. widget. textview;
public class myfirstjniactivity extends activity {
Public void oncreate (bundle savedinstancestate) {
super. oncreate (savedinstancestate);
textview TV = new textview (this );
TV. settext (stringfromjni ();
setcontentview (TV );
}< br>
Public native string stringfromjni ();
static {system. loadlibrary ("myfirstjni") ;}

}

② This step may cause problems in step 2 and step 4.
Before using the javah-JNI command, you must use cmd to enter the classes folder F: \ eclipse \ workspace \ myfirstjni \ bin \ Classes of the project. (Remember, you do not need to copy any files during the operation. The full path F: \ eclipse \ workspace \ myfirstjni \ bin \ Classes \ com \ CN \ test is included in this folder, it contains the myfirstjniactivity file. class), then the command is javah-JNI com.cn. test. myfirstjniacriity. after successful, a com_cn_test_myfirstjniactivity.h header file is generated in the classes folder.

③ Create a new folder JNI under the myfirstjni folder and use eclipse to create a com_cn_test_myfirstjniactivity.c file,
The content is as follows (the function name is the same as that in the header file)
# Include <string. h>
# Include <JNI. h>

Jstring java_com_cn_test_myfirstjniactivity_stringfromjni (jnienv * ENV, jobject thiz)
{
Return (* env)-> newstringutf (ENV, "hello from JNI! ");
}

④ Copy Android. mk in XXX \ android-ndk-r7 \ samples \ hello-JNI \ JNI to XXX \ android-ndk-r7 \ samples \ myfirstjni \ JNI, and then open it with text, change
Local_module: = myfirstjni
Local_src_files: = com_cn_test_myfirstjniactivity.c

⑤ Open cygwin, CD into XXX \ android-ndk-r7 \ samples \ myfirstjni \ JNI, then
Enter $ ndk/ndk-build
A. So file is successfully generated under XXX \ android-ndk-r7 \ samples \ myfirstjni \ libs \ armeabi

⑥ OK, it's done. Eclipse F11 to check whether the simulator is displayed.

 

 

Reference Source

Related Article

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.