在做Android JNI 或者NDK混合开发调试的时候,用AndroidStudio 的效率明显要高于在Android 源码中用Android.mk的编译so,push到机器 上测试。源码增量编译时间和来回替换时间效率太低了,尤其是碰到服务器很卡的时候,简直要命。
而且在AndroidStudio中开发c/c++的提示功能明显要好于在vs code中的提示情况。AndroidStudio时如此的丝滑和流程,所以我就把这种c/c++ 混合java 的开发调试全部挪到本地。
CSDN 上流传最多的一篇链接:https://blog.csdn.net/mjfh095215/article/details/90315162其实在版本上不适用,而且还是打马赛克的,我的天啊!
首先看测试的so 的源文件和头文件:
// // Created by minwenping on 2021/12/23. // #ifndef NATIVETEST_OTHERS_H #define NATIVETEST_OTHERS_H char * getRealName(); int age(); #endif //NATIVETEST_OTHERS_H
//
// Created by minwenping on 2021/12/23.
//
#include "others.h"
char * getRealName(){
return "this is the world!";
}
int age(){
return 99;
}
我看了主要的问题都是编译问题,而编译问题的产生都是因为引用不到第三方so。那么so放置的位置有两种:
放在这个位置的时候,build.gradle 的配置如下:
那么它的CMake的配置方式就和其他的位置差不多
在本地工程cpp文件中使用
#include#include #include "include/others.h" extern "C" JNIEXPORT jstring JNICALL Java_com_wenping_nativeso_MainActivity_stringFromJNI( JNIEnv* env, jobject ) { std::string hello = "Hello from C++"; std::string result =getRealName(); return env->NewStringUTF(result.c_str()); } extern "C" JNIEXPORT jint JNICALL Java_com_wenping_nativeso_MainActivity_getNumber(JNIEnv *env, jobject thiz) { return age(); }



