Build the android ndk8 compiling environment and test hellojni

Source: Internet
Author: User

Reference:

Http://www.cnblogs.com/hibraincol/archive/2011/05/30/2063847.html

Http://blog.csdn.net/cboy017/article/details/8455629

Why ndk?

Our normal Android Application Development does not support ndk development, and SDK development is enough. The normal development environment is eclipse + SDK + ADT.

However, if you encounter some transplanted C/C ++ functional modules, the development of ndk is particularly convenient.

In summary, it is divided into the following situations:

1. Code protection, because the Java-Layer Code of APK is easily decompiled, it is difficult to reverse the C/C ++ library.

2. Call a third-party C/C ++ library in ndk, because most open-source libraries are written in C/C ++ code.

3. Ease of transplantation. The C/C ++ library can be used again on other embedded platforms.

Download ndk from the home page

Http://developer.android.com/tools/sdk/ndk/index.html

We can also see from the installation instructions that cywin1.7 and above need to be installed for cross-Compilation of C/C ++ code

Http://www.cygwin.com/

After downloading the ndk, select the correct path from eclipse> preferences> Android> ndk.

Install cywin

Compile the ndk. Under the default settings, you only need to select devel (Click devel in the list,Change the following default to install, As shown by the arrow in the figure) All others are in the default status.

(In fact, ndk need not much, mainly autoconf2.1, automake1.10, binutils, GCC-core, GCC-, G ++, gcc4-core,

Gcc4-g ++, GDB, PCRE, PCRE-devel, gawk, make)

The download completion time depends on the number of installation packages you select and the network connection speed.

Configure cygwin

Enter the cygwin directory in the command line and execute cygwin. bat. If you are not using the Administrator account to log on to the system, the cygwin installation directory \ home \

Folder to generate a new folder named after your login name.

Modify the file ". bash_profile" in the new folder and open it in a text editor such as UE or editplus,

Add at last: (D/android-ndk-r8 is the path to install ndk)

Ndk_root =/cygdrive/D/Eclipse/android-ndk-r8e

Export ndk_root

Save and close.

Okay. So far, the ndk compilation environment has been installed and set up.


Now let's import the JNI project in the ndk sample.

Cygwin has not been used yet. Now we can use it to compile C ++, right-click the project, and create a new compilation rule in the project property builders:

Follow the settings below

Location: D: \ cygwin \ bin \ bash.exe

Working directory: D: \ cygwin \ bin

Arguments: -- login-c "CD/cygdrive/D/Eclipse/android-ndk-r8e/samples/Hello-JNI & $ ndk_root/ndk-build"

Then set in build options

Finally, move the ndk_builder to the top.

Finally, compile the project. After the compilation is successful, the *. So library file is successfully generated. Run OK.

Some colleagues may have questions about this JNI project. For details about how to use the header file in a JNI project or how to create an ndk engineer, refer to this blog:

Http://www.cnblogs.com/hibraincol/archive/2011/05/30/2063847.html

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.