6 c++ java java-native-interface android android-ndk
我没有找到任何能够在线回答我的具体问题的人.我有一个旧的Android项目,我想复制一些.so库并将它们粘贴到一个新项目中.我是新手,我知道我需要告诉我的新程序在哪里找到这些库,但我不知道我是否应该使用CMake或NDK来导入alreay编译的代码.这是我的目录:
我在我的程序中调用这个库,如下所示:
static {
System.loadLibrary("serial_port");
}
Run Code Online (Sandbox Code Playgroud)
但是,如何告诉编译器在哪里找到这些复制和粘贴的文件?
我根据Android 的文档创建了一个文件,但我对一些事情感到困惑.这是我到目前为止:
# Sets the minimum version of CMake required to build your native library.
# This ensures that a certain set of CMake features is available to
# your build.
cmake_minimum_required(VERSION 3.4.1)
# Specifies a library name, specifies whether the library is STATIC or
# SHARED, and provides relative paths to the source code. You can
# define multiple libraries by adding multiple add.library() commands,
# and CMake builds them for you. When you build your app, Gradle
# automatically packages shared libraries with your APK.
add_library( # Specifies the name of the library.
serial_port
# Sets the library as a shared library.
SHARED
IMPORTED
serial_port/src/${ANDROID_ABI}/libserial_port.so
# Provides a relative path to your source file(s).
src/main/cpp/libs/armeabi/libserial_port.so )
Run Code Online (Sandbox Code Playgroud)
我不认为我做得对.请看一看并指出我正确的方向.谢谢
您需要将它们保存jniLibs在各自文件夹中的目录中。
例如。
/app/src/main/jniLibs/armeabi/libserial_port.so
而且您不需要使用任何其他工具(如 CMake)来使用它们。您可以直接加载它们。
| 归档时间: |
|
| 查看次数: |
1557 次 |
| 最近记录: |