4

I have a large source tree with multiple projects. One of the projects uses JNI.

When I try to "make clean" on my entire source tree it goes through and removes all the object files and libs. Then it steps into my applications directory to make clean.

When it gets to my JNI project it executes "ndk-build clean" which fails because the library I link against has been removed as part of the clean:

ndk-build clean
Android NDK: ERROR:/Users/spartygw/xyz/src/applications/foo/jni/Android.mk:bar: LOCAL_SRC_FILES points to a missing file    
Android NDK: Check that /Users/spartygw/xyz/src/applications/foo/jni/../../../../lib/libbar.a exists or that its path is correct   
/Users/spartygw/android-ndk-r6b/build/core/prebuilt-library.mk:43: *** Android NDK: Aborting    .  Stop.
make[3]: *** [clean_android] Error 2
make[2]: *** [clean] Error 2
make[1]: *** [clean] Error 2
make: *** [clean] Error 2

I've tried adding "ndk-build -k clean" and "ndk-build --ignore clean" but it bails out regardless.

How can I make ndk-build ignore the dependency on the libraries that are not yet built and just clean the local objects?

spartygw
  • 3,289
  • 2
  • 27
  • 51
  • 1
    You could let your make file's clean rule run "ndk-build clean" first. – tiguchi Dec 16 '13 at 16:33
  • Good idea but still run into the problem if I did "make clean" twice. Believe me, if it were JUST me I could live with it, but if I check this into git like this I will get complaints. – spartygw Dec 16 '13 at 17:25

2 Answers2

5

Your ndk-buid includes prebuit static library, which is not supposed to disappear even in clean build. There is some non-standard step that builds libbar.a and copies it to ../../../../lib/.

If you have strong reasons not to link to libbar.a directly from the place where it's built (…/obj/local/armeabi), then you have two options: either include $(PREBUILT_STATIC_LIBRARY) conditionally if its $(LOCAL_SRC_FILES) is present, or if clean is not the target.

Follows a simple outline of the former approach:

include $(CLEAR_VARS)
LOCAL_MODULE = bar
LOCAL_PATH := ../../../../lib
LOCAL_SRC_FILES := libbar.a
ifneq (,$(wildcard $(LOCAL_PATH)/$(LOCAL_SRC_FILES)))
  include $(PREBUILT_STATIC_LIBRARY)
endif
Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • I can't figure out the syntax for either a conditional include based on if LOCAL_SRC_FILES exists -or- how to do an action on !clean. Can you help by elaborating in your answer? – spartygw Dec 18 '13 at 23:38
  • Please see the update. But let me repeat once again, this is not a _clean_ solution (pun intended). To make your life easier in the long run, you should eliminate the step that copies `libbar.a` to `../../../../lib/`. – Alex Cohn Dec 19 '13 at 08:08
  • 1
    Thanks, Alex...now that you show me the use of $(wildcard ...) and ifneq(,...) it makes sense. Good for me to know that nugget for the future. – spartygw Dec 19 '13 at 15:55
1

As suggested in Alex's answer, you could also use ifneq ($(MAKECMDGOALS),clean) to check if the current target is not clean:

include $(CLEAR_VARS)
LOCAL_MODULE := foo
LOCAL_SRC_FILES := bar.so
LOCAL_EXPORT_C_INCLUDES := bar/location
# Avoid including on clean
ifneq ($(MAKECMDGOALS),clean)
    include $(PREBUILT_SHARED_LIBRARY)
endif