I want to add some features into Browser app by start an activity from another android application. It gives me package does not exist
while I make the Main Pro
I've stumbled over a solution, on how a java library can access resources. The resources are build as a separate apk. The jar-lib can be used from any app that says so in its Manifest. The java-library-code has the R.java
of the resources-apk and uses createPackageContext()
to gain access to the actual resources. createPackageContext()
gets the app-context as parameter which each app must provide whenever it uses a java-lib-function that needs access to the resources.
I'm not that deep into the AOSP-build-system yet, so I'm hoping what I document here makes sense. It's not my solution either, I just improoved on something that some other developer created here at my job so I don't know where he got the approach from.
for the resource-only-apk we have:
Android.mk
include $(CLEAR_VARS)
LOCAL_PATH := $(call my-dir)
LOCAL_PACKAGE_NAME := shared-resources
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_APPS)
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
include $(BUILD_PACKAGE)
AndroidManifest.xml
For the jar-lib we have:
Android.mk
LOCAL_PATH:= $(call my-dir)
####################
# compile the jar #
include $(CLEAR_VARS)
LOCAL_MODULE := helper-lib
LOCAL_SRC_FILES := $(call all-java-files-under, src)
# add package-context-ressources
resource-intermediates := $(call intermediates-dir-for,APPS,shared-resources,,common)
shared_res := $(resource-intermediates)/src/my/company/common/resources/R.java
$(shared_res): $(resource-intermediates)/src/R.stamp
LOCAL_GENERATED_SOURCES := $(shared_res)
LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_JAVA_LIBRARIES)
LOCAL_ADDITIONAL_DEPENDENCIES := helper-lib.xml
include $(BUILD_JAVA_LIBRARY)
######################
# deliver permisions #
include $(CLEAR_VARS)
LOCAL_MODULE := helper-lib.xml
LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_PATH := $(TARGET_OUT)/etc/permissions
LOCAL_SRC_FILES := helper-lib.xml
include $(BUILD_PREBUILT)
AndroidManifest.xml
helper-lib.xml
Last but not least here is how we declare them in that over-all-makefile that says what all to include -> base_packages.mk
PRODUCT_PACKAGES += \
my.company.common \
shared-resources \
helper-lib