Use NDK to create and configure C ++ programs (native pure C ++ project, excluding JAVA code)

Source: Internet
Author: User

Preface: This article was written on the basis of the previous blog: Building an Android Development Environment (using NDK to develop C/C ++ programs without installing Cygwin) under Eclipse, if this article is not clear, please observe my previous article. Link: http://www.cnblogs.com/xiaomiao/archive/2012/02/20/2360308.html

 

-------------------- Split line ----------------------

1. First, build the Android test platform (see the document for details: Build an Android development environment in Eclipse (use NDK to develop C/C ++ programs without installing Cygwin).

2. As described in Figure 1, first create an Android project (see the following document:Android. NDK. Beginner's. Guide, Author:Sylvain Ratabouil,Let me send another link., Http://ishare.iask.sina.com.cn/f/23061508.html? Retcode = 0This is a resource Sina loves to ask. It requires two points to be downloaded. If there are no points, you can search for one more point, which won't be too difficult)

   

Note: 1. The project name and package name can be customized. It is worth noting that the corresponding name will be changed to the corresponding name in the next AndroidManifest. xml.

2. Do not check Create Activity.

3. For the Android platform Version and Min SDK Version, only the corresponding Version is required.

    

(Figure 1)

 

 

3. modify the content of the AndroidMainfest. xml file to the following content. The only thing to note is <meta-data android: name = "android. app. in the lib_name "android: value =" droidblaster "/> label, the value must be the same as that of Android. the LOCAL_MODULE names in mk are the same.

The content of AndroidMainfest. xml is as follows:

<? Xml version = "1.0" encoding = "UTF-8"?>

<Manifest xmlns: android = "http://schemas.android.com/apk/res/android"

Package = "com. packtpub. droidblaster"

Android: versionCode = "1"

Android: versionName = "1.0" type = "codeph" text = "/codeph">

<Uses-sdk android: minSdkVersion = "10"/>

<Application android: icon = "@ drawable/icon"

Android: label = "@ string/app_name">

<Activity android: name = "android. app. NativeActivity"

Android: label = "@ string/app_name">

<Meta-data android: name = "android. app. lib_name"

Android: value = "droidblster"/>

<Intent-filter>

<Action android: name = "android. intent. action. MAIN"/>

<Category android: name = "android. intent. category. LAUNCHER"/>

</Intent-filter>

</Activity>

</Application>

</Manifest>

 

4. Use Eclipse to convert the generated project to a C ++ project, as shown in Figure 2:

    

(Figure 2)

5. Create and configure a Builder so that the project can automatically compile C/C ++ code. (See section 5.5 in the previous blog. the creation process is described in detail in this document)

6. Right-click the project, select Properties> C/C ++ General> Path and Symbols, and find the columns of DES,

Add three environment variables, as shown in figure 3.

 

(Figure 3)

Note: The three variables point:

$ {Env_var: ANDROID_NDK}/platforms/android-9/arch-arm/usr/include;

$ {Env_var: ANDROID_NDK}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/lib/gcc/arm-linux-androideabi/4.4.3/include;

$ {Env_var: ANDROID_NDK}/sources/android/native_app_glue;

ANDROID_NDK is the system environment variable, representing the installation directory of the NDK.

7. Create a folder jni under the project directory, and create the file Android. mk in jni. The content of Android. mk is as follows:

LOCAL_PATH: = $ (call my-dir)

Include $ (CLEAR_VARS)

LOCAL_MODULE: = droidblster

LOCAL_SRC_FILES: = Main. cpp EventLoop. cpp Log. cpp

LOCAL_LDLIBS: =-landroid-llog

LOCAL_STATIC_LIBRARIES: = android_native_app_glue

Include $ (BUILD_SHARED_LIBRARY)

$ (Call import-module, android/native_app_glue)

 

Note: The statement marked as a red font must be filled in according to the specific project.

 

8. Put the prepared. cpp and. hpp documents into the jni file. (Reference document: Page 150-153 of Android. NDK. Beginner's. Guide. Due to limited space, I will not post those codes)

 

9. Compile and run, OK!

 

------------------------ Split line -----------------------

  

The text is not very detailed, at least not detailed in the previous article. However, I think it should be enough to list the important situations that need attention.

Some people may think that there are some problems with this layout, because I usually write a document on the word (after all, this is important) and then copy it out, paste it here and make a slight modification.

Finally, let's talk about it again. Welcome to the discussion, and repost it. Love the discussion and accept criticism. OK!

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.