1

I am trying to integrate the NDK project where Android Studio tells me I can have a workaround by:

Warning: Native C/C++ source code is found, but it seems that NDK option is not configured. Note that if you have an Android.mk, it is not used for compilation. The recommended workaround is to remove the default jni source code directory by adding:

android {
    sourceSets {
        main {
            jni.srcDirs = []
    }
} } 

to build.gradle, manually compile the code with ndk-build, and then place the resulting shared object in src/main/jniLibs

so after my ndk build, i find that there are two places where I can find .so files in armeabi-v7a,mips and x86 folders

/libs
/obj/local

so which folders from above two contain the actual .so files to be copied?

And do I have to configure anything else to make this work? I imported the project via Android Studio's import ADT method. Thank you!

3
  • You need to place it under libs folder. There can be total 4 folder will create if you follow ndk compilation. under each folder you can place your .so file Commented Nov 23, 2015 at 8:57
  • I have done ndk-build and it created the .so files in two folders, what I wanted to ask was which of those two folders(/libs or /obj/local) from to copy my '.so' files into my main Android Studio project.
    – Aavaas
    Commented Nov 23, 2015 at 9:02
  • As per my understanding obj/local/ has everything you have compiled including o.d and executable file but lib has only .so file. i.e obj/local has a fresh copy of .so file. These is the default environment used for compilation . NDK_LIBS_OUT=./Libs NDK_OUT=./obj Commented Nov 23, 2015 at 9:13

1 Answer 1

8

The suggested workaround assumes that you manually copy the contents of libs directory to src/main/jniLibs.

Alternative workaround is to add the following enchantment to the build.gradle file:

jniLibs.srcDirs = [ 'libs' ]

This line goes together with jni.srcDirs as stated in the message you quote.

4
  • Also note that the libraries are not contained directly within the jniLibs.srcDirs directories, but rather within sub-directories named as the architecture of the compiled library. For example, with a library named libdetection_based_tracker.so, and jniLibs.srcDirs = ['src/main/jniLibs'], your file paths may be: src\main\jniLibs\armeabi-v7a\libdetection_based_tracker.so and src\main\jniLibs\x86\libdetection_based_tracker.so. Commented Nov 23, 2015 at 20:49
  • So the .so files in the /obj/local are not the ones I need to point to? One of the comments in the question stated that they had more fresh copy of .so files and it also has the same set of .so files but with different size from those in /libs directory.
    – Aavaas
    Commented Nov 24, 2015 at 5:53
  • 2
    The files under /obj are important for debugging. When we use ndk-stack or addr2line, we point to the "fat" copies under /obj. The linker (started from ndk-build) produces its output in /obj. After that, ndk-build starts strip process that copies a stripped version of the libraries to /libs folder. You don't need all debug symbol information to run the program on your device, but you can enjoy this significant gain of APK size.
    – Alex Cohn
    Commented Nov 24, 2015 at 8:20
  • Thank you! that was the answer I was looking for.
    – Aavaas
    Commented Nov 24, 2015 at 18:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.