1

我的 Android 项目已经使用 Eclipse 和 ADT 进行了几年。该项目使用 3 个预编译的静态库(curl、ssl 和 crypto),然后编译并静态链接 libxml2。Android.mk 中的相关行是:

LOCAL_MODULE    := my_shim
LOCAL_SRC_FILES := $(LOCAL_FILE_LIST:$(LOCAL_PATH)/%=%)
LOCAL_CFLAGS := -DCURL_DISABLE_TYPECHECK
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog -lz
LOCAL_SHARED_LIBRARIES :=
LOCAL_STATIC_LIBRARIES += xml2 curl ssl crypto
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../c_module
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../libxml2/include

include $(BUILD_SHARED_LIBRARY)

include $(APP_LOCAL_PATH)/../../libxml2/Android.mk

我现在正在使用 Gradle Experimental 切换到 Android Studio 2,但在正确配置 Gradle 时遇到了问题。我想我已经设法理清了对 log 和 z 的依赖关系,以及静态编译的 curl、ssl 和加密库,但我不知道如何告诉它构建然后静态链接 libxml2 模块。

有什么线索吗?这是我到目前为止所拥有的:

model {
    android {
        ...
    }

    android.ndk {
        moduleName "my_shim"
        platformVersion 19
        abiFilters.addAll(["armeabi", "x86"])
        CFlags.add("-DCURL_DISABLE_TYPECHECK")
        ldLibs.addAll(["log", "z"])
        stl "stlport_static"
    }

    android.sources {
        main {
            jni {
                dependencies {
                    library "crypto" linkage "static"
                    library "curl" linkage "static"
                    library "ssl" linkage "static"
                    library "xml2" linkage "static"
                }
            }
        }
    }

    repositories {
        libs(PrebuiltLibraries) {
            crypto {
                binaries.withType(StaticLibraryBinary) {
                    def cryptoLibPath = "src/main/jni/includes/${targetPlatform.getName()}/libcrypto.a"
                    staticLibraryFile = file("${cryptoLibPath}")
                }
            }
        }
        libs(PrebuiltLibraries) {
            curl {
                binaries.withType(StaticLibraryBinary) {
                    def curlLibPath = "src/main/jni/includes/${targetPlatform.getName()}/libcurl.a"
                    staticLibraryFile = file("${curlLibPath}")
                }
            }
        }
        libs(PrebuiltLibraries) {
            ssl {
                binaries.withType(StaticLibraryBinary) {
                    def sslLibPath = "src/main/jni/includes/${targetPlatform.getName()}/libssl.a"
                    staticLibraryFile = file("${sslLibPath}")
                }
            }
        }
    }
}
4

1 回答 1

1

有两种方法,我想。

  1. 手动预构建 libxml2 并将其与其他预构建库放在一起。

  2. 建立一个依赖项(和 xml2 库的单独项目)这里描述

于 2016-04-15T11:13:54.353 回答