【问题标题】:jni/Android.mk:8:curlLib/packages/Android/Android.mk: No such file or directoryjni/Android.mk:8:curlLib/packages/Android/Android.mk: 没有这样的文件或目录
【发布时间】:2017-01-05 06:23:07
【问题描述】:

我从未使用 Android 构建 curl。

先决条件:我使用的是 Android Studio 2.1.2 我正在使用 NDK ,非实验方式 我在 curlLib 目录的 jni 文件夹中有 curl-7.49.1 库的源代码 ExtLibCurl 是我的应用程序 jni 文件夹中的文件夹/目录,其中包含从下载的源代码 https://android.googlesource.com/platform/external/curl/+/e6f2b03027b5feb92b30f5d47801ec3fabe9fd95

可以在 Android.mk 中检查 cURL 和其他文件。

根据问题中的 cmets 更新文件。

以下是我的 Android.mk 文件

JNI_DIR := $(call my-dir)

LOCAL_PATH:= $(JNI_DIR)
include $(CLEAR_VARS)

include $(LOCAL_PATH)/ExtLibCurl/Android.mk

# Build main library as shared library.
LOCAL_PATH := $(JNI_DIR)
include $(CLEAR_VARS)

LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_C_INCLUDES += $(LOCAL_PATH)/ExtLibCurl/include/curl
LOCAL_C_INCLUDES += $(LOCAL_PATH)/ExtLibCurl/lib

FILE_LIST += $(wildcard $(LOCAL_PATH)/ExtLibCurl/src/*.c)

LOCAL_MODULE := ndksampleapp
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)

LOCAL_STATIC_LIBRARIES := ExtLibCurl

include $(BUILD_SHARED_LIBRARY)

应用程序.mk

APP_ABI := all
APP_STL    := gnustl_static
APP_CFLAGS += -std=gnu++11
APP_OPTIM  := debug
LOCAL_CPP_FEATURES += exceptions

NDK_TOOLCHAIN_VERSION := 4.9

我构建 curl 的 Android.mk 的方式是否正确?

当我在 src\main 路径中执行 ndk-build 时,出现以下错误

    [arm64-v8a] Compile        : ndksampleapp <= curlutil.c
cc1.exe: warning: command line option '-std=gnu++11' is valid for C++/ObjC++ but not for C
In file included from jni/ExtLibCurl/lib/strdup.h:24:0,
                 from jni/ExtLibCurl/src/setup.h:206,
                 from jni/ExtLibCurl/src/curlutil.c:23:
jni/ExtLibCurl/lib/setup.h:120:28: fatal error: curl/curlbuild.h: No such file or directory
 #include <curl/curlbuild.h>
                            ^
compilation terminated.
make: *** [obj/local/arm64-v8a/objs-debug/ndksampleapp/ExtLibCurl/src/curlutil.o] Error 1

如果我删除 FILE_LIST += $(wildcard $(LOCAL_PATH)/ExtLibCurl/src/*.c) 不会生成任何 cURL 文件。

【问题讨论】:

  • 作为一个快速测试,将 curlLib 的 android.mk 的相对路径包含更改为完整的绝对路径。如果这可行,那么问题就变成了在知道构建的其余部分是正确的情况下找出正确的相对路径..
  • 嘿@RichardCritten 感谢您的回复,但它无法正常中止并给出以下错误:Android NDK: Trying to define local module 'curl' in jni/curlLib/packages/Android/Android.mk。 Android NDK:但是这个模块已经被 jni/curlLib/packages/Android/Android.mk 定义了。 C:/Users/m1035325/AppData/Local/Android/sdk/ndk-bundle/build//../build/core/build-module.mk:34: *** Android NDK: 中止。 .停止。我什至尝试使用完全合格的路径。
  • 在这个问题中反对什么?
  • 重新投反对票 - 不知道 - 将你投回 0。
  • @RichardCritten 谢谢 :)

标签: android c++ c curl android-ndk


【解决方案1】:

您的Android.mk 文件应如下所示:

JNI_DIR := $(call my-dir)

LOCAL_PATH:= $(JNI_DIR)
include $(CLEAR_VARS)

include $(LOCAL_PATH)/ExtLibCurl/Android.mk

# Build main library as shared library.
LOCAL_PATH := $(JNI_DIR)
include $(CLEAR_VARS)

LOCAL_C_INCLUDES += $(LOCAL_PATH)/ExtLibCurl/include
LOCAL_C_INCLUDES += $(LOCAL_PATH)/ExtLibCurl/lib

# !!! place list of YOUR sources to this variable !!!
FILE_LIST += $(wildcard $(LOCAL_PATH)/src/*.c) 

LOCAL_MODULE := ndksampleapp
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)

LOCAL_STATIC_LIBRARIES := libcurl
LOCAL_LDLIBS += -lz

include $(BUILD_SHARED_LIBRARY)

模块名称不需要与其目录名称匹配。

ExtLibCurl/Android.mk你必须取消注释BUILD_STATIC_LIBRARY部分,你也可以通过创建可执行的curl(第74行+)删除所有部分,即文件将如下所示:

# Google Android makefile for curl and libcurl
#
# Place the curl source (including this makefile) into external/curl/ in the
# Android source tree.  Then build them with 'make curl' or just 'make libcurl'
# from the Android root. Tested with Android 1.5
#
# Note: you must first create a curl_config.h file by running configure in the
# Android environment. The only way I've found to do this is tricky. Perform a
# normal Android build with libcurl in the source tree, providing the target
# "showcommands" to make. The build will eventually fail (because curl_config.h
# doesn't exist yet), but the compiler commands used to build curl will be
# shown. Now, from the external/curl/ directory, run curl's normal configure
# command with flags that match what Android itself uses. This will mean
# putting the compiler directory into the PATH, putting the -I, -isystem and
# -D options into CPPFLAGS, putting the -m, -f, -O and -nostdlib options into
# CFLAGS, and putting the -Wl, -L and -l options into LIBS, along with the path
# to the files libgcc.a, crtbegin_dynamic.o, and ccrtend_android.o. Remember
# that the paths must be absolute since you will not be running configure from
# the same directory as the Android make.  The normal cross-compiler options
# must also be set.
#
# The end result will be a configure command that looks something like this
# (the environment variable A is set to the Android root path):
#
#  A=`realpath ../..` && \
#  PATH="$A/prebuilt/linux-x86/toolchain/arm-eabi-X/bin:$PATH" \
#  ./configure --host=arm-linux CC=arm-eabi-gcc \
#  CPPFLAGS="-I $A/system/core/include ..." \
#  CFLAGS="-fno-exceptions -Wno-multichar ..." \
#  LIB="$A/prebuilt/linux-x86/toolchain/arm-eabi-X/lib/gcc/arm-eabi/X\
#  /interwork/libgcc.a ..." \
#
# Dan Fandrich
# September 2009
LOCAL_PATH:= $(call my-dir)
common_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
#########################
# Build the libcurl library
include $(CLEAR_VARS)
include $(LOCAL_PATH)/lib/Makefile.inc
CURL_HEADERS := \
    curlbuild.h \
    curl.h \
    curlrules.h \
    curlver.h \
    easy.h \
    mprintf.h \
    multi.h \
    stdcheaders.h \
    typecheck-gcc.h \
    types.h
LOCAL_SRC_FILES := $(addprefix lib/,$(CSOURCES))
LOCAL_C_INCLUDES := \
    $(LOCAL_PATH)/include \
    external/openssl/include \
    external/zlib
LOCAL_CFLAGS += $(common_CFLAGS)
LOCAL_COPY_HEADERS_TO := libcurl/curl
LOCAL_COPY_HEADERS := $(addprefix include/curl/,$(CURL_HEADERS))
#LOCAL_SHARED_LIBRARIES := libz
LOCAL_MODULE:= libcurl
include $(BUILD_STATIC_LIBRARY)

【讨论】:

  • 那是 gr8。现在由于 32 位和 64 位以及 openssl 而出现错误,但答案适用于我提出的问题。 “取消注释 BUILD_STATIC_LIBRARY 部分,通过创建可执行 curl 删除所有部分” IMP 输入。感谢您的早期,及时的回应,并消除了疑虑。 :) 赞成并接受您的回答 :)
猜你喜欢
  • 2023-03-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多