文章目录
注1:android9.0-ndk开发系列文档提供一个ndk编译JNI库,并访问第三方库,APP 直接通过jar接口调用的方法。
注2:本文为个人学习记录,可能存在个别或多处错误,欢迎指正和讨论。
android9.0-ndk开发(1)-第三方库的生成
android9.0-ndk开发(2)-JNI代码
android9.0-ndk开发(3)-Jar打包
android9.0-ndk开发(4)-APP 调用实例
一、流程图
流程如下:
二、ndk库的生成(第三方库)
2.1 ndk下载:
https://developer.android.google.cn/ndk/downloads/
我这里选择的是Linux 64 位 (x86) android-ndk-r20-linux-x86_64.zip版本
使用以下命令后,即可使用ndk-build编译工具
export PATH=/home/ttx/work_runtime/alex/android-ndk-r20:$PATH
查看ndk-build
$ ndk-build -v
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for x86_64-pc-linux-gnu
2.2 sample.cpp
/*
* Copyright (C) 2019 Alex
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>