NDK开发汇总
报错:No implementation found for java.lang.String
问题排查
- build.gradle配置 abiFilters ‘armeabi-v7a’
android {
...
defaultConfig {
...
externalNativeBuild {
cmake {
cppFlags ""
abiFilters 'armeabi-v7a'
}
}
}
}
- CmakeList配置实现方法的cpp路径:add_library
cmake_minimum_required(VERSION 3.4.1)
# 引入指定目录下的CMakeLists.txt
add_subdirectory(src/main/cpp/librtmp)
add_library(
native-lib
SHARED
src/main/cpp/native-lib.cpp
src/main/cpp/VideoChannel.cpp)
...
- 检查包名路径与c/cpp中静态注册的是否一致
java路径:com.cn.ray.rtmpdump.LivePusher
cpp实现方法
#include <jni.h>
#include <string>
#include "safe_queue.h"
extern "C" JNIEXPORT void JNICALL
Java_com_cn_ray_rtmpdump_LivePusher_native_1init(JNIEnv *env, jobject instance) {
}
注意:
- 引入#include <jni.h>
- 方法中有_后面带1
- cpp中实现带extern “C”,extern "C"只针对当前这一个方法
- loadLibrary 要在方法调用前(static)加载,注意是 System.loadLibrary
static {
System.loadLibrary("native-lib");
}
- 清除缓存
Clean Project-> Rebuild Project -> Refresh Linked C++ Projects