I have libs jar and *.so. I created Eclipse project as in tutorial (for this libs). I am now doing project in Android Studio, but system can\'t find *.so files. I make how i
Create folder name "jniLibs" inside src/main folder and add All the folders containing your "*.so" file and sync and run your application. No other steps required.
Current Solution
Create the folder project/app/src/main/jniLibs, and then put your *.so files within their abi folders in that location. E.g.,
project/
├──libs/
| └── *.jar <-- if your library has jar files, they go here
├──src/
└── main/
├── AndroidManifest.xml
├── java/
└── jniLibs/
├── arm64-v8a/ <-- ARM 64bit
│ └── yourlib.so
├── armeabi-v7a/ <-- ARM 32bit
│ └── yourlib.so
└── x86/ <-- Intel 32bit
└── yourlib.so
Deprecated solution
Add both code snippets in your module gradle.build file as a dependency:
compile fileTree(dir: "$buildDir/native-libs", include: 'native-libs.jar')
How to create this custom jar:
task nativeLibsToJar(type: Jar, description: 'create a jar archive of the native libs') {
destinationDir file("$buildDir/native-libs")
baseName 'native-libs'
from fileTree(dir: 'libs', include: '**/*.so')
into 'lib/'
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn(nativeLibsToJar)
}
Three options:
One
Copy yours *.SO libraries on your libs
folder and put that on Build.gradle
:
dependencies
{
compile fileTree(include: ['*.jar'], dir: 'libs')
}
Two
Make a new folder on src/main/jniLibs
and write that on your Build.gradle
:
android {
//Another code
sourceSets {
main {
jniLibs.srcDirs = ['src/main/jnilibs']
}
//Another code
}//sourceSets tag close
}//Android tag close
There
Make a new folder on src/main/jniLibs
and write that on your Build.gradle
:
//Another code....
dependencies
{
compile fileTree(dir: "$buildDir/native-libs", include: 'native-libs.jar')
}//end dependencies
task nativeLibsToJar(type: Jar, description: 'create a jar archive of the native libs') {
destinationDir file("$buildDir/native-libs")
baseName 'native-libs'
from fileTree(dir: 'src/main/jnilibs', include: '**/*.so')
into 'lib/'
}
tasks.withType(JavaCompile)
{
compileTask -> compileTask.dependsOn(nativeLibsToJar)
}
You need to put your .so files inside a folder named lib (it's not libs and should be lib). It should be in the same structure it should be in the APK file.
Structure
Project:
|--lib:
|--|--armeabi:
|--|--|--.so files.
Then an armeabi folder where insert all .so
files. Then zip the folder into a .zip.Rename the .zip file into armeabi.jar and add the line
compile fileTree(dir: 'libs', include: '*.jar')
into dependencies {}
in the gradle's build file.
For more info and alternate method please see This answer and This answer