gpt4 book ai didi

java - Android Studio 重命名原生库

转载 作者:搜寻专家 更新时间:2023-11-01 08:31:45 25 4
gpt4 key购买 nike

我已经创建了一个支持 C++ 和一个库模块的 Android Studio 项目。名为 native-lib.cpp 的 C++ 文件自动添加到我的项目中。当我现在构建项目时,*.so 文件的输出名称是 libnative-lib.so

如果我将 native-lib.cpp 重命名为其他名称(使用重构/重命名功能),C++ 文件就会从我的项目中消失,直到我改回名称。

那么我该如何重命名我的原生库,或者设置输出文件的名称呢?

最佳答案

很高兴您能解决这个问题。无论如何,我都会在这里发布答案以供引用。

CMakeLists.txt <<= 应该在您的应用模块的根目录中 (my_project/app/CMakeLists.txt)

# https://developer.android.com/studio/projects/add-native-code.html#create-cmake-script


# Minimum version of CMake
cmake_minimum_required(VERSION 3.4.1)


# adding CEC library
# add_library structure: add_library(lib_name lib_type_STATIC_or_SHARED source_file_path)
add_library(my_lib_name SHARED src/main/jni/my_cpp_file.cpp)


# include_directories is to provide the path to you native lib code
# include_directories structure: include_directories(native_lib_folder_path)
include_directories(src/main/jni/)


# adding Android log library
# find_library is used to find NDK API libraries (built in NDK libs)
# find_library structure: find_library(name_you_want_to_call_the_lib lib_name_in_ndk_api)
find_library(log-lib log)


# linking log lib to our native lib
# once you find the library, you have to link that library with your native library
# target_link_libraries structure: target_link_libraries(you_native_lib lib_found_using_find_library)
target_link_libraries(my_lib_name ${log-lib})

然后在build.gradle中,执行以下操作

externalNativeBuild {
cmake {
path 'CMakeLists.txt'
}
}

然后,使用“构建”菜单中提供的选项彻底清理、刷新 C++ 项目。

就像@bitwise 发布的那样,如果必须,请删除 build.externalNativeBuild 文件夹的内容并重建项目。

关于java - Android Studio 重命名原生库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39964921/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com