内容如其名,纯小白从零开始搞这个。原因是学长说要用as链接linux下ndk编译的so库,而不能直接用as生成,那么好的工具,说不用就不用了。不过既然有要求,那咱也不能含糊,脱下裤子,不不不,撸起袖子就是干。
文章目录
神奇的又有了更新,下面是调用非JNI标准的函数的步骤,在最后面会加上调用标准JNI函数的步骤
调用非JIN标准函数
1 搭建的环境
windows10 1803版
VirtualBox 5.2.14版本下的debian-9.5.0-armd64虚拟机
Android studio 3.2
2 linux方面
首先配置好NDK环境
1下载ndk https://developer.android.google.cn/ndk/downloads/
2 解压 unzip <filename.zip>
3 配置环境变量
#vim /etc/profile 在文件末尾添加如下
export ANDROID_NDK=“ndk路径”
export PATH="$ANDROID_NDK:$PATH"
4.更新系统变量
#source /etc/profile
5.检查ndk环境配置正确与否
#ndk-build
//出现如下界面即配置成功
AndroidNDK: Could not find application project directory !
Android NDK: Please define the NDK_PROJECT_PATH variable topoint to it.
/android-ndk-r16b/build/core/build-local.mk:151: *** Android NDK: Aborting . Stop.
3 linux下用ndk编译成so
新建一个文件夹jni,然后在jni文件夹下
首先需要cpp和h文件,我的只是简单做个例子,如下
testC.h
#ifndef TESTC_H
#define TESTC_H
int testC();
#endif
testC.cpp
#include "testC.h"
int testC()
{
return 6;
}
LOCAL_PATH:=$(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE :=testC
LOCAL_SRC_FILES:=testC.cpp
include $(BUILD_SHARED_LIBRARY)
APP_ABI := all # 编译类型为适配所有架构的cpu
APP_PLATFORM := android-28 # 对应版本是28
编译命令
ndk-bu