2

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!

Community
  • 1
  • 1
AConsiglio
  • 256
  • 1
  • 3
  • 13
  • You can't install .aar archives on phones directly as they are used for library projects. I guess you only mean .apk achives. – anthonymonori Nov 18 '16 at 21:40
  • Sorry should have said I also tried using the aar inside of an Android.mk in which AOSP generates an APK. The following location contained the APK generated from AOSP /android/out/target/product/generic/data/app/MyApplicationName. When I take this APK and transfer it to my phone it crashes upon startup with the same unsatisfiedlinkerror. – AConsiglio Nov 18 '16 at 21:54
  • I have also added the apk to the /packages/apps/MyApplicationName – AConsiglio Nov 18 '16 at 22:22
  • _"I have also added the apk to the `/packages/apps/MyApplicationName`"_ That's enough. No need to duplicate it in `/android/out/target/product/generic/data/app/MyApplicationNa‌​me`, let the build system build it. – Onik Nov 18 '16 at 22:28
  • can you post Android.mk which is inside jni folder and main Android.mk file??? – sandeepmaaram Sep 18 '17 at 10:03
  • Did you find solution for this, I am also facing exactly same issue. Could you guide me on this? @AConsiglio – sandeepmaaram Sep 18 '17 at 10:04
  • @sandeepmaaram I found a solution which I detailed at the bottom of this post, hopefully this works for you! – AConsiglio Sep 19 '17 at 18:42

2 Answers2

0

which points to the very first line of code that's calling my native method.

Sounds like you are building your application with native libraries included and the .APK you created has only bundled some architecture types into it. If you have native libraries, make sure to include all architecture types (usually x86 and armv7 does the job, but always consult your compatibility checklist first) and make sure if you do ABI splitting that you are using the right APK.

Please consule the following guide to make sure you have the NDK integration set up correctly.

anthonymonori
  • 1,754
  • 14
  • 36
  • The OP is talking about including an `apk` to AOSP, which is not the same as deploying an app on a running OS. – Onik Nov 18 '16 at 21:45
0

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)

AConsiglio
  • 256
  • 1
  • 3
  • 13
  • Thank for solution, is It added in main Android,mk or under jni directory? – sandeepmaaram Sep 19 '17 at 20:34
  • 1
    @sandeepmaaram all of this would be added inside of your Android.mk file which will generate a .so based on your LOCAL_SRC_FILES. You can also manually add a generated .so file under those directories inside of your AOSP folders that you're building out of. – AConsiglio Sep 21 '17 at 16:49
  • Thanks a lot man, last query from above code "LOCAL_SRC_FILES := lib/myfile.so # or wherever your .so is located " meaning in .so file path aosp right eg. out/target/system/lib/myfile.so. What about Android.mk code under jni folder??? Thanks in advance. – sandeepmaaram Sep 22 '17 at 07:20
  • @sandeepmaaram the lib/myfile would just be the file path to the location of your .so object. The android.mk code assuming it's an application would reside in the folder of the application. When your AOSP starts the build the image again it will go inside the folder and read the Android.mk file – AConsiglio Sep 22 '17 at 16:51