[Android] environment configuration-Android Studio development NDK and androidndk

Source: Internet
Author: User

[Android] environment configuration-Android Studio development NDK and androidndk

========================================================== ======================
Author: qiujuer
Blog: blog.csdn.net/qiujuer
Website: www.qiujuer.net
Open-source Library: Genius-Android
Reprinted please indicate the source: http://blog.csdn.net/qiujuer/article/details/42040963
========================================================== ======================

Which one is better than NDK? Find Blue Fly in XX.

SpeakingNDKDevelopment is to call the underlyingC/C ++To improve efficiency.

But in many cases, you don't need to use it. Why? I personally feel that it is sometimes troublesome. First, we need to configure NDK and download Cygwin, configure Cygwin, and then compile and generate it. If you useEclipseIt is indeed much easier to compile, but a lot of configuration is required in the early stage. However, if the configuration is wrong, it cannot be hurt.

What Google is pushingAndroid StudioThis is a good tool, at least for nowEclipseThis can be done on both sides.EclipseNot necessarily.

In the following exampleAndroid StudioHow to proceedNDKDevelopment.

Preparations for building the Android Studio Environment

In my previous article [Android], the official version of Android Studio 1.0 is introduced.

Build an NDK Environment

  • Download: http://developer.android.com/tools/sdk/ndk/index.html
  • Windows32: android-ndk-r10d-windows-x86.exe
  • Windows64: android-ndk-r10d-windows-x86_64.exe
  • Mac OS X 32-bit: android-ndk-r10d-darwin-x86.bin
  • Mac OS X 64-bit: android-ndk-r10d-darwin-x86_64.bin
  • Linux 32-bit (x86): android-ndk-r10d-linux-x86.bin
  • Linux 64-bit (x86): android-ndk-r10d-linux-x86_64.bin

They are all executable files. After downloading them, click them to decompress them to the current folder. Of course, you can use the command line to decompress them across folders.

Create a project NDKDemo:


Create a corresponding class. In MathKit, we calculate the number of Integers of the INT value.

public class MathKit {    public static native int square(int num);    static {        System.loadLibrary("JniDemo");    }}
StringKit: This is the charge:

public class StringKit {    public static native void setNull(String str);    static {        System.loadLibrary("JniDemo");    }}

Prepare the. h file

Go to the Java directory. Run CMD to enter the Directory and perform javah operations:


This is certainly not a stranger to everyone. This file is the header file corresponding to the java class. Of course, if you are more powerful, you don't need to generate it like this, and you can just repeat the code to complete it yourself; I can't do it anyway.

Create a folder as follows:


Copy the previous file:


Implementation:

Net_qiujuer_ndkdemo_jni_MathKit.cpp

#include <net_qiujuer_ndkdemo_jni_MathKit.h>JNIEXPORT jint JNICALL Java_net_qiujuer_ndkdemo_jni_MathKit_square  (JNIEnv *env, jclass cls, jint num)  {        return num*num;  }
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)  {  }
Set Project

Set local. properties in the root directory


This setting is not required. If you have set the environment variable, you do not need to set it. If you have not set it, it will appear:


Set APP Project build. gradle


This setting is used to set the generated Jni name to JniDemo.

Main file call:


Click Run now:


It can be seen that this call is very simple. It can be said that I have done the most simple operation, or even generated. H files can be edited. sh file for Batch Processing (this will be available later ).


More

In normal operations, we need to establish the following:

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
These two files are not created here. How can this problem be decided?

We can press Ctrl on the modelName of the ndk and click it. This interface will appear:



These are all parameters that can be set. Corresponding:

Ndk {moduleName "JniDemo" // set the generated file name cFlags "-DANDROID_NDK-D_RELEASE" // This corresponds to the generated mode ldLibs "m", "log ", "jnigraphics" // This corresponds to LOCAL_LDLIBS, but you need to remove the previous "l" abiFilters "all" // This is the corresponding APP_ABI stl "stlport_shared" // This corresponds to APP_STL}

Well, I wish you all success. Package and upload the project.

Click here to download this project.

========================================================== ======================
Author: qiujuer
Blog: blog.csdn.net/qiujuer
Website: www.qiujuer.net
Open-source Library: Genius-Android
Reprinted please indicate the source: http://blog.csdn.net/qiujuer/article/details/42040963
========================================================== ======================

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.