//---------------------------------------------------------
LOCAL_STATIC_LIBRARIES
These are the static libraries that you want to include in your module.
Mostly, we use shared libraries, but there are a couple of places,
like executables in sbin and host executables where we use static libraries instead.

LOCAL_WHOLE_STATIC_LIBRARIES
These are the static libraries that you want to include in your module without allowing the linker to remove dead code from them.
This is mostly useful if you want to add a static library to a shared library and have the static library's content exposed from the shared library.
//---------------------------------------------------------
從以上內容可知,
LOCAL_WHOLE_STATIC_LIBRARIES 會加載整個靜態庫,
LOCAL_STATIC_LIBRARIES 只是加載靜態庫中用到的函數。
看起來它們作用只是使生成的函式庫文件大小不一樣而已,但是卻不僅僅如此。
下面我們使用一個實例來分析一下。
現在我們需要靜態編譯原始碼中的 libchromium_net 函式庫。
由原始碼分析可知,libchromium_net 需要依賴 libicuuc 和 libicui18n,
而 libicui18n 又會依賴 libicuuc。
現在我們需要將 libicui18n 和 libicuuc 靜態編譯到libchromium_net中,這裡就存在一個嵌套編譯的問題。

如果,在 libchromium_net 的Android.mk文件中,我們這麼加載靜態庫:
LOCAL_STATIC_LIBRARIES := libicuuc libicui18n

因為在Android.mk文件中,
我們先引入了 libicuuc,系統就引入了 libicuuc 中所需要的函數,
然後再引入 libicui18n 中所需要的函數,
但是系統引入的時候不會遞歸引入
(就是引入 libicui18n 所需函數的同時再引入這些函數所需的函數),
所以 libicui18n 中所包含的 libicuuc 並沒有被引入。

當開始編譯的時候,如果 libicui18n 和 libchromium_net 所需要的 libicuuc 中的函數相同,就沒問題。
但是如果不同的話,就會提示 libicuuc 中部分函數找不到。

那麼如何解決這個問題呢?
有以下四個方案:
第一是將 libicui18n 和 libicuuc 中的函數全部加載;
第二是 libicuuc 部分加載,靜態編譯了 libicuuc 的 libicui18n 全部加載;
第三是 libicuuc 全部加載,libicui18n 部分加載;
第四是先加載 libicui18n,再加載 libicuuc,系統就會將 libchromium_net 和 libicui18n 所需 libicuuc 的函數一次性加載。

顯然第四種方案編譯出來的函式庫是最小的。
通過這個實例,大家應該會對 LOCAL_WHOLE_STATIC_LIBRARIES 和 LOCAL_STATIC_LIBRARIES 的區別有一個基本的理解。

arrow
arrow
    全站熱搜

    BB 發表在 痞客邦 留言(0) 人氣()