ZZ Android Studio NDK JINI

Source: Internet
Author: User

When it comes to NDK development, there are some times when you need to call some of the bottom- C + + programs for your project needs, and in order to be more efficient.

But there are times when you don't have to, and that's why? Personal feeling sometimes feel trouble, first to configure the NDK to download Cygwin, configuration Cygwin, and then need to build, ah too troublesome. If you say the use of Eclipse, it is very simple to compile, but also need to configure a large number of early, ah, the configuration is wrong and can not afford to hurt.

Now Google's main push for Android Studio This is a good tool, at least now on the Eclipse can be done on this side, there is not necessarily eclipse on this side.

Let's talk about how to develop the NDK in Android Studio .

Getting ready to work Android Studio environment setup

In my previous article [Android] environment configuration, the official version of Android Studio 1.0 has been introduced.

NDK Environment Setup

Download: http://developer.android.com/tools/sdk/ndk/ Index.htmlwindows32:android-ndk-r10d-windows-x86.exewindows64:android-ndk-r10d-windows-x86_64.exemac OS X 32- Bit:android-ndk-r10d-darwin-x86.binmac OS X 64-bit:android-ndk-r10d-darwin-x86_64.binlinux 32-bit (x86) : Android-ndk-r10d-linux-x86.binlinux 64-bit (x86): Android-ndk-r10d-linux-x86_64.bin

are executable files, download and click to extract to the current folder, of course, you can use the command line for cross-folder decompression.

Establish a project Ndkdemo:

Establish the corresponding class, in Mathkit we implement the calculation of the square number of INT value.

public class Mathkit {public    static native int square (int num);    static {        system.loadlibrary (Jnidemo);    }}

Stringkit this is used by sucks:

public class Stringkit {public    static native void SetNull (String str);    static {        system.loadlibrary (Jnidemo);    }}

Prepare the. h file

Enter the Java directory; CMD enters the directory for Javah operations:


This presumably everyone is not unfamiliar with it, the file is the Java class corresponding to the header file, of course, if you are more powerful words can not be generated, your own knock code to complete the line;

Create a folder as follows:

Copy the previous file in:

implemented separately:

Net_qiujuer_ndkdemo_jni_mathkit.cpp

#include <net_qiujuer_ndkdemo_jni_mathkit.h>jniexport jint jnicall java_net_qiujuer_ndkdemo_jni_mathkit_ Square  cls, jint num)  {        return num*num;  } </net_qiujuer_ndkdemo_jni_mathkit.h>

Net_qiujuer_ndkdemo_jni_stringkit.cpp

#include <net_qiujuer_ndkdemo_jni_stringkit.h>jniexport void Jnicall java_net_qiujuer_ndkdemo_jni_stringkit_ SetNull  (jnienv *env, Jclass obj, jstring str)  {  }</net_qiujuer_ndkdemo_jni_stringkit.h>
Set up the project

Setting the root directory: Local.properties

This setting is not required, and if you set the environment variable you can not set it, if not, then the settings will appear:

set up an APP project Build.gradle

This setting is to set the generated JNI name to: Jnidemo.

Primary file invocation:

Now click on Run:

Can be seen is very simple, this call can be said to be the simplest I have done, and even generated. H files can be edited by the. sh file for batch processing (there is time to do this later).

More

In the usual operations we inevitably have to build:

android.mk

Local_path:= $ (call My-dir) include $ (clear_vars) local_module    : = geniuslocal_src_files: = Net_qiujuer_ Imageblurring_jni_imageblur.cpplocal_ldlibs    : =-lm-llog-ljnigraphicsinclude $ (build_shared_library)

Application.mk

app_abi:= allapp_platform.:= android-19app_optim:= Release

And here are the two files are not established, then how to decide?

We can press and hold CTRL on the NDK's modelname to click on the interface that will appear:

These are all parameters that can be set. corresponding to each:

ndk{            modulename Jnidemo//Set the generated file name Cflags-dandroid_ndk-d_release//            This corresponds to the generation mode            ldlibs m, log, Jnigraphics This corresponds to local_ldlibs but need to remove the front "L"            abifilters All//This is the corresponding App_abi            STL stlport_shared//This corresponds to App_stl         }

All right, I wish you all a success. Project Package upload.

ZZ Android Studio NDK JINI

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.