AOSP Add Jar to Boot Class Path

243 Views Asked by At

I've set up the AOSP project, it builds fine (Android 12).

I've created a new module under frameworks/base/mylib which is just a Java library. It builds fine and gets added to /system/framework/mylib.jar. The jar contains a classes.dex which contains my classes.

I now want to add this jar to the boot class path so any app can access the classes inside of it.

I've tried adding PRODUCT_BOOT_JARS += com.example.mylib to my target product, build/target/product/sdk_phone_arm64.mk.

This causes the build to generate the following files in the framework folder:

arm64/boot-com.example.mylib.art
arm64/boot-com.example.mylib.oat
arm64/boot-com.example.mylib.vdex

boot-com.example.mylib.vdex

The jar now contains an empty classes.dex. When I try accessing a class in my app, I am getting the following errors:

Accessing hidden field Lcom/example/mylib/MyClass;->
MY_STRING:Ljava/lang/String; (blocked, linking, denied)

java.lang.NoSuchFieldError: No static field MY_STRING of type Ljava/lang/String; 
in class Lcom/example/mylib/MyClass; or its superclasses 
(declaration of 'com.example.mylib.MyClass' appears in 
/system/framework/com.example.mylib.jar)

This seems to be due to the non SDK interface restrictions of Android.

How do I get around this, if I need to add it to the SDK where can I do that?

I am aware that using the <uses-library> will add the library to the app's class path, but I'd like to avoid app's needing to add this to their Manifest files and just make it globally available.

0

There are 0 best solutions below