2

I have one shared library and one header file. I did one sample project there I have generated .so and header files but now my problem is how to import existing .so and .h files in android studio.

I searched in google but there they are showing how to generate but I want how to import these files. Please suggest me some links or any other examples

Mounika
  • 3,348
  • 5
  • 16
  • 25
  • It depends on how you are building the shared library that you load from your java/kotlin code. If you're using cmake you would add the prebuilt library [as a `SHARED IMPORTED` library](https://cmake.org/cmake/help/latest/command/add_library.html#imported-libraries). If you're using ndkBuild you would use [the `PREBUILT_SHARED_LIBRARY` rule](https://developer.android.com/ndk/guides/prebuilts). And of course the .so file should also be built using the NDK. – Michael May 21 '19 at 10:14
  • See [this answer](https://stackoverflow.com/a/51418850/1524450) for a cmake example. – Michael May 21 '19 at 10:16
  • I am using android make I got that library from C developers and I just paste that library in myandroid src/libs directory – Mounika May 21 '19 at 10:59

1 Answers1

0

but now my problem is how to import existing .so and .h files in android studio

Usually, you should put your .so files inside jniLibs which is usually located at app/src/main/jniLibs, and put c/c++ source code inside app/src/main/cpp. See below directory structure.

.
├── CMakeLists.txt // Your cmake configuration files. 
├── app.iml
├── build
├── build.gradle
├── libs
├── proguard-rules.pro
└── src
    ├── androidTest
    │   └── java
    ├── main
    │   ├── AndroidManifest.xml
    │   ├── cpp // Directory to put your jni native source code. 
    │   │   └── native-lib.cpp
    │   ├── java
    │   ├── jniLibs // Directory to put your jni libs, i.e. the .so files. 
    │   └── res
    └── test
        └── java

See: https://stackoverflow.com/a/52048933/8034839

shizhen
  • 12,251
  • 9
  • 52
  • 88
  • I followed whatever you said , its done next i should do ndk-build or directly I should run the app. where I should keep header file – Mounika May 22 '19 at 05:47