1、编译使用到https的时候需要连接openssl库,--with-openssl=PATH 这里的路径为编译openssl库后使用make install安装后的路径,不能手动将库和头文件拷贝到某个目录然后指定该路径,这样是无法识别的
Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
--with-schannel enable Windows native SSL/TLS
--with-secure-transport enable Apple OS native SSL/TLS
--with-amissl enable Amiga native SSL/TLS (AmiSSL)
--with-ssl=PATH old version of --with-openssl
--without-ssl build without any TLS library
--with-openssl=PATH Where to look for OpenSSL, PATH points to the SSL
installation (default: /usr/local/ssl); when
possible, set the PKG_CONFIG_PATH environment
variable instead of using this option
2、静态库编译成功后添加到androidStudio进行编译,如果出现以下问题,需要指定androidStudio的默认API Level,如果你用NDK编译的Level大于或等于21,但androidStudio使用的默认Level小于21,会出现以下问题:
cmd.exe /C "cd . && D:\AndroidStudio\SDK\ndk\21.1.6352462\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=armv7-none-linux-androideabi16 --gcc-toolchain=D:/AndroidStudio/SDK/ndk/21.1.6352462/toolchains/llvm/prebuilt/windows-x86_64 ......"
D:/androidStudio_prj/backup/FOTA_20211215/app/src/main/cpp/../jniLibs/armeabi-v7a/libcurl.a(libcurl_la-multi.o):multi.c:function curl_multi_fdset: error: undefined reference to '__FD_SET_chk'
D:/androidStudio_prj/backup/FOTA_20211215/app/src/main/cpp/../jniLibs/armeabi-v7a/libcurl.a(libcurl_la-multi.o):multi.c:function curl_multi_fdset: error: undefined reference to '__FD_SET_chk'
我们看到在21 版本NDK里面的select.h头文件中有这样一段代码,API版本大于或等于21会有__FD_SET_chk接口定义
/* Inline loop so we don't have to declare memset. */
#define FD_ZERO(set) \
do { \
size_t __i; \
for (__i = 0; __i < sizeof(fd_set)/sizeof(fd_mask); ++__i) { \
(set)->fds_bits[__i] = 0; \
} \
} while (0)
#if __ANDROID_API__ >= 21
void __FD_CLR_chk(int, fd_set*, size_t) __INTRODUCED_IN(21);
void __FD_SET_chk(int, fd_set*, size_t) __INTRODUCED_IN(21);
int __FD_ISSET_chk(int, const fd_set*, size_t) __INTRODUCED_IN(21);
#endif /* __ANDROID_API__ >= 21 */
#define __FD_CLR(fd, set) (__FDS_BITS(fd_set*,set)[__FDELT(fd)] &= ~__FDMASK(fd))
#define __FD_SET(fd, set) (__FDS_BITS(fd_set*,set)[__FDELT(fd)] |= __FDMASK(fd))
#define __FD_ISSET(fd, set) ((__FDS_BITS(const fd_set*,set)[__FDELT(fd)] & __FDMASK(fd)) != 0)
修改默认API LEVEL的方法,在build.gradle中将minSdk 改成21
android { compileSdkVersion 30 buildToolsVersion "30.0.3" defaultConfig { applicationId "com.example.fota" //minSdk 16 minSdk 21 targetSdk 30 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" externalNativeBuild { cmake { cppFlags '' abiFilters 'arm64-v8a', 'armeabi-v7a' } } }
}