Sakawa
Sakawa

Reputation: 38

Is it necessary to install the NDK to use a .so library?

I have a Android project that is a library (with the Is library checkbox marked) and other Android project that need these libraries. In the library there are three .jar packets and a folder called armeabi that contains 7 files with .so extension.

I have added the .jar libraries in the Java build path, libraries tab. But I can't manage to add the libraries to the project that need these libraries. I would like to know if there is any way I can add these libraries without installing the NDK.

In case I need to install the NDK, how should I proceed to add the .so libraries?

Thank you very much

Upvotes: 0

Views: 559

Answers (3)

ph0b
ph0b

Reputation: 14473

You need the NDK only to build .so files, it does nothing for packaging.

The .so files are usually stripped from .jars on Android, if you want to get these into your app your need to extract the files yourself and put them inside /libs/armeabi/, /libs/x86/, etc for eclipse, /jniLibs/armeabi/, /jniLibs/x86/, etc for Android Studio.

If you want to package your library and get its .so files integrated automatically when used, you can package it as a .aar instead of a .jar and use gradle: http://tools.android.com/tech-docs/new-build-system/aar-format.

Inside the .aar, your .so files for each architectures should go inside jni/armeabi/, jni/x86/, etc.

Upvotes: 0

Christian Hackl
Christian Hackl

Reputation: 27538

You don't need the NDK to use an *.so file, only to build one yourself.

If you need the *.so files for an app, just place them into the /libs/armeabi directory of your project. They will end up in the APK created by the Android build system.

One thing to watch out for are bugs / undocumented behaviour with the files' names. I once had an inexplicable problem with an *.so file whose name didn't start with "lib"; it was in the APK but would be ignored by the installer on the device. Only when I renamed it would it correctly be installed.

If you need the *.so files for a library, you basically don't do anything. The Android library system is not very sophisticated and even worse than what Java already offers in this area (in my opinion); there is no way to create an Android library which has everything included in one single file. So if the Java code in your *.jar archive needs the native functions in the *.so files, then you'll have to ship both the *.jar and the *.so files to your clients, as separate files. (Of course, the clients will then do the same thing which I explained above: place the *.so files in their app project's /libs/armeabi directory.)

Upvotes: 1

ThaMe90
ThaMe90

Reputation: 4296

Libraries that you build (with the NDK) generally come out in the libs/armeabi directory of your project (I don't know for sure if you can change this).

But seeing that you already have your .so file, I think it's safe if you manually put it in the libs/armeabi folder. Then it is automatically packed with your apk.

Upvotes: 0

Related Questions