Я использую эту библиотеку в своем приложении для Android в качестве библиотеки http для отправки запросов https. cpp/CMakeLists.txt
содержимое:
cmake_minimum_required(VERSION 3.4.1)
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).
native-lib.cpp)
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)
add_library(
curl
SHARED
IMPORTED
)
set_target_properties(
curl
PROPERTIES IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/curl-android-ios/prebuilt-with-ssl/android/${ANDROID_ABI}/libcurl.a
)
include_directories(
${CMAKE_SOURCE_DIR}/curl-android-ios/prebuilt-with-ssl/android/include/
)
find_library(
zlib
z
)
message("***********************" ${zlib})
target_link_libraries( # Specifies the target library.
native-lib
curl
z
# Links the target library to the log library
# included in the NDK.
${log-lib})
И это мой cpp /Файл native-lib.cpp. Код взят со страницы примера libcurl :
#include <jni.h>
#include <string>
#include <curl/curl.h>
#include <stdio.h>
#include <iostream>
#include <android/log.h>
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "native-lib", __VA_ARGS__))
size_t WriteCallback(char *contents, size_t size, size_t nmemb, void *userp)
{
((std::string*)userp)->append((char*)contents, size * nmemb);
return size * nmemb;
}
extern "C" JNIEXPORT jstring JNICALL
Java_com_example_libcurltest_MainActivity_stringFromJNI(
JNIEnv *env,
jobject /* this */) {
curl_global_init(CURL_GLOBAL_ALL);
CURL* easyhandle = curl_easy_init();
std::string readBuffer;
curl_easy_setopt(easyhandle, CURLOPT_URL, "https://google.com");
curl_easy_setopt(easyhandle, CURLOPT_VERBOSE, 1L);
// curl_easy_setopt(easyhandle, CURLOPT_PROXY, "http://my.proxy.net"); // replace with your actual proxy
// curl_easy_setopt(easyhandle, CURLOPT_PROXYPORT, 8080L);
curl_easy_setopt(easyhandle, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(easyhandle, CURLOPT_WRITEDATA, &readBuffer);
curl_easy_perform(easyhandle);
__android_log_print(ANDROID_LOG_DEBUG, "LOG_TAG", "\n this is log messge \n");
// std::cout << readBuffer << std::endl;
std::string result = "here: " + readBuffer;
std::string hello = "hello";
return env->NewStringUTF(result.c_str());
}
Но в текстовом представлении в Android ничего не отображается. Не могли бы вы помочь мне исправить это? Есть ли проблемы с тем, как я написал cmake или код, который я использую для отправки запроса https?