How to write / debug Android.mk for NDK static library?

I am trying to create a static library using the latest version of Android NDK (r5) and I have no luck. I managed to build and run samples (like HelloJni) without any problems, but starting a new project from scratch was a different story.

In this experiment, I am trying to create libpng. The structure of my folder is as follows:

root | +--- jni | +---- Android.mk ( one line: "include $(call all-subdir-makefiles)" ) | +---- png | +---- Android.mk ( see below ) | +---- { a bunch of .c and .h files ) 

So, I have two Android.mks. One for building all subprojects and one for libpng subproject. root / jni / png / Android.mk looks like this:

 LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := png MODULE_PATH := $LOCAL_PATH LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.c) LOCAL_C_INCLUDES := $(wildcard $(LOCAL_PATH)/*.h) LOCAL_INTERMEDIATE_TARGETS += junk junk: echo $(LOCAL_SRC_FILES) include $(BUILD_STATIC_LIBRARY) 

This installation installation does nothing (i.e. launching ndk-build from the root folder does nothing, even after building ndk-build). A detailed run (ndk-build V = 1) shows some rm -f calls (deleting nonexistent folders), but nothing is related to the project or subproject.

I am very interested why this build of the script fails, but the process should have been trivial, so I'm sure its nothing terribly interesting. I'm much more interested in how I can start attacking build errors myself. The echo call in the script never gets above - I have no idea how to determine which values โ€‹โ€‹or why it skips the subproject. Has anyone found a way to find out what the build system is trying to create?

I would also be interested to know if there are documents for these tools or if these are just a few text files in the Docs Docs folder? I tried to solve this problem by copying pieces of random Android.mk that I found from googling, but only a few commands used in simple NDK samples seem to be documented, so the experience really just raised new questions.

+7
source share
3 answers

I would recommend getting rid of MODULE_PATH and not trying to use a wildcard: I actually did not see this work correctly.

 LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := png LOCAL_SRC_FILES := pngget.c pngread.c pngrutil.c pngtrans.c pngwtran.c png.c pngmem.c pngrio.c pngset.c pngwio.c pngwutil.c pngerror.c pngpread.c pngrtran.c pngwrite.c LOCAL_C_INCLUDES := png.h pngconf.h pngpriv.h include $(BUILD_STATIC_LIBRARY) 

In addition, there is some serious magic of the path that I have not completely deciphered: somehow Eclipse is doing everything right, but making it jump through the correct hoops from the command line still amazes or skips for me.

EDIT: so he was very interested in understanding this, since it has been a while since I played with NDK. When I use the source file, it did not compile, but when I put the png source code in the jni directory and then used this Android.mk file:

 LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := png LOCAL_SRC_FILES := pngget.c pngread.c pngrutil.c pngtrans.c pngwtran.c png.c pngmem.c pngrio.c pngset.c pngwio.c pngwutil.c pngerror.c pngpread.c pngrtran.c pngwrite.c LOCAL_C_INCLUDES := png.h pngconf.h pngpriv.h include $(BUILD_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := png2 LOCAL_STATIC_LIBRARIES := png include $(BUILD_SHARED_LIBRARY) 

he created both libpng.a and libpng2.so in the obj / local / armeabi folder. I assume that it simply will not create a static library if there is no dependency.

+9
source

I have beaten myself over the head with this problem in the last two hours, and this post helped solve this problem. Instead of adding a dummy dependency, just call ndk-build (which is just a thin shell over make) as "ndk-build png".

+1
source

I found that when I added the dummy shared library as described in the edit, the .a (which I found in obj /, assuming it was an internal part) did not contain any .o files I wanted.

In addition, .so recompiled all the files that would be created for the static library. So it made sense that .a was empty.

It helped me to add the line APP_MODULES to my Application.mk, as described in Unable to create a static library with Android NDK R8 . You probably want Application.mk anyway, as it contains other settings important for your static library, such as APP_STL, APP_PLATFORM, APP_ABI, etc.

0
source

All Articles