Use NDK for development without cygwin

Source: Internet
Author: User

NDK comes with a compiler starting from 7, and does not need to configure the cygwin environment on windows.

Configure the NDK path in ipvs

In eclipse, click window-Perferences in the menu bar to configure the NDK path.

Add native lib to the Project

Create a blank Android project and right-click Adnroid Tools-Add Native Support in the root directory...

In the displayed dialog box, enter the name of the lib to be created and click Finish. A jni folder is displayed under the project directory, which contains a blank cpp file and an Android. mk file.

The content of the Android. mk file is

LOCAL_PATH: = $ (call my-dir)

Include $ (CLEAR_VARS)

LOCAL_MODULE: = TestJni
LOCAL_SRC_FILES: = TestJni. cpp

Include $ (BUILD_SHARED_LIBRARY)

TestJni is the name of the lib to be loaded, and LOCAL_SRC_FILES is the path of the resource file.

Hello jni


The MainActivity. java code is as follows:

  MainActivity  =  TextView( "TestJni"

The TestJni. cpp Code is as follows:

#include <jni.h>  jstring Java_com_example_testjni_MainActivity_helloFromJni(JNIEnv * env->NewStringUTF(

Run the program directly. You can see the NDK build output in the Console window.

One thing to note: Because I use the x86 Android Virtual Machine to run, all of them use the x86 compiler. The compiler method is to create an Application. mk file in the jni directory and enter the following content:

# APP_ABI: = armeabi
APP_ABI: = x86
# APP_ABI: = armeabi armeabi-v7a x86 mips mips-r2 mips-r2-sf
# APP_ABI: = all
APP_STL: = stlport_static

For Android phones with common arm processors, APP_ABI: = armeabi is used. For x86 processors, APP_ABI: = x86 is used.

If APP_ABI: = all, The so of all commands will be compiled.

The running result is as follows:

As for how C/C ++ compilation is implemented, let's take a look at the Properties of the project.

There are two more items in Builders: CDT Builder and hierarchical Configuration Builder.

Add Builder for existing projects

If the jni directory already exists in the project, but the C/C ++ compiler is not configured, the experts can add the Builder by themselves. For me, this cute little cainiao, right-click the project menu, add a new blank so and delete it. Then, CDT Builder and deployment Configuration Builder will be released.

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.