将现有的jni库(已编译为".so")添加到另一个android studio项目中 [英] adding existing jni libraries (already compiled ".so") to another android studio project
问题描述
我还没有找到能够在线回答我的特定问题的人.我有一个旧的Android项目,我想从其中复制一些.so库并将其粘贴到新项目中.我对这些东西不熟悉,我知道我需要告诉新程序在哪里可以找到这些库,但是我不知道是否应该使用CMake或NDK导入alreay编译的代码.这是我的目录的样子:
I haven't found anyone who has been able to answer my specific question online. I have an old Android project that I want to copy some .so libraries from and paste them into a new project. I'm new to this stuff and I know I need to tell my new program where to find these libraries but I don't know if I should be using CMake or NDK to import alreay compiled code. This is what my directory looks like:
我在程序中这样调用该库:
I call for this library in my program like this:
static {
System.loadLibrary("serial_port");
}
但是我如何告诉编译器在哪里可以找到这些复制和粘贴的文件?
But how do I tell the compiler where to find these copied and pasted files?
我基于Android的文档启动了一个文件但是我对一些事情感到困惑.这是我到目前为止的内容:
I started a file based on the documentation from Android but I'm confused about a few things. This is what I have so far:
# 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 )
我认为我做的不对.请看一下并指出正确的方向.谢谢
I don't think I'm doing it right. Please take a look and point me in the right direction. Thanks
推荐答案
您需要将它们保留在各自文件夹的目录jniLibs
中.
You need to keep them inside the dir jniLibs
in their respective folders.
例如
/app/src/main/jniLibs/armeabi/libserial_port.so
/app/src/main/jniLibs/armeabi/libserial_port.so
您无需使用任何其他工具(例如CMake)即可使用它们.您可以直接加载它们.
And you don't need to use any other tools like CMake to use them. You can directly load them.
这篇关于将现有的jni库(已编译为".so")添加到另一个android studio项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!