1

I'm using a 3rd party library that is for an Android app, but I need to use it in a Cordova plugin (Phonegap) and after I build/run debug running on the device, the logger is throwing an error about not being able to find the .so file. They use this file with JNI. How can I ensure that the files are being added to apk? Their documentation states that the files need to go in the libs directory like:

/libs/armeabi-v7a/<filename>.so

I've added them to this directory and it seems that only jar files are being added to the plugin. How can I get this file to load onto the device when building the plugin? I'm using Android Studio 0.3.6 with Android API level 19. ( I can't change the versions because that's what we currently support in our app)

u84six
  • 4,604
  • 6
  • 38
  • 65
  • Do you do the plugin directly in android studio or do you use plugman and the cli? I've made plugins with native .so libraries, and all I did was tell plugman to copy to libs/armeabi-v7a folder. Maybe your issue is caused by the early alpha version of android studio you're using (you're also using it to build the apk?) Have you tried to build the apk using the command line? – QuickFix May 26 '15 at 17:00
  • I'm using latest Android Studio to build the plugin. I haven't used cli. Do you know how I can do it with Android Studio? The file structure in the plugin is generally src/android with all the jars and java files within. Does the .so need to be in a special directory or do I just add it to the same directory as the others? – u84six May 26 '15 at 22:30
  • I've noticed in regular Android project (in Android Studio), you place these files in jniLibs/armeabi-v7a/*.so, but when you look at the directory structure in the file system, you see /libs/armeabi-v7a/*.so. Why does it have to be so confusing? How do these .so files get into the .apk correctly given this information? In the regular Android app, I see no mention of .so files in the build.gradle files, but it just works. – u84six May 26 '15 at 22:40
  • And by the way are you aware that if you copy only armeabi-v7a, your apk will not be compatible with some devices like the ones using x86? – QuickFix May 27 '15 at 09:30
  • Yes, I'm aware of that. Thanks – u84six May 27 '15 at 14:25

2 Answers2

0

Android studio opens by default in "Android view" wich can be quite confusing.

To change the view you click on the down arrow at the right of the word android just above your project content. If you switch to the project view, you will see something that will be less confusing for you and where what's displayed matches the file system structure.

android studio view selection

Then you can copy your .so files in the libs/something folder (something being the name of the processor architecture).

If you switch back to the android view, you will see the file inside jniLibs.

QuickFix
  • 11,661
  • 2
  • 38
  • 50
  • This is still not working. The interesting thing is if I put the file in libs/armeabi-v7a/.so and switch to Android view, there's no jniLibs folder. Do I need to add something to plugin.xml or my build.gradle file? – u84six May 27 '15 at 14:33
  • I even tried putting in my plugin.xml to try and force and it still doesn't work. But here's a hint, when I put this file in a .jar file under the libs folder, it seems to get further but there's a different error. – u84six May 27 '15 at 14:41
  • 1
    Well if you're not using the cli, I don't think plugin.xml is of any use. If at a point you run plugman or the cli, then yes you need to add in plugin.xml lines to copy the files, lines with `` but target should be libs, not jndiLibs! – QuickFix May 27 '15 at 14:55
0

Please pay attention to that topic How to include *.so library in Android Studio?. You need put the files into "app\src\main\jniLibs". In plugin.xml that looks like

<source-file src="src/android/armeabi-v7a/some_file.so" target-dir="app\src\main\jniLibs\armeabi-v7a" />