Android Studio hands-On call you NDK development environment building and basic use

Source: Internet
Author: User

First, the preparatory work

Download NDK:http://dl.google.com/android/repository/android-ndk-r12b-windows-x86_64.zip

Second, the Android studio environment configuration

Path: file->setting-> Look at the picture, there is an ndk to tick on.

Third, the new project, look at the picture

Iv. Configuring the NDK environment

The above three steps, after the completion of the project, will give you to build a Demo,demo in the CPP, you can directly run one side, feel a bit. Then, a face of the crazy, wrong ........

Look at the solution below.

Unzip the step by one of the downloaded compressed packages. I put it near the as directory. Just put it, you can find it.

This configures the environment.

Five, the demo run a run, can be done .....

There is always a restless heart, do not modify how can be done.

The demo is to return a string, I have to make a return int type, but also write a function body, run.

Then, a native method is written directly in the mainactivity. The corresponding method is generated in CPP. Then, the function body is called. Run for a moment and immediately error

 for ...... .....

What's the situation? The function body has been declared. As no error and warning, a run error.

Then give the correct code, and you understand it yourself:

#include <jni.h>#include<string>extern "C"{intcount (); Jniexport jstring Jnicalljava_com_ailin_shoneworn_ndkdemo_mainactivity_stringfromjni (JNIEnv*Env, Jobject/* This*/) {std::stringHello ="Hello from C + +"; returnEnv->Newstringutf (Hello.c_str ());}intcount () {intA =1; intb=2; returnA +b;} Jniexport jint Jnicalljava_com_ailin_shoneworn_ndkdemo_mainactivity_intfromjni (jnienv*Env, jobject instance, Jint x, Jint y) {    //TODO    returncount ();}}

Summary: C + + has been too long useless, a lot of things have been forgotten. Hey!

Above, only need to add {} In the function body outside extend "C", the two function body is enclosed together is good.

Android Studio calls you NDK development environment building and basic use

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.