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 Project. Notice that I see the AndroidLib is built successfully into an out/target/product/generic/data/app/AndroidLib.apk
Here are two android.mk files: AndroidLib(a normal Android App)
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_STATIC_JAVA_LIBRARIES := \
google-ps \
android-support-v4 \
LOCAL_SRC_FILES := \
$(call all-java-files-under, src) \
LOCAL_MODULE := AndroidLib
LOCAL_PACKAGE_NAME := AndroidLib
LOCAL_MODULE_TAGS := tests
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := google-ps:libs/google-play-services.jar
include $(BUILD_PACKAGE)
# additionally, build tests in sub-folders in a separate .apk
include $(call all-makefiles-under,$(LOCAL_PATH))
Browser App
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_STATIC_JAVA_LIBRARIES := \
android-common \
guava \
android-support-v13 \
android-support-v4 \
LOCAL_SRC_FILES := \
$(call all-java-files-under, src) \
src/com/android/browser/EventLogTags.logtags
LOCAL_PACKAGE_NAME := Browser
LOCAL_PROGUARD_FLAG_FILES := proguard.flags
LOCAL_EMMA_COVERAGE_FILTER := *,-com.android.common.*
# We need the sound recorder for the Media Capture API.
LOCAL_REQUIRED_MODULES := SoundRecorder, AndroidLib
include $(BUILD_PACKAGE)
# additionally, build tests in sub-folders in a separate .apk
include $(call all-makefiles-under,$(LOCAL_PATH))
Then I do:
make -j Browser
It gives me:
packages/apps/Browser/src/com/android/browser/BrowserActivity.java:36: package com.om.AndroidLib does not exist
import com.om.AndroidLib.MainActivity;
I know I'm digging this out of the grave a little bit, but there was never really an answer for how to actually include an Android Library Project (or other apk with resources) within an AOSP built application.
Here is what I have done with two projects. "main" is the main application I am building the apk for. "util" is a utility library with resources I am linking against. Both of the projects reside in external/seabold/{package}:
Android.mk
in seabold/Android.mk
in seabold/main/Be careful here to make sure you fiddle with the filenames correctly. For me, the files defined in
UTIL_JAVA_SRC
are in the form ofutil/src/com/seabold/util/*.java
. Since, the build script for the main app expects java files to be relative paths to the location ofAndroid.mk
, I'm adding a ../ to properly get to the util library's path.The key for resources is the LOCAL_AAPT_FLAGS. This tells the resource packager to make sure it generates an R.java for the package in the utility library. Without this, all of the utility's resources will get put into the main applications R.java, and the utility classes will fail to compile because its R.java will be missing.
Update
Essentially your problem is that the line:
Tells the Android build that your Browser depends on
AndroidLib
being built first, however it will not be linked toAndroidLib
in any way. To do that you need:Except that requires the
AndroidLib
to be a java library project, using the build type:And java libraries cannot include resources, unfortunately. And there is no way to link one app to another app in the Android build system.
We are working around that issue frequently, and it is frankly a bit of a mess to do so. But the only workaround we have found is to include all the resources directly in the apps that use those resources. Sorry.
How to make your
AndroidLib
a java library and link to itYour android lib should probably be built as a java library, and not as a app package. So instead of:
You should probably do:
Then you lib will be placed in
out/target/product/generic/system/framework/AndroidLib.jar
along with the other system libs.Also you do not need a
LOCAL_MODULE_NAME
for a lib, it is only applicable for an app. So strip that.And you should probably consider changing your
LOCAL_MODULE_TAGS
to:tests
indicates that you lib should only be built for testing,user
says to build you lib for all user builds (and implicitly also for engineering builds)In you app
Android.mk
you should then add a line:Such that your app will be built with
AndroidLib
in the classpath.In you apps
AndroidManifest.xml
you also need to put a uses library in theapplication
tag:And last you need to create a permissions xml file, with the following content:
And update your product configuration file such that the xml file will be deployed to target:
Replace
device/XXX/libs/
with the path to the permissions xml file.This is how we add and use an Android library in our Android builds. I hope it helps. :)
To add a pre-build jar file to the framework I did that:
Locate a folder with the jar and the Android.mk file under
prebuilds/misc/common/
Android.mk:
Run make on the Android.mk file:
make prebuilds/misc/common/Android.mk
Add the jar file to the frameworks/base/services/Android.mk: