Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding own framework or library to AOSP

I'm trying to add my custom package to AOSP under frameworks/opt/mypackage.

I provided an Android.mk Makefile with the following content:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := mypackage
include $(BUILD_JAVA_LIBRARY)

In an other framework, I was out to use this package. For example in the telephony package.

But unfortunately the telephony framework is not able to use my package. I added my package to the LOCAL_JAVA_LIBRARIES variable in telephony's Android.mk but when the code is executed it gives me 01-11 16:51:01.835: E/AndroidRuntime(1789): java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

Did I miss something?

EDIT: setting include $(BUILD_STATIC_JAVA_LIBRARY) instead of include $(BUILD_JAVA_LIBRARY) in my Makefile and adding my package to the LOCAL_STATIC_JAVA_LIBRARIES of the frameworks works well. Nevertheless: the question is why does it not work with a non-static library.

like image 454
firefexx Avatar asked Jan 11 '15 16:01

firefexx


People also ask

Can you use java libraries in Android?

To use a Java library (JAR file) inside your Android project, you can simple copy the JAR file into the folder called libs in your application. *. jar files in this folder are included into the compile classpath via the default build.


1 Answers

It's because you need a permission file for local libraries.

Follow these steps:

  1. add your lib name "mypackage" to LOCAL_JAVA_LIBRARIES in your Android.mk of the package you want to use it.

  2. add the xml permission file like this:

com.mypackage.platform_library.xml

<?xml version="1.0" encoding="utf-8"?>
<permissions>
    <library name="com.mypackage.platform_library"
        file="/system/framework/com.mypackage.platform_library.jar"/>
</permissions>

This file must be placed in /system/etc/permissions on the device. Make also sure that your mypackage.jar is at the specified location on the device.

  1. In your AndroidManifest use <uses-library android:name="com.mypackage.platform_library" />

Here you can find an example.

like image 168
nilo Avatar answered Oct 17 '22 21:10

nilo