Android jni调用第三方so库和.h文件

Android利用cmake调用第三方so库配合.h文件,进行so库第二次封装

1.将第三方库复制至JniLibs目录下

在这里插入图片描述

2.将头文件复制head目录下
3.在cmake目录下添加第三方库
cmake_minimum_required(VERSION 3.4.1)

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.

add_library( # Sets the name of the library.
        native-lib

        # Sets the library as a shared library.
        SHARED

        # Provides a relative path to your source file(s).
        src/main/cpp/native-lib.cpp)
# 添加第三方库
add_library(cp
        SHARED
        IMPORTED)
# 配置第三方库链接
set_target_properties(
        cp
        PROPERTIES
        IMPORTED_LOCATION
        ${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libcp.so)
# 添加头文件
include_directories(${CMAKE_SOURCE_DIR}/src/main/head)

# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

find_library( # Sets the name of the path variable.
        log-lib

        # Specifies the name of the NDK library that
        # you want CMake to locate.
        log)

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( # Specifies the target library.
        native-lib
        cp//第三方库
        # Links the target library to the log library
        # included in the NDK.
        ${log-lib})
4.导入第三方库头文件,进行方法调用即可

![在这里插入图片描述](https://img-blog.csdnimg.cn/20200120110724486.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NpbmF0XzM4ODkyOTYw,size_16,color_FFFFFF,t_70

上一篇:Android ndk利用android.mk生成so库

  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Qt for Android中,调用第三方可以通过以下步骤实现: 1. 将第三方文件(通常是一个文件或者是一个.so文件)添加到Qt项目的目录中,可以放在项目的根目录下或者是一个单独的文件夹中。 2. 在项目的.pro文件中添加文件的路径和依赖项。可以通过使用LIBS参数来指定文件路径,例如:LIBS += -L/path/to/library -lmylibrary。另外,如果文件有依赖文件,可以使用DEPLOYMENT参数指定依赖文件的路径,例如:DEPLOYMENT += path/to/dependency。 3. 在Qt代码中引用第三方。使用#include指令将的头文件引入到Qt代码中,例如:#include <mylibrary.h>。然后就可以使用中提供的函数和类了。 需要注意的是,调用第三方时,需要确保文件的兼容性和正确性。特别是在使用跨平台的时,需要检查是否支持Android平台,并且要确保所使用的文件与Qt版本和Android NDK版本兼容。 此外,Qt for Android还提供了JNI(Java Native Interface)的支持,可以通过JNI调用Java代码和使用Java。这种方式可以更深入地与Android系统交互,并且能够访问更多的Android API和功能。 总而言之,Qt for Android调用第三方需要将文件添加到项目中,并在项目配置文件中设置路径和依赖项。然后使用#include指令引入的头文件,并通过提供的函数和类来使用第三方的功能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值