Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top