简体   繁体   English

在APK中两次包含原生代码包库的Android库项目

[英]Android library project with native code packages library twice in the APK

I have two Android projects, one is a shared library and one is my application's project. 我有两个Android项目,一个是共享库,另一个是我的应用程序的项目。 Both projects contain some Java and some native code. 这两个项目都包含一些Java和一些本机代码。 When I try and run my APK I receive the following error: 尝试运行APK时,出现以下错误:

Error generating final archive: Found duplicate file for APK: lib/armeabi/libOEShared.so 生成最终归档文件时出错:找到APK的重复文件:lib / armeabi / libOEShared.so

My shared library is marked as a library project (Properties->Android->'Is Library') so that I am able to use it's Java code. 我的共享库被标记为一个库项目(Properties-> Android->'Is Library'),因此我可以使用它的Java代码。 This presumably copies libOEShared.so for me once. 据推测这会为我复制一次libOEShared.so。

In order to link my Applications native code with libOEShared I use the NDK Prebuilds feature. 为了将我的应用程序本机代码与libOEShared链接,我使用NDK Prebuilds功能。 Here is my Android.mk: 这是我的Android.mk:

#include shared library
include $(CLEAR_VARS)
LOCAL_MODULE := OEShared
LOCAL_SRC_FILES := ../../../Shared/OEShared/libs/armeabi/libOEShared.so
include $(PREBUILT_SHARED_LIBRARY)

#build App library
include $(CLEAR_VARS)
LOCAL_MODULE    := OEApp
LOCAL_SRC_FILES := OEApp.cpp
LOCAL_LDLIBS    := -llog -lGLESv2 -lz
LOCAL_SHARED_LIBRARIES := OEShared
include $(BUILD_SHARED_LIBRARY)

However, the NDK also copies libOEShared into my Application project's lib folder, resulting in two copies being present in the final APK. 但是,NDK还将libOEShared复制到我的Application项目的lib文件夹中,导致最终的APK中存在两个副本。

How can I link my Application's native code to libOEShared without it being automatically duplicated? 如何将我的应用程序的本机代码链接到libOEShared而不自动复制它?

Thank you for you time, this has caused me a lot of frustration so far. 谢谢您的时间,到目前为止,这使我感到非常沮丧。

Only linking is required here, instead of build. 这里仅需要链接,而不是构建。 Linking can be done by using LOCAL_LD_LIBS flag. 可以使用LOCAL_LD_LIBS标志进行链接。 You can try this. 你可以试试看

LOCAL_LDLIBS  := -L$(LOCAL_PATH)/../../../Shared/OEShared/libs/$(TARGET_ARCH_ABI)/  \
         -lOEShared

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM