在Android studio中使用jni调用C/C++,有两种方式,一种是使用传统方式,通过Android.mk来调用,一种是使用cmake来调用
一,传统方式调用
1. 创建一个as工程NDKDemo,包名为:
com.sun.android.ndkdemo
2. 在ndkdemo包下创建一个调用本地库的工具类 NDKTools
package com.sun.android.ndkdemo; public class NDKTools { public static native String getStringFromNDK(); }
3. 在默认创建的MainActivity的布局文件中,textView添加id,方便之后引用设置
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <TextView android:id="@