The Android NDK process

Source: Internet
Author: User

    • Define the Wrap class, declare the native function, load the library
 Package Com.ndk.hello;  Public class classs {    publicnative  String Say_hello ();     Static     {        system.loadlibrary ("HELLOANDROIDNDK");}    }
    • Create a JNI folder in the project root directory to generate JNI header files in this folder
Javah-classpath. /bin/classes com.ndk.hello.Classs
    • Write implementation files for the generated com_ndk_hello_classs.h
 /*   do not EDIT this file-it are machine Generated  */  #include  <jni.h >/*   Header for class Com_ndk_hello_classs  */  #ifndef _included_com_ndk_hello_ Classs#define _included_com_ndk_hello_classs#ifdef __cplusplusextern  "C"  {# endif  /*   * CLASS:COM_NDK_HELLO_CLASSS * Method:say_hello * Signature: () ljava/lang/string;  */ jniexport jstring jnicall java_com_ Ndk_hello_classs_say_1hello (jnienv  * 
#include "com_ndk_hello_classs.h"this) {    return (*env)->newstringutf ( Env, "Hello Java ndk!" );}
    • Write Android.mk file in Jni folder
# Copyright (C) thethe Android Open Source project## Licensed under the Apache License, Version2.0(The"License");fileExceptinchcompliance with the license.# obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0# # unless required by applicable law or agreed toinchwriting, software# distributed under the License is distributed in an" as is"basis,# without warranties or CONDITIONS of any KIND, either express or implied.# see the License forThe specific language governing permissions and# limitations under the license.#local_path := $(Pagermy-dir)include $ (clear_vars)local_module := helloandroidndklocal_src_files := com_ndk_hello_classs.cinclude $ (build_shared_library)
    • Cross-compiling the Mk file in the Jni folder
$Ndk/ndk-build
    • The libs/armeabi/libhelloandroidndk.so file will be generated
    • Write the Android Framework program and call the native method.
 PackageCom.ndk.hello;Importcom.ndk.hello.Classs;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.widget.TextView; Public classHelloandroidndkextendsactivity{@Override Public voidonCreate (Bundle s) {Super. OnCreate (s); Classs C=Newclasss (); String say=C.say_hello (); TextView TV=NewTextView ( This);          Tv.settext (say);      Setcontentview (TV); }}

The Android NDK process

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.