http://my.oschina.net/zhoulc/blog/111929
http://blog.csdn.net/vrix/article/details/7683212先贴一个博文,不过没成功。。。。
利用源码编译的 : http://www.tmy13.com/?p=24
加openssl编译的: http://piggyq.com/pen/compile-libcurl-and-openssl-on-android-using-ndk.html
——————————————————————————————————
参考:终于编译成功curl,里面有上篇文章的摘要。
其实就是缺少.configure出的配置文件,但是该文件是通用的,可以提供下载:Here
里面有具体编译方法的说明,这里不具体再细讲了,这不过不是使用ndk-builder,而是ndk-builder.cmd。
测试的话,使用eclipse建立Android工程:
1.新建Android application project,名称叫:curltest,命名空间是:package com.mtterra.curltest,入口Activity是curltest,布局文件是main.xml。
2.把上面压缩包里面的curltest.java拷贝到src,main.xml拷贝到layout,libcurltest.so拷贝到libs\armeabi,jni拷贝到项目root下,
3 AndroidManifest.xml添加访问网络的权限:
<uses-permission android:name=”android.permission.INTERNET”/>
APP_PROJECT_PATH := $(call my-dir)/project
APP_MODULES := curljni libcurl
LOCAL_PATH:= $(call my-dir) CFLAGS := -Wpointer-arith -Wwrite-strings -Wunused -Winline \ -Wnested-externs -Wmissing-declarations -Wmissing-prototypes -Wno-long-long \ -Wfloat-equal -Wno-multichar -Wsign-compare -Wno-format-nonliteral \ -Wendif-labels -Wstrict-prototypes -Wdeclaration-after-statement \ -Wno-system-headers -DHAVE_CONFIG_H include $(CLEAR_VARS) include $(LOCAL_PATH)/curl/lib/Makefile.inc LOCAL_SRC_FILES := $(addprefix curl/lib/,$(CSOURCES)) LOCAL_CFLAGS += $(CFLAGS) LOCAL_C_INCLUDES += $(LOCAL_PATH)/curl/include/ $(LOCAL_PATH)/curl/lib LOCAL_COPY_HEADERS_TO := libcurl LOCAL_COPY_HEADERS := $(addprefix curl/include/curl/,$(HHEADERS)) LOCAL_MODULE:= libcurl include $(BUILD_STATIC_LIBRARY) # Build shared library now # curltest include $(CLEAR_VARS) LOCAL_MODULE := curljni LOCAL_SRC_FILES := curljni.c LOCAL_STATIC_LIBRARIES := libcurl LOCAL_C_INCLUDES += $(LOCAL_PATH)/curl/include $(LOCAL_PATH)/curl/lib include $(BUILD_SHARED_LIBRARY)
//curljni.c
#include <string.h> #include <jni.h> #include <stdio.h> #include <stdlib.h> #include "curl_config.h" #include "curl/curl.h" typedef struct pageInfo_t { char *data; int len; } pageInfo_t; static size_t HTTPData(void *buffer, size_t size, size_t nmemb, void *userData) { int len = size * nmemb; pageInfo_t *page = (pageInfo_t *)userData; if (buffer && page->data && (page->len + len < (16 * 1024)) ) { memcpy(&page->data[page->len], buffer, len); page->len += len; } return len; } //Inteface funciton that will recieve web page fom Java jstring Java_com_curljni_curljni_JNIGetWebpage( JNIEnv* env, jobject entryObject, jstring webpageJStr ) { pageInfo_t page; CURL *curl; CURLcode res; char *buffer; const jbyte *webpage; webpage = (*env)->GetStringUTFChars(env, webpageJStr, NULL); if (webpage == NULL) { return NULL; /* OutOfMemoryError already thrown */ } page.data = (char *)malloc(16 * 1024); page.len = 0; if (page.data) memset(page.data, 32, 16 * 1024); buffer = (char *)malloc(1024); curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, webpage); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, HTTPData); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &page); res = curl_easy_perform(curl); /* always cleanup */ curl_easy_cleanup(curl); (*env)->ReleaseStringUTFChars(env, webpageJStr, webpage); if(res == 0) { if (buffer) { page.data[page.len < 256 ? page.len : 256] = '\0'; sprintf(buffer, "pagedata(%d): %s. done.\n", page.len, page.data); return (*env)->NewStringUTF(env, buffer); } } sprintf(buffer, "Result error:%d", res); return (*env)->NewStringUTF(env, buffer); } else { return (*env)->NewStringUTF(env, "Unable to init cURL"); } }
4 在android-ndk目录中 执行 make APP=curljni -B
在project/libs/armeabi/生成 libcurljni.so 文件。
5 建立测试工程的时候注意命名。android:name="com.curljni.curljni"