I wrote a System Service, but it fails on boot with the message:
java.lang.UnsatisfiedLinkError: dlopen failed: library "libgojni.so" not found
Basically in the code of the .aar library it tries to load a library using System.loadLibrary() but it fails, even though it is in the aar file. It even works when I try to do it in an android app, but it fails on android.
It may be also worth mentioning that I created the .aar library using gomobile to bind a go-project into an .aar library.
AFAIK path to load native libraries differs for system and user applications. I think the idea behind it is that system libraries are common for all Android framework and system apps, so the libs can be reused, and each dependent app doesn't need to carry its own copy, probably of different version.
The libraries for system apps are stored in system image.
You may want to look at this tutorial how to add system apps with native code to AOSP build: https://devarea.com/aosp-creating-a-system-application.
The question probably duplicates System.loadLibrary(...) couldn't find native library in my case