Calling inner Android.mk file to build prebuilt libraries not working

471 views
Skip to first unread message

Jona

unread,
Apr 18, 2012, 11:58:01 AM4/18/12
to andro...@googlegroups.com

I have a project organized as follow:

project/jni/Android.mk
project/jni/libA/Android.mk
project/jni/libB/Android.mk
project/lib/armeabi/libA.so
project/lib/armeabi/libB.so
 

My libA and libB are set on my main Android.mk as prebuilt libs cause I don't want them to be built every time I build my main Android.mk. Here is what I have:

///////////////// Main Android.mk /////////////////

LOCAL_PATH := $(call my-dir) ########################################### # Declare the prebuilt A library ########################################### include $(CLEAR_VARS) LOCAL_MODULE := A-prebuilt LOCAL_SRC_FILES := ../lib/$(TARGET_ARCH_ABI)/libA.so LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/libA include $(PREBUILT_SHARED_LIBRARY) ########################################### # Declare the prebuilt B library ########################################### include $(CLEAR_VARS) LOCAL_MODULE := B-prebuilt LOCAL_SRC_FILES := ../lib/$(TARGET_ARCH_ABI)/libB.so LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/libB/include include $(PREBUILT_SHARED_LIBRARY) ########################################### # Declare our main module ########################################### include $(CLEAR_VARS) LOCAL_MODULE := libjnimain LOCAL_SRC_FILES := \ main.c # for logging LOCAL_LDLIBS += -llog # include the prebuilt libraries LOCAL_SHARED_LIBRARIES := \ A-prebuilt \ B-prebuilt #This will include all Android.mk files in sub-directories #of the current build file's path. include $(call all-subdir-makefiles) include $(BUILD_SHARED_LIBRARY)

//////////////////////////////////////////////
 

The main problem I have is building the prebuild libraries. I can't seem to be able to build the libA or libB by calling their Android.mk because when I do the main Android.mk is called. Any help would be appreciated.

David Turner

unread,
Apr 18, 2012, 1:58:44 PM4/18/12
to andro...@googlegroups.com
On Wed, Apr 18, 2012 at 5:58 PM, Jona <medica...@gmail.com> wrote:

 

The main problem I have is building the prebuild libraries. I can't seem to be able to build the libA or libB by calling their Android.mk because when I do the main Android.mk is called. Any help would be appreciated.

That's normal, ndk-build will try to find the root of your project path, then use $PROJECT/jni/Android.mk by default.
You can specify an alternative Android.mk using APP_BUILD_SCRIPT when invoking ndk-build, see $NDK/docs/HOWTO.html

Note that the binaries will be placed under $PROJECT/libs/$ABI/ by default.
 
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/android-ndk/-/Ujr9l7dfq5EJ.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.

Jona

unread,
Apr 18, 2012, 2:15:00 PM4/18/12
to andro...@googlegroups.com
Ok, so essentially I need an Application.mk to specify the APP_BUILD_SCRIPT.  Once I do that than I can actually selectively call to build libA and libB?

I do understand that once Android.mk builds properly it will store it as you mentioned under $PROJECT/libs/$ABI/ by default.  Would the main Android.mk than remove those libraries? Cause I did see that...

David Turner

unread,
Apr 18, 2012, 2:23:00 PM4/18/12
to andro...@googlegroups.com
On Wed, Apr 18, 2012 at 8:15 PM, Jona <medica...@gmail.com> wrote:
Ok, so essentially I need an Application.mk to specify the APP_BUILD_SCRIPT.  Once I do that than I can actually selectively call to build libA and libB?

You can also force it by placing it on the ndk-build command-line, as in:

  ndk-build APP_BUILD_SCRIPT=<your-Android.mk> <other-options>

This will still use the default Application.mk through.
 
I do understand that once Android.mk builds properly it will store it as you mentioned under $PROJECT/libs/$ABI/ by default.  Would the main Android.mk than remove those libraries? Cause I did see that...

Yes, of course, you need to copy them to a different location.

The thing is, you're really dealing with three different NDK build projects, so it's better to treat them like that, e.g.:

$PROJECT/jni/Application.mk
$PROJECT/jni/Android.mk
$PROJECT/libs/

$PROJECT/lib1/jni/Application.mk   <-- dummy file, can be empty
$PROJECT/lib1/jni/Android.mk
$PROJECT/lib1/libs/$ABI/   <-- where the generated libraries will be placed

$PROJECT/lib2/jni/Application.mk   # dummy file
$PROJECT/lib2/jni/Android.mk
$PROJECT/lib2/libs/$ABI

You can build the prebuilts with "ndk-build -C $PROJECT/lib1" and "ndk-build -C $PROJECT/lib2"

Then in your main Android.mk, make the prebuilt modules take the libraries directly from the libN/libs/$ABI/ directories.

You don't need dummy Application.mk if you use a parallel directory install, as in:

$TOP/$PROJECT/
$TOP/lib1/
$TOP/lib2/

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/android-ndk/-/ngqfiwQfQzMJ.

Jona

unread,
Apr 18, 2012, 4:45:30 PM4/18/12
to andro...@googlegroups.com
Interesting. Thanks for your detailed explanation.  I was just trying to keep all sources inside one jni directory just for sake of having organized jni source... 

I tried ndk-build APP_BUILD_SCRIPT=<your-Android.mk> <other-options> and that worked but after your explanation I really need to figure out a much cleaner approach.
Reply all
Reply to author
Forward
0 new messages