I've created an Application that works perfectly in Android Studio. If I generate an AAR and APK and use these files they again work fine. I can install the APK on several devices and it works flawlessly. Now when I install the APK inside of an AOSP build I keep getting an java.lang.UnsatisfiedLinkError: which points to the very first line of code that's calling my native method. I used this link as a reference Add .apk files in aosp. When I run the emulator and click my application it crashes and produces that UnsatisfiedLinkError. The same thing happens if I generate an APK using my AAR file. Just to clarify again this only happens in AOSP it does not happen when using the AAR inside Android Studio doing other builds and the APK always works regardless of the device I install it on. Any advice as to why this is happening would be great!
AOSP was trying to find the .so that my APK uses from either the system/lib or vendor/lib folders and since it wasn't there it was causing the UnsatisfiedLinkError. So by adding the .so object file directory to those locations the APK started up fine inside the emulator after that. This could also be accomplished by modifying the Android.mk as well by adding these lines to the file.
include $(CLEAR_VARS)
LOCAL_MODULE := myfile
LOCAL_SRC_FILES := lib/myfile.so # or wherever your .so is located
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_SUFFIX := .so
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
include $(BUILD_PREBUILT)