NDK Development environment Construction and development process under Windows

Source: Internet
Author: User

in development project for Android apps. Whether it's a game or a normal application. are often used. So is the dynamic link library, and what are the advantages of. So. This people can check on the Internet, I do not do too much explanation.

. So is a file type under Linux, so compile. So must be in Linux environment, then how to compile under win? Random search on the Internet, the tutorial is also a variety of, not clear, not a certain foundation, even if you look at the tutorial to the last expected or choke, not to mention just start learning people, looked to ensure dizziness, I also based on some examples on the Internet. summed up a person think it is relatively simple one. So compile method: GNUstep (online There are many use Cygwin. You can also study it).

Go to the chase. Win under. So development environment set up: (Because the resources on the Internet is not very easy to find, so I will need to put the tools into the network disk)

1.NDK ( This NDK version number is ): link:   http://pan.baidu.com/s/1bn1xdqb PASSWORD: LR7D 

2.gnustep-core-0.34.0-setup.exe. Gnustep-devel-1.4.0-setup.exe,gnustep-msys-system-0.30.0-setup.exe Link: http://pan.baidu.com/s/ 1ntlwd53 Password:kuuj

After the download and installation is complete (the installation path is available by default):

First of all. Import the NDK's path in Eclipse (the path after the decompression is complete)


And then. In the C drive (my installation path is in the C drive), locate the file gnustep.conf and open to configure the environment variable:


Add or change the last two lines of the file: (Note your ndk's path)

Ndk=e:/baiyuliang/android-ndk-r10export=ndk
Open GNUstep, enter make-v, OK (enter key), and then enter Gcc-v. Appear for example with symptoms:


Enter the CD $NDK and symptoms appear:


It means the development environment has been built successfully!

All right. Next we will do a simple sample to learn how to use GNUstep to develop the NDK:

To create a project in Eclipse Project, package name: Com.byl.testjni, the main class name Mainactivity (this to see clearly, next will ask you to enter their path and name correctly):


After the creation is complete, open cmd and enter the Javah command to execute:


appears, it means that everything goes well and you can continue down, assuming that the command is not found, then check that your JDK environment variable is configured correctly.

Next. Navigate to the path in the SRC directory drive in the project project:



Open the mainactivity in the project. Add the following code:

    Public native String hello ();//Definition. The method name in the. So       static{            system.loadlibrary ("Testjni");//define the name of the generated. So    }
This is required to be written in the activity of the call. So, at compile time will be self-generated in the header file definition of the method name, as well as the last generated. So name, next in cmd enter the following command, generate C headerFile:

Javah-d. /jni com.byl.testjni.MainActivity
Be careful not to write wrong path. Once determined, assuming that nothing is indicated, the operation succeeds, and in eclipse right-refreshes the project:


Then create a C file in the JNI directory. The name is the same as the. So name, which is TESTJNI.C:


Next. Still writing the Android.mk file in the JNI directory, the android.mk file can be found in the Samples/hello-jni/jni under the NDK installation path and copied directly:


open android.mk, and changes in the local_module and Local_src_files:

local_module is descriptive of the narrative module, used to give java The module name of the call. The corresponding libtestjni.so will be generated;
local_src_ Files are source files, and multiple file spaces are separated.


The key step is here. Open GNUstep and start compiling and generating the. so file:

1. Enter the command. Navigate to the location of the project (TESTJNI):

Cd/e/androidproject/testjni
2. Enter the command to generate the testjni.so file:

$NDK/ndk-build



What you see is the success of the execution, refresh the project, see Libs under the Testjni.so file is not already quietly lying there? (Note: The resulting file will be preceded by a lib that is libtestjni.so)


Here is the time to witness miracles:

Open Mainactivity, in the OnCreate method. Call the Hello () method and print, assuming that the "hellojni! "That means. So is generated without error and the call succeeds.

LOG.E ("JJ", Hello ());
Execute, see LOGCAT:



Ok! Perfect execution.

After that, you will be able to put some important variables. or a service address or something in. So, and then put the generated. So into the project to be able to use it!

PS: This sample is very easy. is to print a string, and the actual application of the development of the complex methods to be written in the wrong way, so really learn the NDK development still need painstaking!

Precautions:

There are child shoes that may be generated using this sample. So the call method does not succeed when used directly on other projects, here to tell you, compile. So, the activity path used must be called in the project. So the activity of the method is consistent, for example: Aactivity in a project to invoke A. So. So, if you create a separate project, such as Project B, to generate. So, the activity path in the B project is exactly the same as a:

Project A: com.byl.testjni.AActivity,

Then the B project must also be:com.byl.testjni.AActivity


Demo Source code: http://download.csdn.net/detail/baiyuliang2013/8505977

NDK Development environment Construction and development process under Windows

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.