Managing multiple Android.mk build files

6,771 views
Skip to first unread message

socratesJ

unread,
Sep 29, 2010, 10:31:03 PM9/29/10
to android-ndk
As a simple case, say I have a main Android.mk build file that
generates a shared library, let's say libA. This shared library
depends on another library, libB, that is created by a separate
Android.mk build file.

How do I build libA such that libB will also get built? What do I need
to do to tell the Android build system that libA depends on libB?

Thanks!

Ngo Van Luyen

unread,
Sep 30, 2010, 1:01:03 AM9/30/10
to andro...@googlegroups.com
Hi,

What I did is put both build script in one mk file, something like:
clear var
script lib 1
clear var
script lib 2
.....



2010/9/30 socratesJ <mcar...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
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.




--
Hello Android!
http://androidcore.com/

David Turner

unread,
Sep 30, 2010, 6:04:49 AM9/30/10
to andro...@googlegroups.com
You can have as many Android.mk files as you want, as long as they get included by the top-level one.

Each Android.mk can define any number of modules. Module dependencies are expressed with LOCAL_STATIC_LIBRARIES and LOCAL_SHARED_LIBRARIES.

In this case, you could have:

top-level Android.mk:
TOP_PATH := $(call my-dir)
include $(TOP_PATH)/libA/Android.mk
include $(TOP_PATH)/libB/Android.mk

libA/Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libA
LOCAL_SRC_FILES ...
LOCAL_SHARED_LIBRARIES := libB
include $(BUILD_SHARED_LIBRARIES)

libB/Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libB
LOCAL_SRC_FILES := ...
include $(BUILD_SHARED_LIBRARIES)


Tim Mensch

unread,
Sep 30, 2010, 10:41:52 AM9/30/10
to andro...@googlegroups.com
On 9/29/2010 11:01 PM, Ngo Van Luyen wrote:
> What I did is put both build script in one mk file, something like:
> clear var
> script lib 1
> clear var
> script lib 2
I wouldn't recommend that. It means that every time you modify the
makefile, ALL files get built. (All the files in a makefile implicitly
depend on the makefile).

If you instead follow David's suggestion, then modifying one makefile
means that only one project gets built.

Tim

Jerry Yin

unread,
Sep 30, 2010, 12:00:41 PM9/30/10
to andro...@googlegroups.com
In this case, is that the libB need to be build as static library? If not, is it necessary to load both libA and libB using System.loadLibrary()? Or the libB will be automatically loaded?
 
thanks,
Jerry

Ngo Van Luyen

unread,
Sep 30, 2010, 1:18:08 PM9/30/10
to andro...@googlegroups.com

In my case, i have to load both of them using system.loadlibrary, and remember to load B first, then A

On Sep 30, 2010 6:00 PM, "Jerry Yin" <jerry...@gmail.com> wrote:

In this case, is that the libB need to be build as static library? If not, is it necessary to load both libA and libB using System.loadLibrary()? Or the libB will be automatically loaded?
 
thanks,
Jerry

On Thu, Sep 30, 2010 at 6:04 AM, David Turner <di...@android.com> wrote:
>

> You can have as many An...

--

You received this message because you are subscribed to the Google Groups "android-ndk" group.

To po...

Kelly

unread,
Sep 30, 2010, 1:30:23 PM9/30/10
to android-ndk
If you have a BUILD_SHARED_LIBRARY in your top level with
LOCAL_STATIC_LIBRARIES := (Other libs) and all the other libraries are
BUILD_STATIC_LIBRARY, you will only generate one shared library and
only have to load that.

On Sep 30, 10:18 am, Ngo Van Luyen <nvluye...@gmail.com> wrote:
> In my case, i have to load both of them using system.loadlibrary, and
> remember to load B first, then A
>

David Turner

unread,
Oct 1, 2010, 6:01:28 AM10/1/10
to andro...@googlegroups.com
On Thu, Sep 30, 2010 at 6:00 PM, Jerry Yin <jerry...@gmail.com> wrote:
In this case, is that the libB need to be build as static library? If not, is it necessary to load both libA and libB using System.loadLibrary()? Or the libB will be automatically loaded?
 

You can create two shared libraries, but you will have to load them both, taking care of loading one library before any other that depends on it.

socratesJ

unread,
Oct 1, 2010, 2:32:14 PM10/1/10
to android-ndk
I tried David's suggestion, and it worked great. Thanks!

On Oct 1, 6:01 am, David Turner <di...@android.com> wrote:
> >> On Thu, Sep 30, 2010 at 4:31 AM, socratesJ <mcart...@gmail.com> wrote:
>
> >>> As a simple case, say I have a main Android.mk build file that
> >>> generates a shared library, let's say libA. This shared library
> >>> depends on another library, libB, that is created by a separate
> >>> Android.mk build file.
>
> >>> How do I build libA such that libB will also get built? What do I need
> >>> to do to tell the Android build system that libA depends on libB?
>
> >>> Thanks!
>
> >>> --
> >>> You received this message because you are subscribed to the Google Groups
> >>> "android-ndk" group.
> >>> To post to this group, send email to andro...@googlegroups.com.
> >>> To unsubscribe from this group, send email to
> >>> android-ndk...@googlegroups.com<android-ndk%2Bunsubscribe@googlegr oups.com>
> >>> .
> >>> For more options, visit this group at
> >>>http://groups.google.com/group/android-ndk?hl=en.
>
> >>   --
> >> You received this message because you are subscribed to the Google Groups
> >> "android-ndk" group.
> >> To post to this group, send email to andro...@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> android-ndk...@googlegroups.com<android-ndk%2Bunsubscribe@googlegr oups.com>
> >> .
> >> For more options, visit this group at
> >>http://groups.google.com/group/android-ndk?hl=en.
>
> >  --
> > You received this message because you are subscribed to the Google Groups
> > "android-ndk" group.
> > To post to this group, send email to andro...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > android-ndk...@googlegroups.com<android-ndk%2Bunsubscribe@googlegr oups.com>
> > .
Reply all
Reply to author
Forward
0 new messages