diff options
author | Ying Wang <wangying@google.com> | 2011-12-14 14:29:28 -0800 |
---|---|---|
committer | Ying Wang <wangying@google.com> | 2011-12-14 16:04:59 -0800 |
commit | 20e2083ea0f8bae57ace17f098e7fe71a9625f84 (patch) | |
tree | 023984eb0eb2989410999b9bde69897cf8fdf5d8 /core/java_library.mk | |
parent | ec7a6448c67ca63a445bdf72a8fa705c690cd390 (diff) | |
download | build-20e2083ea0f8bae57ace17f098e7fe71a9625f84.zip build-20e2083ea0f8bae57ace17f098e7fe71a9625f84.tar.gz build-20e2083ea0f8bae57ace17f098e7fe71a9625f84.tar.bz2 |
Support to build static Java library with Android resource
Bug: 5714516
The rationale behind this change:
- the library is compiled into a jar file, but its R class is generated
making the constant not constant (static, not final static) (aapt
option --non-constant-id). Also the jar file does not contain the R
class.
- this allows the integer value to not be inlined in the compiled
class files. Note that this prevents using switch statements.
- the main project use this jar file as a normal static library: it will
add all the class files except the R.class.
- the main project uses the library res folder as a resource
folder with lower priority than the main project (basically the
main project is an overlay. This is accomplished using aapt's
--auto-add-overlay to handle resources only in the main project
(which the normal overlay mechanism doesn't allow).
- the main project creates R classes in the main project's
package but also in the library's package. This is done with
aapt's --extra-packages which accept as many packages as
needed, separated by a :.
- manifest merging is not done yet, so
activities/services/permissions/etc... have to be manually declared in
the main app.
To use a static library with Android resource in your app,
1. Add the library's resource dir to your app as an overlay:
LOCAL_RESOURCE_DIR := <app_resource_dir> <static_library_resource_dirs>
2. Set the proper aapt flags:
LOCAL_AAPT_FLAGS := <apps_own_flags> --auto-add-overlay \
--extra-packages <lib1_package_name>:<lib2_package_name>:...
Change-Id: Ifb4d2300b952ea4aaee74da1bb0c6c72ea0698a3
Diffstat (limited to 'core/java_library.mk')
-rw-r--r-- | core/java_library.mk | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/core/java_library.mk b/core/java_library.mk index fa40c0e..904ef5f 100644 --- a/core/java_library.mk +++ b/core/java_library.mk @@ -14,9 +14,11 @@ ifneq (,$(LOCAL_ASSET_DIR)) $(error $(LOCAL_PATH): Target java libraries may not set LOCAL_ASSET_DIR) endif +ifneq (true,$(LOCAL_IS_STATIC_JAVA_LIBRARY)) ifneq (,$(LOCAL_RESOURCE_DIR)) $(error $(LOCAL_PATH): Target java libraries may not set LOCAL_RESOURCE_DIR) endif +endif #xxx base_rules.mk looks at this all_res_assets := |