CMAKE:建筑.dylib测试Android Junit测试

发布于 2025-01-28 15:36:02 字数 1460 浏览 3 评论 0原文

我正在使用c ++使用cmake构建的代码从事Android Native项目。当前,我的应用程序运行良好,本机LIB(.so)已使用System.loadLibrary()成功加载。

但是我想在我的Mac上测试junitAndroid 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文