如何在 android studio 项目中包含共享库?

How to include shared libraries in android studio project?

我正在尝试使用 ARToolKit library in an android studio project. This library uses an NDK shared library, so i have followed this guide to include it in my project. I have also tried solutions from this 问题。

我不认为这个问题是 ARToolKit 库特有的,而是我误解了 NDK 共享库的使用。

我的 Android.mk 共享库模块文件如下所示(按照上面提到的问题):

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE    := artoolkit
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libc++_shared.so
include $(PREBUILT_SHARED_LIBRARY)

或者像这样分别(按照上面提到的指南):

LOCAL_PATH := /Users/balance/SDKs/ARToolKit5

include $(CLEAR_VARS)
LOCAL_MODULE := artoolkit
LOCAL_SRC_FILES := android/libs/$(TARGET_ARCH_ABI)/libc++_shared.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_SHARED_LIBRARY)

对于 .aar 模块:

include $(CLEAR_VARS)
LOCAL_MODULE := aRBaseLib-release
LOCAL_SHARED_LIBRARIES := artoolkit
include $(BUILD_SHARED_LIBRARY)

我已将共享库模块添加为 .aar 模块的依赖项,从而在 aRBaseLib-release 中生成此代码:

configurations.maybeCreate("default")
artifacts.add("default", file('aRBaseLib-release.aar'))
dependencies {
    implementation project(':artoolkit')
}

但是在尝试构建项目时出现以下错误:

Gradle sync failed: Could not find method implementation() for arguments [project ':artoolkit'] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

我意识到这些片段可能没有多大帮助,所以我当然准备好在您的指导下重新开始,并从那里收到 post 新的错误消息。

我们将不胜感激并尝试任何想法。

我终于找到了解决办法here.so 文件必须位于 <project>/app/src/main/jniLibs/ 中才能包含在 .apk 中。之前,我把它们放到了 libs 文件夹中。