How to add external java library to custom Android framework?
-
01-03-2021 - |
Question
Can someone enlighten me on how to include an external java framework to android framework and compile it as a part of the custom android framework?
The idea is to make this external framework a part of my custom android framework and expose it as android service for other processes to use.
In essence what I did is -
- checked for android port of the java framework
- Copied the src dir (including all the external jar files) from the ported framework to
framework/base/core/java/android/
- Edited ActivityManager in the framework to call the copied library
- run make
Is this the right approach to edit Android framework? Since, I am including the java files and associated external jars of the external project inside the Android framework I suspect make fails while converting the jars to dex.
Can somebody point me towards any available resources dealing with Android Framework internals and on how to edit Android framework?
I checked the Tutorial: Android Internals - Building a Custom ROM, Pt. 2 of 2
on youtube from this year's Marko Gargenta presentation in Beijing, China. But he didn't make it (i.e. adding external framework or jars) clear either.
Solution
First: I'm not very experienced in the Android build process, so there might be a better solution, but this one should work (at least for Android 2.2).
I assume, that you use Eclipse for the source code modification and already executed a successful make -j4
...
- Create a new source folder:
external/<your-library>/src
- Copy all Java source files into this folder.
- Open the following make file:
<android>/frameworks/base/Android.mk
Search for
# Build ext.jar
and add your library as follows:[...] ext_dirs := \ ../../external/apache-http/src \ ../../external/<your-library>/src \ ../../external/gdata/src \ ../../external/protobuf/src \ ../../external/tagsoup/src [...]
- Now you should be able to access these libraries from the Android framework...
- Finally execute
make -j4 ext
to build only the external module, - Or
make -j4
to build all changed files (if a previous build exists in/out/
).
OTHER TIPS
README.txt from git repo in https://android.googlesource.com/platform/vendor/sample is a good example howto do it. It's good to clone it to see the examples.
Basically you need to create jar file and add it in filesystem, add xml configuration into /system/etc/permissions/
and declare <uses-library>
in apk's AndroidManifest.xml
.
In my case I had problem with adding <uses-library>
on a wrong place (not in <application>
).
So it's good to check the result with:
$ aapt dump badging Foo.apk | grep uses-library
uses-library:'android.foo'