Step by Step - How to create a c++ library with NDK on Android Studio 1.5 (not experimental way)

转载 2017年03月24日 00:48:23

转载地址:http://kn-gloryo.github.io/Build_NDK_AndroidStudio_detail/

1. Configure JDK, NDK path environments

I'm using jdk 1.8.0_65 and ndk-bundle. We can use the official ndk also.

Let's see!

2. Add javah, ndk-build as External Tools

(Menu Location is 'Settings > Tools > External Tools')

2-1. Configure javah

Let's see!

2-2. Configure ndk-build

Let's see!

2-3. Configure ndk-build clean

Let's see!

3. Create a new Android Studio Project

Let's see!

4. Add a java class for JNI

Let's see!

5. Create a folder for JNI

screenshot from 2015-12-03 15_36_30

6. Configure build.gradle

android {
  ...
  defaultConfig {
    ...
    ndk {
      moduleName "your dllname"
    }

    sourceSets.main {
      jni.srcDirs = []
      jniLibs.srcDir "src/main/libs"
    }
    ...
  }
  ...
}

7. First Build

We will encounter an error like 'Error: NDK integration is deprecated in the current plugin. blah blah'.

Because we are not using the experimental class for NDK.

Let's add one line in 'gradle.properties'.

android.useDeprecatedNdk=true

And build again, it must be succeeded.

8. Create a JNI header file

Use 'NDK external tools - javah'

screenshot from 2015-12-03 15_40_32

Then we will have a JNI header file.

screenshot from 2015-12-03 15_41_07

9. Create a C++ source file

We don't need to check "Create associated header".

screenshot from 2015-12-03 15_42_13

screenshot from 2015-12-03 15_42_26

screenshot from 2015-12-03 15_43_55

10. Create some MakeFiles

Android.mk

screenshot from 2015-12-03 15_44_24

screenshot from 2015-12-03 15_44_37

screenshot from 2015-12-03 15_45_44

Application.mk

screenshot from 2015-12-03 15_46_24

11. Build Our NDK Library

screenshot from 2015-12-03 15_51_28

ndk_build_result

12. Let's Use Our NDK Library Function

use_ndk

13. Final Build and Create APK

After build, We must have our library in the APK.

screenshot from 2015-12-03 15_54_57

screenshot from 2015-12-03 15_55_12

14. Let's Enjoy NDK :)


Oracle 11g Active Data Guard step by step: How to create a Physical Standby Database using RMAN

Database IP DB_UNIQUE_NAME Oracle Net Service Name  Primary 192.168.8.1...

kubernetes1.4 基础篇:Learn Kubernetes 1.4 by 6 steps(3):Step 2. Using kubectl to Create a Deployment

在上一篇文章中我们学习到了如何快速搭k8s的集群。本文将会将会学到Kubernetes的应用部署(Deployment),以及如何使用kubectl来部署我们的应用。被部署的应用我们将直接使用kube...

Step by Step Setup Git Server on Windows with CopSSH + msysGit and Integrate Git with Visual Studio

http://www.codeproject.com/Articles/296398/Step-by-Step-Setup-Git-Server-on-Windows-with-CopS I...

How to Create a High Availability Setup with Pacemaker, Corosync and Floating IPs on CentOS 7

How to Create a High Availability Setup with Pacemaker, Corosync and Floating IPs on CentOS 7 Poste...
  • gzhouc
  • gzhouc
  • 2016年11月20日 14:01
  • 470

How to create a VM on a specified host with openstack

如果用devstack安装的openstack cluster,那么所有的source code都在/opt/stack下面。 如果用户想创建一个VM在特定的机器上,openstack提供了...

how to post URL with Image on facebook by ShareKit

Sharekit - sending a url link to facebook up vote0down votefavorite share [fb]share ...

Step By Step Guide To Create Physical Standby Database Using RMAN Backup and Restore (Doc ID 469493.

In this Document   Goal   Solution   References Applies to: Oracle Database - ...

How can I use Microsoft Visual C++ 2010 to create MEX files with MATLAB 7.10 (R2010a)?

标题 How can I use Microsoft Visual C++ 2010 to create MEX files with MATLAB 7.10 (R2010a)?1 ...

How can I use Microsoft Visual C++ 2010 to create MEX files with MATLAB 7.10 (R2010a)?

直接下载下面的压缩包,然后解压出来,把\bin\win32\mexopts里面对应的文件拷贝到matlab2010a安装路径里面对应的文件夹下面即可!!   I have Visual Studi...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Step by Step - How to create a c++ library with NDK on Android Studio 1.5 (not experimental way)
举报原因:
原因补充:

(最多只允许输入30个字)