[Android] Environment optimized configuration Android Studio Development NDK

Source: Internet
Author: User

========================================================
Qiujuer
Blog:Blog.csdn.net/qiujuer
site:Www.qiujuer.net
Open Source Library:Genius-android
Reprint Please specify Source: http://blog.csdn.net/qiujuer/article/details/42040963
========================================================

Which strong is the NDK developing? xx xx find Blue Fly.

Speaking of NDK development. In fact, there are times when it's necessary to call some of the bottom- C + + things for project requirements. The other is to be more efficient.

But there are so many times that you don't have to. Personal feeling sometimes think of trouble, the first to configure the NDK to download Cygwin, configuration Cygwin, and then need to build , ah too troublesome.

Suppose you say that using Eclipse, it is very simple to compile, but it is necessary 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 is a great tool, at least for now, on this side of Eclipse that can be done. There's not necessarily Eclipse on this side.

Here's 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.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

Can be run files, download and click to extract to the current directory, of course, you can use the command line for cross-directory decompression.

Establish a project Ndkdemo:


Create the appropriate classes. In Mathkit we implement the calculation of the square number of the 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 folder; CMD enters the folder for Javah operations:


This must not be unfamiliar to everyone, the file is the Java class corresponding header file. Of course, if you're more powerful, you don't have to generate it. It's OK to write your own program. I can't do it anyway.

For example, create the directory:

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvcwl1anvlcg==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">

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  (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 up the project

Set the root folder:local.properties

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvcwl1anvlcg==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">

This setting is not required. Let's say you set an environment variable without setting it, but if you don't have one, it will appear:


Set up an APP project build.gradle


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

Primary file invocation:

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvcwl1anvlcg==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">

Now click to execute:

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvcwl1anvlcg==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">

It's easy to see. This call can be said to be the simplest I have ever done, or even generate. H files are capable of editing. sh files for batch processing (this time later).


Many other

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?

This interface will appear when we can press CTRL on the NDK modelname to click on it:



These are all the parameters that can be set.

respectively, corresponding:

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

All right. I wish you all success in this respect. Project Package upload.

Click here to download the project.

========================================================
Qiujuer
Blog:Blog.csdn.net/qiujuer
site:Www.qiujuer.net
Open Source Library:Genius-android
Reprint Please specify Source: http://blog.csdn.net/qiujuer/article/details/42040963
========================================================

Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.

[Android] Environment optimized configuration Android Studio Development NDK

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.