Android Studio for NDK development

Source: Internet
Author: User

1. Create a new JNI directory in the src/main/directory first



2, here to steal a lazy, directly from other projects to copy Android.mk,application.mk,demo.cpp to the JNI directory

in the application.mk file, configure the following:

App_abi: = Armeabi armeabi-v7a arm64-v8a x86 x86_64 MIPS MIPS64
App_platform: = android-7


3, in the local.properties file configuration: ndk.dir=d\:\\android\\androidstudio\\ndk\\android-ndk-r10e


4, in the Build.gradle file in the Android node Defaultconfig The following configurations are configured in the node:

Android {    compilesdkversion    buildtoolsversion "22.0.1"    defaultconfig {        ApplicationID " Com.ycy.ndkdemo "        minsdkversion        targetsdkversion        1        versionname" 1.0 "        NDK {            ModuleName "demo"            ldlibs "log", "Z", "M"            abifilters "Armeabi", "armeabi-v7a", "arm64-v8a", "x86", "x86 _64 "," MIPS "," Mips64 "}}    }

5, through the above configuration basic OK, and then can be called in Java.

PS: This method calls native through C + + source code, and the resulting. So file is generated after the final compilation in App\build\intermediates\ndk\debug\lib



=================================================================================================


The second way to call C + + is described next


1, this method is on the basis of so library, directly on each CPU platform on the so library files in the src/main/jnilibs directory (new jnilibs directory)



2. Configure in the Android node in the Build.gradle file:

    Sourcesets {        main {java.srcdirs = [' Src/main/java ', ' Src/main/jnilibs '}    }

through the above configuration basic OK, and then you can call it heartily.


Finally, the two methods can only choose one, can not be used together, otherwise it will conflict.


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android Studio for NDK development

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.