3

I have an Android application project that depends on two native libraries, libA and libB. libA depends on libB, and both libraries are built using APP_STL:=gnustl_shared. The problem then arises when trying to build the APK:

[2014-09-30 14:31:47 - Appname] Error generating final archive: Found duplicate file for APK: lib/armeabi/libgnustl_shared.so
Origin 1: /libA/libs/armeabi/libgnustl_shared.so
Origin 2: /libB/libs/armeabi/libgnustl_shared.so

How do I configure these libraries to build/link properly while using a common shared library such as libgnustl_shared.so?

EDIT: I have tried many alternative makefile settings, so it's hard to know what to post here, but I'll try. Both Application.mk files in libA/jni and libB/jni contain:

APP_STL := gnustl_shared
APP_OPTIM := release
APP_ABI := armeabi-v7a armeabi
APP_PLATFORM := android-15

In libA/jni, the Android.mk file contains:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := MyBase
LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/libMyBase.so
LOCAL_PRELINK_MODULE := true
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE    := Base
LOCAL_SRC_FILES := Base.cpp
LOCAL_C_INCLUDES := ../../../../LIBS/MyBase/pub/include

LOCAL_LDLIBS    := -llog -ljnigraphics
LOCAL_SHARED_LIBRARIES := MyBase
LOCAL_CPP_FEATURES += rtti
LOCAL_CPP_FEATURES += exceptions
include $(BUILD_SHARED_LIBRARY)

In libB/jni, the Android.mk file contains:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := MyMedia
LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/libMyMedia.so
LOCAL_PRELINK_MODULE := true
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE    := Media
LOCAL_SRC_FILES := Media.cpp media_jni.cpp
LOCAL_C_INCLUDES := ../../../../LIBS/MyBase/pub/include \
                    ../../../../LIBS/MyMedia/pub/include

LOCAL_LDLIBS    := -llog -ljnigraphics
LOCAL_SHARED_LIBRARIES := MyBase MyMedia
LOCAL_CPP_FEATURES += rtti
LOCAL_CPP_FEATURES += exceptions
include $(BUILD_SHARED_LIBRARY)

$(call import-module,LIBS/MyBase/jni)

MyBase and MyMedia are two native libraries written in C++ and are not Java/JNI aware. MyMedia is dependent on MyBase. Both libraries are dependent on a robust C++ library such as gnustl_shared.

Dennis Estenson
  • 1,022
  • 10
  • 11
  • 1
    please see [if this SO question helps](http://stackoverflow.com/questions/24314983/how-to-exclude-duplicate-c-shared-libraries-so-in-a-multi-project-android-bui), if not can you update your question with make file details. – ashoke Oct 01 '14 at 01:12
  • I'm not using gradle, and the issue seems to be special with the fact that the APP_STL variable in my Application.mk file. I will try to add more details. – Dennis Estenson Oct 01 '14 at 14:49
  • Well, this is embarrassing. After trimming down my makefiles for publishing in my question, it's now working as I wanted it to. – Dennis Estenson Oct 01 '14 at 15:09
  • Ok, now I restarted Eclipse and the problem is back. This is very frustrating. – Dennis Estenson Oct 01 '14 at 15:59
  • can you try running from cmd line `ndk-build clean & ndk-build NDK_LOG=1`, see ndk build log. – ashoke Oct 01 '14 at 17:18
  • @ashoke I don't think that will help. The builds of the individual libraries are fine. The issue occurs when using those libraries from an Android java app (which doesn't use NDK). – Dennis Estenson Oct 01 '14 at 17:27
  • Please explain _how_ you reference the **libA** and **libB** from your Java project with no native support defined. – Alex Cohn Oct 02 '14 at 05:58
  • In Eclipse, I have referenced the two libraries (and others) in the Android->Library section of the properties dialog for the main project by clicking the `Add...` button and selecting the projects libA and libB from the list of available library projects. – Dennis Estenson Oct 05 '14 at 21:54

0 Answers0