I'm having trouble getting the dependency module to build while building a static library in AOSP. Call this library A, it has a dependency on another static lib B.
A's Android.mk looks like this:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := A
LOCAL_SRC_FILES := <files...>
LOCAL_STATIC_LIBRARIES := B
include $(BUILD_STATIC_LIBRARY)
Individually B builds fine (mma).
Problem is when I build A, B is not being built. Instead I see this at output:
Export includes file: <...>/B/Android.mk -- out/<...>/STATIC_LIBRARIES/B_intermediates/export_includes
Can someone explain what does this line mean and, why is it not trying use B's Android.mk to properly build B?
I understand it's not ideal to package a static lib inside another, but here I'm more courious about why is it the build system not running through B's makefile, when it's clearly a dependency?
Thank you!
The build system ignores lots of irrelevant statements, LOCAL_STATIC_LIBRARIES being one of examples. They don't write every entry in LOCAL_STATIC_LIBRARIES as a dependency for libA.a. Instead, they interpret the Android.mk files to produce make rules for all targets, and if a dependency happens to show up, it will eventually get built, too.
Therefore, the easiest workaround for you would be to add a dummy shared library to your Android.mk, like
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := A
LOCAL_SRC_FILES := <files...>
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := dummyA
LOCAL_SRC_FILES := dummy.c
LOCAL_STATIC_LIBRARIES := B
include $(BUILD_SHARED_LIBRARY)
I am not sure if you can drop LOCAL_SRC_FILES completely. In terms of good old plain make files, the above is roughly equivalent to:
all: libA.a libdummyA.so
libdummyA.so: dummy.c libB.a
gcc -o $# dummy.c -lb
Alternatively, you can manually specify the dependency:
$(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libA_intermediates/libA.a: $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libB_intermediates/libB.a
Re: export_includes message, it is the result of processing LOCAL_EXPORT_C_INCLUDES statement for libB.
Related
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?
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.
So I've been scratching my head for quite some time with this: basically, I have two Android makefile, one in my jni folder, and one in another folder that contains my native c++ code.
Thing is, for the following makefile,
LOCAL_PATH := $(call my-dir)
GENERATED_PATH := $(LOCAL_PATH)/../../generated/release/api/Android
############################ Includes ############################
#------------------------------------------------------------------ Assimp
LOCAL_MODULE := Assimp
LOCAL_EXPORT_C_INCLUDES := $(GENERATED_PATH)/assimp/include
LOCAL_SRC_FILES := $(GENERATED_PATH)/assimp/lib/libassimp.a
include $(PREBUILT_STATIC_LIBRARY)
# More Libraries included....
#....
I get the following error:
Android NDK: ERROR:jni/../../../appCommon/Android.mk:Assimp: LOCAL_SRC_FILES points to a missing file
Android NDK: Check that jni/../../../appCommon/jni/../../../appCommon/../../generated/release/api/Android/assimp/lib/libassimp.a exists or that its path is correct
What bugs me is that there's twice the LOCAL_PATH in the path where the ndk searches for the library. I've already read about a few cases like this one (like using the notdir macro) but couldn't find a satisfying solution.
How can I specify correctly (and not manually) the correct directory ?
So it turns out that the problem stems from the PREBUILT_STATIC_LIBRARY script, which looks for the lib in the following path: $(LOCAL_PATH)/$(LOCAL_SRC_FILES)
Thus, a simple workaround that worked is to have separate variables for the directories, like that:
GENERATED_PATH := ../../generated/release/api/Android
GENERATED_INCLUDE_PATH := $(LOCAL_PATH)/$(GENERATED_PATH)
and then use them like that:
LOCAL_MODULE := Assimp
LOCAL_EXPORT_C_INCLUDES := $(GENERATED_INCLUDE_PATH)/assimp/include
LOCAL_SRC_FILES := $(GENERATED_PATH)/assimp/lib/libassimp.a
include $(PREBUILT_STATIC_LIBRARY)
I have a problem with an ndk-build script that builds a static library.
The problem is that this script gets included by our application's larger build script, which gets called with ndk-build all
The build script for the static library looks like this:
# LoadBalancing-cpp
LOCAL_PATH := $(call my-dir)
all_static_libraries = common-cpp-static-prebuilt \
photon-cpp-static-prebuilt
lib_suffix := ${APP_OPTIM}_android_${APP_ABI}
lib_loadbalancing_cpp_static_name := loadbalancing-cpp-prebuilt-static_${lib_suffix}
include $(CLEAR_VARS)
LOCAL_MODULE := loadbalancing-cpp-static-prebuilt
LOCAL_SRC_FILES := lib$(lib_loadbalancing_cpp_static_name).a
LOCAL_STATIC_LIBRARIES := $(all_static_libraries)
include $(PREBUILT_STATIC_LIBRARY)
$(call import-module,common-cpp-prebuilt)
$(call import-module,photon-cpp-prebuilt)
The problem is, building a static library requires the LOCAL_SRC_FILES to point to a single value (the path to the library), however when called with ndk-build all in this case, it will contain multiple values (since lib_suffix will point to all available architectures).
Is there a way to build this file using ndk-build all ?
You can use TARGET_ARCH variable which is managed by ndk-build:
lib_suffix := $(APP_OPTIM)_android_$(TARGET_ARCH)
... and so on.
Essentially, ndk-build will "call" your Android.mk file multiple times, each time setting the TARGET_ARCH variable differently.
I have a shared library libfoo.so and need to use it in my android app.
My first try was to have in Android.mk:
include $(CLEAR_VARS)
LOCAL_MODULE := test
LOCAL_SRC_FILES := test.cpp
LOCAL_LDLIBS := -L$(PATH_TO_FOO) -lfoo
include $(BUILD_SHARED_LIBRARY)
in my activity, I have:
statis
{
System.loadLibrary("foo");
}
This builds correctly, however I noticed that created apk doesnt include libfoo.so (also I see it is not copied to libs/armeabi). I guess for that reason I have UnsatisfiedLinkError when executing my app.
I saw in some other posts that I need to add $(PREBUILD_SHARED_LIBRARY), so I add the following to my Android.mk:
include $(CLEAR_VARS)
LOCAL_MODULE:= foo
LOCAL_SRC_FILES := $(FOO_PATH)/libfoo.so
include $(PREBUILD_SHARED_LIBRARY)
But now I am getting the build error:
foo: LOCAL_SRC_FILES points to a missing file.
I am sure that the path is correct. Note that the libfoo.so was having origionally the version number at the end, though I had to remove it (and leave only .so) since ndk-build complained.
What am I doing wrong?
The include appears to be misspelt:
include $(PREBUILD_SHARED_LIBRARY)
should be
include $(PREBUILT_SHARED_LIBRARY)
Found the solution!! LOCAL_SRC_FILES can not have absolute or relative paths, just the filename. The path must be set in LOCAL_PATH.
So in my case, instead of:
LOCAL_SRC_FILES := $(FOO_PATH)/libfoo.so
I have now:
LOCAL_PATH := $(FOO_PATH)
LOCAL_SRC_FILES := libfoo.so
And this works ok.
In eclipse, i add a static library by copying the file in the path project/libs/armeabi/ and rebuild the project after cleaning it. This includes the .so in the apk.