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可以看到如下显示结果:




  • 2019-11-09 19:16:35

    java标记过期方法

    java注解:@Deprecated(不建议使用的,废弃的);@SuppressWarnings(忽略警告,达到抑制编译器产生警告的目的)

  • 2019-11-12 02:56:39

    使用.htaccess重定向后无法显示图片,CSS失效,该如何处理

    现在我需要把这个域名泛解析到blog目录(*.mydomain.org),同时保持另外两个目录的解析不变。尝试对最后一段作以下修改后(前面的内容不变),出现问题:另两个目录中的网站内的图片无法显示,CSS全部失效。

  • 2019-11-14 11:21:34

    vue中的this指向问题

    ※ 对于普通函数(包括匿名函数),this指的是直接的调用者,在非严格模式下,如果没有直接调用者,this指的是window。showMessage1()里setTimeout使用了匿名函数,this指向 window。 ※ 箭头函数是没有自己的this,在它内部使用的this是由它定义的宿主对象决定。showMessage2()里定义的箭头函数宿主对象为vue实例,所以它里面使用的this指向vue实例。

  • 2019-11-18 23:18:49

    spring boot中读取配置信息一

    首先我们都知道一个常识,那就是每个人都有自己的年龄,比如我们现在的业务需求是查询所有年龄大于20的人的相关信息,如果我们选择通过配置文件来配置这个值为20的常量的话,我们该如何配置和如何从配置文件中获取这个值呢?,application.yml的内容如下(注意 “age:“ 和 “20“ 之间需要一个空格,yml的语法 ):