Android NDK Development (note i)

Source: Internet
Author: User

Fuse: Android NDK R7 is integrated with Cywin and does not bother to download and configure Cywin when developing the NDK.

Android NDK Development Steps:

  1. Eclipse first configures the NDK path, WINDOWS–>PREFERENCES–>ANDROID–>NDK, to specify the NDK path: for example: D:\AndroidNDK\ndk-r10e

    If you do not see the NDK configuration option under Windows–preferences–>android, then download the ECLIPSE–NDK plugin: Http://pan.baidu.com/s/1dDXBKTN, I am Win7 x64 system , so please download the corresponding ECLIPSENDK plugin according to your system. Download the Xxxxxxxxxxxxndk.jar, copy the download, and put it in the Eclipse root directory, such as the D:\Androiddevelop\eclipse\plugins file, and restart Eclipse to see it.

  2. New Android project named, Androidndkdemo, new package name Com.jni, new Jni.java, declaring the C method to be called in JNI.

  3. Select Project, right click on Android tools–>add Native support ..., set up so library named Hello-jni.so. Click Finish.

    At this point you will find in the project directory, a more JNI directory with the obj directory, the directory of two files are: Android.mk, with a hello.cpp file. I am here to replace the Hello.cpp file with the hello.c file directly.

  4. CMD into D:\workspace\AndroidJniTest\bin\
    Javah-jni Com.jni.JNI generates the Hello.h file. Reference

  5. Compiles the associated hello.c file based on the generated. h file.

    If you need to generate different specifications for different CPUs, you need to libhello.so in the hello.c file.

    hello.c

    jstring Java_com_patch_JNI_Hello(JNIEnv* env, jobject obj) {#if defined(__arm__)#if defined(__ARM_ARCH_7A__)#if defined(__ARM_NEON__)#if defined(__ARM_PCS_VFP)#define ABI "armeabi-v7a/NEON (hard-float)"#else#define ABI "armeabi-v7a/NEON"#endif#else#if defined(__ARM_PCS_VFP)#define ABI "armeabi-v7a (hard-float)"#else#define ABI "armeabi-v7a"#endif#endif#else#define ABI "armeabi"#endif#elif defined(__i386__)#define ABI "x86"#elif defined(__x86_64__)#define ABI "x86_64"#elif defined(__mips64)  /* mips64el-* toolchain defines __mips__ too */#define ABI "mips64"#elif defined(__mips__)#define ABI "mips"#elif defined(__aarch64__)#define ABI "arm64-v8a"#else#define ABI "unknown"#endifreturn (*env)->NewStringUTF(env, "Yes ,Hello from JNI !");

    }

Android.mk

    # Copyright (C) 2009 The Android Open Source Project    #    # Licensed under the Apache License, Version 2.0 (the "License");    # you may not use this file except in compliance with the License.    # You may obtain a copy of the License at    #    #      http://www.apache.org/licenses/LICENSE-2.0    #    # Unless required by applicable law or agreed to in writing, software    # distributed under the License is distributed on an "AS IS" BASIS,    # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.    # See the License for the specific language governing permissions and    # limitations under the License.    #    LOCAL_PATH := $(call my-dir)    include $(CLEAR_VARS)    LOCAL_MODULE    := hello-jni    LOCAL_SRC_FILES := hello.c    include $(BUILD_SHARED_LIBRARY)

Application.mk


Content:

    APP_ABI := all
    1. Call in activity:

    2. Run, if the compilation succeeds you will find that the LIBS directory structure has changed

Effect:

Android NDK Development (note i)

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.