CMAKE:建筑.dylib测试Android Junit测试
我正在使用c ++
使用cmake
构建的代码从事Android Native项目。当前,我的应用程序运行良好,本机LIB(.so
)已使用System.loadLibrary()
成功加载。
但是我想在我的Mac上测试junit
在Android Studio
中测试。在Mac上运行测试时,它会引发错误,
myapp.dylib not found.
这是我的cmakelists.txt:
cmake_minimum_required(VERSION 3.18.1)
# Declares and names the project.
project("myapplication")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
add_library( # Sets the name of the library.
myapplication
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
native-lib.cpp
native2.cpp)
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log)
这是我的cpp文件:
#include <jni.h>
#include <string>
#include "header.h"
#include<android/log.h>
extern "C" JNIEXPORT jstring JNICALL
Java_com_example_myapplication_MainActivity_stringFromJNI(
JNIEnv* env,
jobject /* this */) {
return env->NewStringUTF(hello.c_str());
}
要构建.dylib
在运行cmake
从命令行中找不到和liblog(android日志库)之类的错误
。
有什么方法可以使Mac OS构建.dylib
,以便可以解决诸如JNI和Log Librage之类的Android特定依赖关系?
I am working on Android native project using C++
code built using CMake
. Currently my app is running fine and native lib(.so
) is successfully loaded using System.loadLibrary()
.
But I want to test JUnit
tests on my mac in Android Studio
. When running tests on mac, It throws error
myapp.dylib not found.
Here is my CMakeLists.txt :
cmake_minimum_required(VERSION 3.18.1)
# Declares and names the project.
project("myapplication")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
add_library( # Sets the name of the library.
myapplication
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
native-lib.cpp
native2.cpp)
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log)
Here is my cpp file:
#include <jni.h>
#include <string>
#include "header.h"
#include<android/log.h>
extern "C" JNIEXPORT jstring JNICALL
Java_com_example_myapplication_MainActivity_stringFromJNI(
JNIEnv* env,
jobject /* this */) {
return env->NewStringUTF(hello.c_str());
}
To build .dylib
when running cmake
from command line, I get other errors like jni not found
and liblog(android log library) not found
.
Is there a way that I can build .dylib
for mac OS in such a way that it can resolve android specific dependencies like jni and log library?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论