如何在Android项目中导入静态库?
我目前正在尝试在 Android 项目中导入一个非常简单的 C++ 静态库。
静态库项目如下所示:
我设法生成库并找到每个配置的 .a
文件 (arm64-v8a
, armeabi-v7a
、x86
、x86_64
)。
现在我尝试将其导入到 Android 项目中,这就是我所做的:
在
src/main/cpp/jucedemo/lib
中,我添加了 4 个目录 (arm64-v8a
、armeabi-v7a
、x86
、x86_64
),以及我的不同版本每个目录中的libJuceDemo.a
然后我尝试从 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:
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 mylibJuceDemo.a
in each directoryI also added a
include
directory withJuceTest.h
in it, as you can see here:
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 theJuceTest.h
header like this:
#include "jucedemo/lib/include/JuceTest.h
- In that same file (
native-lib.cpp
), in a function, I try to use theJuceTest
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论