Automatically copy .so files from NDK library project?
Using Android Studio 1.2.1.1
with Gradle 1.2.3
. I have a library project NDK
A
that creates multiple files .so
in its own folder libs
. Although, I don't see a link to this folder anywhere in the file build.gradle
.
When I link to a library A
from my application MyApp
, I would expect the files to .so
be copied to MyApp/src/main/jniLibs
, but this is not the case. Do I need to manually copy these files every time I make changes to the library A
?
How can I automate this step?
source to share
I don't know if it can do this if you've copied the files the .so
way you want something to be thrown around.
But you could gradle to do it for you. In your gradle file, add a task that will copy the files .so
where you need them.
android {
...
sourceSets.main {
jni.srcDirs = []
jniLibs.srcDir 'src/main/libs'
}
//copying files
task copyNativeLib(type: Exec, description: 'Copy native file') {
commandLine 'cp <path_of_so_files> src/main/libs'
}
//add dependencies
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn copyNativeLib
}
}
Or maybe just
android {
...
sourceSets.main {
jni.srcDirs = []
jniLibs.srcDir '<path_to_your_so_files>'
}
}
source to share