How to deal with the LOCAL_STATIC_LIBRARIES in android .mk - android

I'm trying to port one of the android NDK samples (native-activity) to work with the vs-android plugging that lets me develop in MVS.
To do this I need to translate the Android.mk commands into something MVS can deal with, and I'm having trouble with one of them.
Android.mk :
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := native-activity
LOCAL_SRC_FILES := main.c
LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv1_CM
LOCAL_STATIC_LIBRARIES := android_native_app_glue
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/native_app_glue)
The lines of LOCAL_STATIC_LIBRARIES and $(call import-module,android/native_app_glue) obviously deal with the native_app_glue that is central to making the native_activity class do it's magic.
Any idea on how to translate this in terms of compile line options in vs-android, linker options of MVS or anything similar? Or at least what those two lines do?
Cheers,
Jaime

Got it to work.
As it seems to be creating a library (native_app_glue) from what the .mk says, I went ahead and compiled the native_app_glue library as another static library (.a) project in my MVS, and then added it to the project dependencies. This worked with no problems

Related

Why modifying an unrelated module in Android.mk rebuilds all libraries?

I made a simple project in Android Studio.
It compiles with no errors, the editor throws no warnings and the app works fine.
BUT if I modify the Android.mk in my project and hit the build button it recompiles everything from scratch.
Since it's a small project it takes little time but I can see the wait becoming much longer.
This is my Android.mk:
MY_DIR := $(call my-dir)
LOCAL_PATH := ${MY_DIR}/src/main/cpp
EXTERNAL_PATH := ${MY_DIR}/../..
include $(CLEAR_VARS)
LOCAL_MODULE := cglm
LOCAL_C_INCLUDES := ${EXTERNAL_PATH}/cglm/include
LOCAL_SRC_FILES := $(wildcard ${EXTERNAL_PATH}/cglm/src/*.c)
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := main
LOCAL_SRC_FILES := main.c noop.c renderer.c triangle.c quad.c shaders.c
LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv3
LOCAL_STATIC_LIBRARIES := android_native_app_glue
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/native_app_glue)
Concrete steps that I took to observe the behaviour I described:
1. With the Android.mk as you see it, I build the app. Everything is compiled from scratch as it should.
2. I change some code inside shaders.c
3. I build the app. Only the shaders.c file is recompiled. Good.
4. I delete shaders.c from the LOCAL_SRC_FILES on Android.mk.
5. I build the app. First thing it does is recompiling the whole cglm module which wasn't even being used by the main module. Then it proceeds to recompile the whole main module as you can see in the Android.mk I showed you.
Why is this happening and can I prevent it from happening without switching to cmake nor using a prebuilt library?

How to include a prebuilt "*.a" library (from tensorflow) to my android NDK project with no Android.mk file?

I'm trying to compile my application to use tensorflow C++ library after building lintensorflow_core.a into my NDK application. The application has the main java layer, that communicates with the NDK component. In that NDK component, I'm looking to call the tensorflow as such: using namespace ::tensorflow::ops; // NOLINT(build/namespaces)
I've seen bunch of links on how to do it with Android.mk file. But apparently, that does not gets created anymore in the new version of android studio. If it is possible with just Android.mk and ndk-build command, that would be great as well. However, the combination of Android.mk and ndk-build has also failed me. The output basically nothing.
I did have plenty of variation of Android.mk file and here's one of them:
LOCAL_PATH := $(call my-dir)
TENSORFLOW_HOME := $(LOCAL_PATH)/../../../../../tensorflow
TENSORFLOW_CORE := $(LOCAL_PATH)/../../../../../tensorflow/tensorflow/core
TENSORFLOW_OPS := $(LOCAL_PATH)/../../../../../tensorflow/tensorflow/core/ops
include $(CLEAR_VARS)
LOCAL_MODULE := tensorflow
LOCAL_SRC_FILES := $(TENSORFLOW_HOME)/tensorflow/contrib/makefile/gen/lib/android_armeabi-v7a/libtensorflow-core.a
LOCAL_LDLIBS := -static -Wl,--build-id -Wl,--allow-multiple-definition -Wl,--whole-archive
LOCAL_CFLAGS := -std=c++11 -I$(TENSORFLOW_HOME)
LOCAL_C_INCLUDES := $(TENSORFLOW_OPS)
TARGET_ARCH_ABI := armeabi
include $(PREBUILT_STATIC_LIBRARY)
But this has been a total failure. Could someone point me to the right direction?

Missing LOCAL_MODULE before including BUILD_SHARED_LIBRARY

I am trying to set a NDK project in Eclipse. I have build the NDK as my sample programs are working properly. But, now when I am running my code I am facing this error
*** Android NDK: Missing LOCAL_MODULE before including BUILD_SHARED_LIBRARY in jni/Android.mk . Stop.
I have tried solving it through this question
Android NDK: Missing LOCAL_MODULE before including BUILD_SHARED_LIBRARY
But, Its not working. Please help me.
Following is my Android.mk file
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
OPENCV_CAMERA_MODULES:= off
OPENCV_MK_PATH:D:\FYP\darwinwallet-master\OpenCV-2.4.9-android-sdk\sdk\native\jni\OpenCV.mk
OPENCV_LIB_TYPE:=STATIC
OPENCV_INSTALL_MODULES:=on
include $(OPENCV_MK_PATH)
LOCAL_C_INCLUDES:=D:\FYP\darwinwallet-master\OpenCV-2.4.9-android-sdk\sdk\native\jni\include\
LOCAL_MODULE:=native_wallet
LOCAL_SRC_FILES:=jni_recognizer.cpp NativeVision/vision.cpp
LOCAL_CFLAGS=-ffast-math -O3 -funroll-loopsLOCAL_LDLIBS+=-llog -ldl
include $(BUILD_SHARED_LIBRARY)
And following is my build-shared-library.mk
LOCAL_BUILD_SCRIPT := BUILD_SHARED_LIBRARY
LOCAL_MAKEFILE := $(local-makefile)
$(call check-defined-LOCAL_MODULE,$(LOCAL_BUILD_SCRIPT))
$(call check-LOCAL_MODULE,$(LOCAL_MAKEFILE))
$(call check-LOCAL_MODULE_FILENAME)
my := TARGET_
$(call handle-module-filename,lib,$(TARGET_SONAME_EXTENSION))
$(call handle-module-built)
LOCAL_MODULE_CLASS := SHARED_LIBRARY
include $(BUILD_SYSTEM)/build-module.mk
Don't use backslash in your make files, it's too dangerous. Even on Windows, you can use forward slashes, i.e. change all \ to /. This will resolve your problem immediately.
Specifically, the line where you define LOCAL_C_INCLUDES ends with \ which means for make that it does not end. make dutifully joins the next line, so what it actually sees is something like
…
LOCAL_C_INCLUDES:=D:\…\include\LOCAL_MODULE:=native_wallet
LOCAL_SRC_FILES:=jni_recognizer.cpp NativeVision/vision.cpp
…
But actually, there is no need to re-define LOCAL_C_INCLUDES after you include OpenCV.mk. This script takes care of setting the include paths, flags, and library dependencies for you.

Static Linking OpenCV 2.4.3.2

I would like to statically link OpenCV(2.4.3.2) to my project. Right now my Android.mk looks like this
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
OPENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=on
include /Users/jamiematthews/Documents/Android-Projects/OpenCV-2.4.3-android-sdk/sdk/native/jni/OpenCV.mk
LOCAL_MODULE := jni_part
LOCAL_SRC_FILES := jni_part.cpp
LOCAL_LDLIBS += -llog -ldl
LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib -llog
include $(BUILD_SHARED_LIBRARY)
Which throws the errors:
Android NDK: ERROR:/Users/jamiematthews/Documents/workspace/AuthentiGuard/jni/Android.mk:on: LOCAL_SRC_FILES points to a missing file
/Users/jamiematthews/Documents/android-ndk-r8d/build/core/prebuilt-library.mk:43: *** Android NDK: Aborting . Stop.
Android NDK: Check that /Users/jamiematthews/Documents/Android-Projects/OpenCV-2.4.3-android-sdk/sdk/native/jni/../libs/mips/libon.so exists or that its path is correct
Anyone know what "LOCAL_SRC_FILES points to a missing file" could mean?
PS if I remove the lines
OPENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=on
it compiles fine, but then I cant statically link
Found the solution. Believe it or not it was an issue with Application.mk, not Android.mk. I had set
APP_ABI := all
Previously, and not even considered that it could effect the build process of this statically. I ended up changing it to
APP_ABI := armeabi-v7a
And now, everything works fine. Note that I ended up not needing OPENCV_CAMERA_MODULES:=on, I believe that is only if you are calling the camera from JNI, which I am not
LOCAL_SRC_FILES show the file where your native code resides. If you use native OpenCV code then you have to add the name of your cpp file here.
If you do not have a native part then you should add the OpenCV library to the libs folder of your project. (in case of static initialization). Please check this page for details.

Avoiding redundant build to make tessaract android library && link tessaract library to c++ NDK

Now I am making an application using on MacOSx with Tessaract and Android NDK.
I use Eclipse as an IDE to develop the program.
I have two questions to ask:
1). I set up tessaract using the most famous example "tess-two" and modified a bit to fit with my existing code. I copied folder "com_googlecode_leptonica_android" and "com_googlecode_tessaract_android" to /jni folder. Then edit Android.mk for setting path to those library folder. Everything works fine! Except one thing.. Every time that I build the project, I need to build both "leptonica" and "tessaract" library again and again..in order to get libtess and liblept.. It takes soooo long. How can I edit android makefile (Android.mk) not to build those libraries.. just compile my code only... thats all.. Here is my Android.mk
LOCAL_PATH := $(call my-dir)
MY_PATH := $(LOCAL_PATH)
TESSERACT_PATH := $(call my-dir)/com_googlecode_tesseract_android
LEPTONICA_PATH := $(call my-dir)/com_googlecode_leptonica_android
include $(call all-subdir-makefiles)
include $(CLEAR_VARS)
include /Applications/eclipse-android/OpenCV-2.4.3-android-sdk/sdk/native/jni/OpenCV.mk
LOCAL_PATH := $(MY_PATH)
LOCAL_MODULE := my_project
LOCAL_SRC_FILES := cppmain.cpp
LOCAL_LDLIBS += -llog -ldl
include $(BUILD_SHARED_LIBRARY)
)
2). I found a lot of examples about using tessaract with Android. However most of them using tessaract with Java (call via JNI) and call JNI from java code (Java -> Tessaract C++ JNI -> Tessaract C++). I cannot find any example that call tessaract from c++ NDK (Java -> my JNI -> my C++ -> Tessract C++). The reason that I want to call tessaract directly from c++ is portability.
Use PREBUILT_STATIC_LIBRARY, something like
LOCAL_PATH = $(MY_PATH)/com_googlecode_tesseract_android/lib
include $(CLEAR_VARS)
LOCAL_MODULE := tesseract
LOCAL_SRC_FILES := libtesseract.a
include $(PREBUILT_STATIC_LIBRARY)
LOCAL_PATH = $(MY_PATH)/com_googlecode_leptonica_android/lib
include $(CLEAR_VARS)
LOCAL_MODULE := leptonica
LOCAL_SRC_FILES := libleptonica.a
include $(PREBUILT_STATIC_LIBRARY)
LOCAL_PATH := $(MY_PATH)
LOCAL_MODULE := my_project
LOCAL_SRC_FILES := cppmain.cpp
LOCAL_LDLIBS += -llog -ldl
LOCAL_LDFLAGS += -ltesseract -lleptonica
include $(BUILD_SHARED_LIBRARY)
The tesseract project does not contain prebuilt libraries, but if you follow the official instructions, these libraries will be built. Using PREBUILT_STATIC_LIBRARY only helps you to avoid unnecessary rebuilds of these libraries all the time. Same approach is recommended for libjpeg and libpng, as long as you don't change these libraries yourself.

Categories

Resources