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

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_MODULE=ndktest
LOCAL_SRC_FILES=ndktest.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 -mfpu=neon -mcpu=kryo -std=c++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++

You forgot to (re)set LOCAL_MODULE for the last part of your makefile. I think the last few lines should be:
LOCAL_MODULE=ndktest
LOCAL_SRC_FILES=ndktest.cpp
LOCAL_LDLIBS += -lm -llog -landroid
LOCAL_CFLAGS += -DARM_NEON_64BIT -O3 -mfpu=neon -mcpu=kryo -std=c++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)

Related

Android Ndk Error No rule to make target

I am try to build Android Cpp project using Ndk.
when i build app its only generate jni folder files
cannot generate jni sub folder files
i got this error
make: *** No rule to make target src/main/jni/src/main/jni/A/B/Helper.cpp', needed bybuild/intermediates/ndk/obj/local/armeabi/objs/demo/src/main/jni/A/B/Helper.o'. Stop.
TOP_LOCAL_PATH:=$(call my-dir)
LOCAL_PATH := $(TOP_LOCAL_PATH)
include $(CLEAR_VARS)
LOCAL_MODULE := demo
LOCAL_SRC_FILES := a.cpp b.cpp c.cpp d.cpp
LOCAL_SRC_FILES := $(LOCAL_PATH)/A/B/Helper.cpp
LOCAL_CFLAGS += -std=c++11 -frtti -fexceptions -fpermissive
LOCAL_LDLIBS += -llog -lGLESv2 -lEGL -landroid -lOpenSLES -lGLESv1_CM -lz
LOCAL_C_INCLUDES := $(LOCAL_PATH)/A/B
include $(BUILD_SHARED_LIBRARY)
The file names that are listed in LOCAL_SRC_FILES are relative to LOCAL_PATH. ALso, you can define this list on multiple lines, but by appending the list, not replacing it.
So, your Android.mk file should probably look like this:
TOP_LOCAL_PATH:=$(call my-dir)
LOCAL_PATH := $(TOP_LOCAL_PATH)
include $(CLEAR_VARS)
LOCAL_MODULE := demo
LOCAL_SRC_FILES := a.cpp b.cpp c.cpp d.cpp
LOCAL_SRC_FILES += A/B/Helper.cpp
LOCAL_CFLAGS += -std=c++11 -frtti -fexceptions -fpermissive
LOCAL_LDLIBS += -llog -lGLESv2 -lEGL -landroid -lOpenSLES -lGLESv1_CM -lz
LOCAL_C_INCLUDES := $(LOCAL_PATH)/A/B
include $(BUILD_SHARED_LIBRARY)
Note that the list LOCAL_C_INCLUDES should use full paths.

Android NDK, error: undefined reference to function of .h file

This is my android.mk file but when I Compile this I get this error
Error while creating
My android.mk file
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libNDK
LOCAL_CFLAGS := -DANDROID_NDK \
-DDISABLE_IMPORTGL
LOCAL_SRC_FILES := SerialPort.c
LOCAL_CFLAGS := -std=c99
LOCAL_LDLIBS := -lGLESv1_CM -ldl -llog
include $(BUILD_SHARED_LIBRARY)

NDK Android compile various extension files

I want to use native libraries in my Android project and I try compiling them. The error I found is caused from the incompatible file extensions. They are .c .h .m4 .y and others extensions.
here is a part of my Android.mk file
LOCAL_PATH := $(call my-dir)
TARGET_ARCH_ABI := armeabi-v7a
include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog
LOCAL_MODULE := openssl-0.9.7m
FILE_LIST := $(wildcard $(LOCAL_PATH)/$(LOCAL_MODULE))
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog
LOCAL_MODULE := pbc-0.5.12
FILE_LIST := $(wildcard $(LOCAL_PATH)/$(LOCAL_MODULE))
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog
LOCAL_MODULE := libbswabe-0.9
FILE_LIST := $(wildcard $(LOCAL_PATH)/$(LOCAL_MODULE))
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog
LOCAL_MODULE := gmp-5.0.2
FILE_LIST := $(wildcard $(LOCAL_PATH)/$(LOCAL_MODULE))
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog
LOCAL_MODULE := libpbc
FILE_LIST := $(wildcard $(LOCAL_PATH)/$(LOCAL_MODULE))
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog
LOCAL_MODULE := m4-1.4.16
FILE_LIST := $(wildcard $(LOCAL_PATH)/$(LOCAL_MODULE))
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog
LOCAL_MODULE := cpabe-0.11
FILE_LIST := $(wildcard $(LOCAL_PATH)/$(LOCAL_MODULE))
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
# LOCAL_LDLIBS := -llog
LOCAL_MODULE := PHRapp_Login_JNI
FILE_LIST := $(wildcard $(LOCAL_PATH)/$(LOCAL_MODULE))
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
include $(BUILD_STATIC_LIBRARY)
when i compile in Eclipse, it warned that there are unsupported source file extensions for the module i described in Android.mk.
How should I do for the solution?
Using $wildcard to list all files in lib build directory is not a good practice. When you work with so many open source libraries it's much easier to prepare and use standalone toolchain for NDK instead of improvizing the Android.mk.

Android NDK. 'abs' was not declared in this scope

Cant build with using gnustl_static. Got:
'abs' was not declared in this scope
And when trying to build with stlport I cant use c++11 methods.
Here is my Application.mk:
APP_ABI := armeabi-v7a
APP_STL := gnustl_static
APP_CPPFLAGS += -std=c++11 -w
APP_PLATFORM := android-19
APP_OPTIM := release
And Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := ModuleName
LOCAL_LDLIBS := -lm -llog -landroid
LOCAL_C_INCLUDES := .......
LOCAL_SRC_FILES += .......
include $(BUILD_SHARED_LIBRARY)

how to generate two .so file in a single android.mk file

I'd like to create two .so file within a single .mk file. But the following codes fails because there should not be a space in LOCAL_MODULE. So is there a way out?
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := gpio hello-jni
LOCAL_CFLAGS := -Werror
LOCAL_SRC_FILES := gpio.c hello-jni.c
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)
I just got it works using the following codes.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := gpio
LOCAL_CFLAGS := -Werror
LOCAL_SRC_FILES := gpio.c
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := h ello-jni
LOCAL_CFLAGS := -Werror
LOCAL_SRC_FILES := hello-jni.c
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)

Categories

Resources