如何在Android项目中导入静态库?

发布于 2025-01-10 02:22:28 字数 1973 浏览 1 评论 0原文

我目前正在尝试在 Android 项目中导入一个非常简单的 C++ 静态库。

静态库项目如下所示:

静态库项目

我设法生成库并找到每个配置的 .a 文件 (arm64-v8a , armeabi-v7ax86x86_64)。

现在我尝试将其导入到 Android 项目中,这就是我所做的:

  • src/main/cpp/jucedemo/lib 中,我添加了 4 个目录 (arm64-v8aarmeabi-v7ax86x86_64 ),以及我的不同版本每个目录中的libJuceDemo.a

  • 我还添加了include 目录,其中包含 JuceTest.h,如下所示: C++ 静态Android项目中的库

  • 我在 CMakeLists.txt 文件中添加了以下内容: CMakeLists. txt内容

然后我尝试从 Android 应用程序的 JNI (C++) 代码中调用库的代码:

  • 在我的 Android 项目的另一个 C++ 文件中 (native-lib.cpp), 我像这样导入 JuceTest.h 标头:
#include "jucedemo/lib/include/JuceTest.h
  • 在同一个文件 (native-lib.cpp) 中,在函数中,我尝试使用 JuceTest class:
jucetest::JuceTest juceTest;
juceTest.getTexte();

现在,当我尝试编译并运行我的 Android 应用程序时,我收到以下错误:

error: undefined reference to 'jucetest::JuceTest::JuceTest()'
error: undefined reference to 'jucetest::JuceTest::getTexte()'
error: undefined reference to 'jucetest::JuceTest::~JuceTest()'

我相信 include 中的 JuceTest.h 头文件的内容有问题 目录,但我找不到它是什么 是。

另外,这里是用于编译库的 CMakeLists.txt

我应该更改什么才能从 Android 应用程序的 JNI 代码调用我的库代码?

感谢您的帮助。

I'm currently trying to import a very simple C++ static library in an Android project.

Here is what the static library project looks like:

Static library project

I managed to generate the library and locate the .a files for each configuration (arm64-v8a, armeabi-v7a, x86, x86_64).

Now I'm trying to import it on an Android project, and here is what I did:

  • in src/main/cpp/jucedemo/lib , I added the 4 directories (arm64-v8a , armeabi-v7a , x86 , x86_64), with the different versions of my libJuceDemo.a in each directory

  • I also added a include directory with JuceTest.h in it, as you can see here:
    C++ static library in Android project

  • I added the following in my CMakeLists.txt file:
    CMakeLists.txt content

Then I tried to call the code of the library from my JNI (C++) code of my Android app:

  • In another C++ file of my Android project (native-lib.cpp), I import the JuceTest.h header like this:
#include "jucedemo/lib/include/JuceTest.h
  • In that same file (native-lib.cpp), in a function, I try to use the JuceTest class:
jucetest::JuceTest juceTest;
juceTest.getTexte();

Now when I try to compile and run my Android app, I get these errors:

error: undefined reference to 'jucetest::JuceTest::JuceTest()'
error: undefined reference to 'jucetest::JuceTest::getTexte()'
error: undefined reference to 'jucetest::JuceTest::~JuceTest()'

I believe there is something wrong with the content of the JuceTest.h header file in the include directory, but I can't find what it is.

Also, here is the CMakeLists.txt used to compile the library.

What should I change so I can call my library code from the JNI code of my Android app?

Thanks for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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