Android下openssl编译和使用(二)

2019-08-30 21:59:20

接下来我们看看如何使用


1、新建一个测试工程,并勾选include C++ support


2、把openssl-1.1.1b/include下的openssl目录,整个复制到项目src下的cpp子目录


3、把lib下的libcryto.a和libssl.a复制到src/cpp/libs子目录




4、修改CMakeList.txt文件,在cmake_minimum_required(VERSION 3.4.1)后面添加:


#表示把src/main/cpp加入到include目录,这样在代码中使用:#include <...>就能访问到头文件

include_directories(src/main/cpp)

 

#添加两个预编译库

add_library(# Sets the name of the library.

        openssl-crypto

        # Sets the library as a static library.

        STATIC

        IMPORTED)

 

set_target_properties(

        # Specifies the target library.

        openssl-crypto

        # Specifies the parameter you want to define.

        PROPERTIES IMPORTED_LOCATION

        # Provides the path to the library you want to import.

        ${CMAKE_SOURCE_DIR}/src/main/cpp/libs/${ANDROID_ABI}/libcrypto.a)

 

add_library(# Sets the name of the library.

        openssl-ssl

        # Sets the library as a static library.

        STATIC

        IMPORTED)

 

set_target_properties(

        # Specifies the target library.

        openssl-ssl

        # Specifies the parameter you want to define.

        PROPERTIES IMPORTED_LOCATION

        # Provides the path to the library you want to import.

        ${CMAKE_SOURCE_DIR}/src/main/cpp/libs/${ANDROID_ABI}/libssl.a)

5、修改CMakeList.txt文件最后的target_link_libraries如下:


target_link_libraries( # Specifies the target library.

        native-lib

 

        # Links the target library to the log library

        # included in the NDK.

        ${log-lib} openssl-ssl openssl-crypto)

6、修改native-lib.cpp返回openssl版本信息




7、启动app可以看到如下显示结果:




  • 2017-03-13 12:07:19

    JavaScript原型与原型链分析

    JavaScript没有类的概念,但几乎所有的东西又是基于对象的,同时也能实现继承,这就是js跟其他OOP语言最大的不同之处,这也是js最难理解的一块。下面我来说说我个人的理解。

  • 2017-03-15 07:43:19

    NodeJS服务器”热部署“代码,实现动态调试

    如果你有 PHP 开发经验,会习惯在修改 PHP 脚本后直接刷新浏览器以观察结果,而你在开发 Node.js 实现的 HTTP 应用时会发现,无论你修改了代码的哪一部份,都必须终止Node.js 再重新运行才会奏效。这是因为 Node.js 只有在第一次引用到某部份时才会去解析脚本文件,以后都会直接访问内存,避免重复载入,而 PHP 则总是重新读取并解析脚本(如果没有专门的优化配置)。

  • 2017-03-16 13:37:58

    mysql中如何使用INSERT一次性插入多条记录

    看到这个标题也许大家会问,这有什么好说的,调用多次INSERT语句不就可以插入多条记录了吗!但使用这种方法要增加服务器的负荷,因为,执行每一次 SQL服务器都要同样对SQL进行分析、优化等操作。