I am getting error while ndk build in android.mk file

Issue

I am getting error during ndk build. I have only one android.mk file and only one Application.mk file in my project Android NDK: Trying to define local module ‘protobuf’ in /home/parag.j/AndroidArm//jni/Android.mk.
Android NDK: But this module was already defined by /home/parag.j/AndroidArm//jni/Android.mk.

Here is my Android.mk file

LOCAL_PATH: $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULEndktest
LOCAL_SRC_FILESndktest.cpp
include $(CLEAR_VARS)
LOCAL_MODULE : c++_shared
LOCAL_SRC_FILES : $(LOCAL_PATH)/inc/build/libc++_shared.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE : armnn
LOCAL_SRC_FILES : $(LOCAL_PATH)/inc/build/libarmnn.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE : armnnTfParser
LOCAL_SRC_FILES : $(LOCAL_PATH)/inc/build/libarmnnTfParser.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE : protobuf
LOCAL_SRC_FILES : $(LOCAL_PATH)/inc/build/libprotobuf.so
include $(PREBUILT_SHARED_LIBRARY)
LOCAL_LDLIBS    + -lm -llog -landroid
LOCAL_CFLAGS + -DARM_NEON_64BIT -O3 -mfpuneon -mcpukryo -stdc++14 -pie
LOCAL_SHARED_LIBRARIES : opencv_java3 armnn armnnTfParser protobuf c++_shared
LOCAL_C_INCLUDES  :   $(LOCAL_PATH)/inc/include\
include $(BUILD_SHARED_LIBRARY)

Here is my Application.mk file

APP_ABI:arm64-v8a 
APP_CFLAGS + -Ofast
APP_OPTIM : release
APP_STL : gnustl_static
APP_CPPFLAGS : -frtti -fexceptions
APP_PLATFORM : android-22
ANDROID_TOOLCHAIN_NAME : clang++

Solution

You forgot to (re)set LOCAL_MODULE for the last part of your makefile. I think the last few lines should be:

LOCAL_MODULEndktest
LOCAL_SRC_FILESndktest.cpp
LOCAL_LDLIBS    + -lm -llog -landroid
LOCAL_CFLAGS + -DARM_NEON_64BIT -O3 -mfpuneon -mcpukryo -stdc++14 -pie
LOCAL_SHARED_LIBRARIES : opencv_java3 armnn armnnTfParser protobuf c++_shared
LOCAL_C_INCLUDES  :   $(LOCAL_PATH)/inc/include
include $(BUILD_SHARED_LIBRARY)

(and get rid of the ndktest lines at the start of the file, of course)

Answered By – Botje

Leave a Comment