开发者社区> 问答> 正文

android-找不到libcurl.so这个so文件

android-找不到libcurl.so这个so文件

展开
收起
健东 2018-11-16 10:13:51 4258 0
2 条回答
写回答
取消 提交回答
  • 接一个你们sdk还有写这些?

    2019-07-17 23:14:55
    赞同 展开评论 打赏
  • java 数据分析 数据可视化 大数据

    一.移植Curl工具到Android环境步骤
    1.修改cURL源码下的mk文件。源码下面的Android.mk文件最后生成的是静态库libcurl.a,做如下修改(编译成动态库)。
    LOCAL_PRELINK_MODULE := false

    LOCAL_MODULE:= libcurl

    LOCAL_MODULE_TAGS := optional

    Copy the licence to a place where Android will find it.

    Actually, this doesn't quite work because the build system searches

    for NOTICE files before it gets to this point, so it will only be seen

    on subsequent builds.

    ALL_PREBUILT += $(LOCAL_PATH)/NOTICE

    $(LOCAL_PATH)/NOTICE: $(LOCAL_PATH)/COPYING | $(ACP)

    $(copy-file-to-target)

    include $(BUILD_STATIC_LIBRARY)

    include $(BUILD_SHARED_LIBRARY)

    2.配置编译环境(cd 到Android.mk同一目录,直接在控制台输入下列代码或者把下面代码弄成sh脚本执行)红色部分根据自己源码情况
    ANDROID_HOME=/home/zhoulc/android/ && \

    NDK_HOME=/home/zhoulc/android/ndk && \

    PATH="$ANDROID_HOME/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin:$PATH" \

    ./configure --host=arm-linux CC=arm-eabi-gcc --with-random=/dev/urandom \

    CPPFLAGS="-I$NDK_HOME/platforms/android-8/arch-arm/usr/include \

    -I $ANDROID_HOME/external/curl/include/ \

    -I $ANDROID_HOME/external/curl/3rd/include \

    -I $ANDROID_HOME/external/curl \

    -I $ANDROID_HOME/out/target/product/generic/obj/STATIC_LIBRARIES/libcurl_intermediates \

    -I $ANDROID_HOME/dalvik/libnativehelper/include/nativehelper \

    -I $ANDROID_HOME/system/core/include \

    -I $ANDROID_HOME/hardware/libhardware/include \

    -I $ANDROID_HOME/hardware/libhardware_legacy/include \

    -I $ANDROID_HOME/hardware/ril/include \

    -I $ANDROID_HOME/dalvik/libnativehelper/include \

    -I $ANDROID_HOME/frameworks/base/include \

    -I $ANDROID_HOME/frameworks/base/opengl/include \

    -I $ANDROID_HOME/frameworks/base/native/include \

    -I $ANDROID_HOME/external/skia/include \

    -I $ANDROID_HOME/out/target/product/generic/obj/include \

    -I $ANDROID_HOME/bionic/libc/arch-arm/include \

    -I $ANDROID_HOME/bionic/libc/include \

    -I $ANDROID_HOME/bionic/libstdc++/include \

    -I $ANDROID_HOME/bionic/libc/kernel/common \

    -I $ANDROID_HOME/bionic/libc/kernel/arch-arm \

    -I $ANDROID_HOME/bionic/libm/include \

    -I $ANDROID_HOME/bionic/libm/include/arch/arm \

    -I $ANDROID_HOME/bionic/libthread_db/include \

    -include $ANDROID_HOME/system/core/include/arch/linux-arm/AndroidConfig.h \

    -I $ANDROID_HOME/system/core/include/arch/linux-arm/ \

    -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -DANDROID -DNDEBUG -DNDEBUG -DHAVE_CONFIG_H" \

    CFLAGS="-fno-exceptions -Wno-multichar -msoft-float -fpic -ffunction-sections \

    -funwind-tables -fstack-protector -Wa,--noexecstack -Werror=format-security \

    -fno-short-enums -march=armv5te -mtune=xscale -Wno-psabi -mthumb-interwork \

    -fmessage-length=0 -W -Wall -Wno-unused -Winit-self -Wpointer-arith \

    -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point \

    -g -Wstrict-aliasing=2 -finline-functions -fno-inline-functions-called-once \

    -fgcse-after-reload -frerun-cse-after-loop -frename-registers -UDEBUG \

    -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 \

    -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" \

    LIBS="-nostdlib -Bdynamic -Wl,-T,$ANDROID_HOME/build/core/armelf.x \

    -Wl,-dynamic-linker,/system/bin/linker -Wl,--gc-sections -Wl,-z,nocopyreloc \

    -L$ANDROID_HOME/out/target/product/generic/obj/lib -Wl,-z,noexecstack \

    -Wl,-rpath-link=$ANDROID_HOME/out/target/product/generic/obj/lib \

    -lc -llog -lcutils -lstdc++ \

    -Wl,--no-undefined $ANDROID_HOME/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/lib/gcc/arm-eabi/4.4.0/libgcc.a \

    $ANDROID_HOME/out/target/product/generic/obj/lib/crtend_android.o \

    -lm $ANDROID_HOME/out/target/product/generic/obj/lib/crtbegin_dynamic.o \

    -L$ANDROID_HOME/external/curl/3rd/libs"
    3.编译libcurl.so库
    cd进入android/external/curl源码目录

    mm-》编译生成libcurl.so库

    4.编写测试case 以及Android.mk文件并生成可执行文件
    新建一个测试案例curl_test.cpp

    include "curl/curl.h"

    include ;

    int main() {

    CURL *curl; 
    
    CURLcode res;
    
    curl_global_init(CURL_GLOBAL_ALL);
    
    curl = curl_easy_init();
    
    if (curl) {     
    
        curl_easy_setopt(curl, CURLOPT_URL, "http://www.baidu.com/"); 
    
        res = curl_easy_perform(curl); 
    
        if (0!=res) {      
    
            printf("curl error: %d\n", res);         
    
        }        
    
        curl_easy_cleanup(curl);     
    
    }   
    
    curl_global_cleanup();
    
    return 0;
    

    }
    在同一目录下写一个Android.mk文件生成curl_test可执行文件

    LOCAL_PATH := $(call my-dir)

    include $(CLEAR_VARS)

    LOCAL_C_INCLUDES += \

    $(TOP)/external/curl/include/ \
    

    LOCAL_SRC_FILES:= curl_test.cpp

    No shared libraries.

    No static libraries.

    LOCAL_SHARED_LIBRARIES := libcurl

    LOCAL_MODULE_TAGS := optional

    LOCAL_MODULE := curl_test

    include $(BUILD_EXECUTABLE)

    生成可执行文件:curl_test

    4.运行查看测试结果
    运行测试case:curl_test

    5.(补充)移植libcurl到android4.0,修改两个地方
    1)把生成的路径改一下,一般默认为out/target/product/generic下面,我们根据系统不同(根据lunch选择不同,最终生成的路径不一样)改为系统的全局变量,

    把$ANDROID_HOME/out/target/product/generic替换成$ANDROID_PRODUCT_OUT。

    ANDROID_HOME_CURL=../../ && \

    NDK_HOME_CURL=../../prebuilt/ndk && \

    PATH="$ANDROID_HOME_CURL/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin:$PATH" \

    ./configure --host=arm-linux CC=gcc --with-random=/dev/urandom \

    CPPFLAGS="-I$NDK_HOME_CURL/platforms/android-8/arch-arm/usr/include \

    -I $ANDROID_HOME_CURL/external/curl/include/ \

    -I $ANDROID_HOME_CURL/external/curl/3rd/include \

    -I $ANDROID_HOME_CURL/external/curl \

    -I $ANDROID_HOME_CURL/out/target/product/generic/obj/STATIC_LIBRARIES/libcurl_intermediates \

    -I $ANDROID_HOME_CURL/dalvik/libnativehelper/include/nativehelper \

    -I $ANDROID_HOME_CURL/system/core/include \

    -I $ANDROID_HOME_CURL/hardware/libhardware/include \

    -I $ANDROID_HOME_CURL/hardware/libhardware_legacy/include \

    -I $ANDROID_HOME_CURL/hardware/ril/include \

    -I $ANDROID_HOME_CURL/dalvik/libnativehelper/include \

    -I $ANDROID_HOME_CURL/frameworks/base/include \

    -I $ANDROID_HOME_CURL/frameworks/base/opengl/include \

    -I $ANDROID_HOME_CURL/frameworks/base/native/include \

    -I $ANDROID_HOME_CURL/external/skia/include \

    -I $ANDROID_HOME_CURL/out/target/product/generic/obj/include \

    -I $ANDROID_HOME_CURL/bionic/libc/arch-arm/include \

    -I $ANDROID_HOME_CURL/bionic/libc/include \

    -I $ANDROID_HOME_CURL/bionic/libstdc++/include \

    -I $ANDROID_HOME_CURL/bionic/libc/kernel/common \

    -I $ANDROID_HOME_CURL/bionic/libc/kernel/arch-arm \

    -I $ANDROID_HOME_CURL/bionic/libm/include \

    -I $ANDROID_HOME_CURL/bionic/libm/include/arch/arm \

    -I $ANDROID_HOME_CURL/bionic/libthread_db/include \

    -include $ANDROID_HOME_CURL/system/core/include/arch/linux-arm/AndroidConfig.h \

    -I $ANDROID_HOME_CURL/system/core/include/arch/linux-arm/ \

    -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -DANDROID -DNDEBUG -DNDEBUG -DHAVE_CONFIG_H" \

    CFLAGS="-fno-exceptions -Wno-multichar -msoft-float -fpic -ffunction-sections \

    -funwind-tables -fstack-protector -Wa,--noexecstack -Werror=format-security \

    -fno-short-enums -march=armv5te -mtune=xscale -Wno-psabi -mthumb-interwork \

    -fmessage-length=0 -W -Wall -Wno-unused -Winit-self -Wpointer-arith \

    -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point \

    -g -Wstrict-aliasing=2 -finline-functions -fno-inline-functions-called-once \

    -fgcse-after-reload -frerun-cse-after-loop -frename-registers -UDEBUG \

    -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 \

    -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" \

    LIBS="-nostdlib -Bdynamic -Wl,-T,$ANDROID_HOME_CURL/build/core/armelf.x \

    -Wl,-dynamic-linker,/system/bin/linker -Wl,--gc-sections -Wl,-z,nocopyreloc \

    -L$ANDROID_PRODUCT_OUT/obj/lib -Wl,-z,noexecstack \

    -Wl,-rpath-link=$ANDROID_PRODUCT_OUT/obj/lib \

    -lc -llog -lcutils -lstdc++ \

    -Wl,--no-undefined $ANDROID_HOME_CURL/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/lib/gcc/arm-eabi/4.4.0/libgcc.a \

    $ANDROID_PRODUCT_OUT/obj/lib/crtend_android.o \

    -lm $ANDROID_PRODUCT_OUT/obj/lib/crtbegin_dynamic.o \

    -L$ANDROID_HOME_CURL/external/curl/3rd/libs"
    2)修改Android.mk

    ALL_PREBUILT += $(LOCAL_PATH)/NOTICE

    $(LOCAL_PATH)/NOTICE: $(LOCAL_PATH)/COPYING | $(ACP)

    $(copy-file-to-target)

    把关于ALL_PREBUILT模块全部注释调

    2019-07-17 23:14:55
    赞同 展开评论 打赏
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
58同城Android客户端Walle框架演进与实践之路 立即下载
Android组件化实现 立即下载
蚂蚁聚宝Android秒级编译——Freeline 立即下载