I have developed an application in Android Studio. I have integrated FFMPEG library in my application. This library contains a module and *.so
files. Now I need to integrate another library having a jar file and native *.so
files, Twilio for calling.
The issue I am facing is, whenever I try to build the application, *.so
file of Twilio
library automatically gets deleted. Then app gives error that, it can not find the native file.
Here is my build.gradle
import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'com.android.application'
repositories {
jcenter()
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "my.package.name"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
pickFirst 'META-INF/ASL2.0'
}
sourceSets.main {
jniLibs.srcDir 'src/main/libs' //set .so files location to libs
jni.srcDirs = [] //disable automatic ndk-build call
}
// call regular ndk-build(.cmd) script from app directory
task ndkBuild(type: Exec) {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'ndk-build.cmd', '-C', file('src/main').absolutePath
} else {
def ndkDir = android.ndkDirectory.getAbsolutePath()
commandLine ndkDir + '/ndk-build', '-C', file('src/main').absolutePath
}
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
}
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)
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile project(':ffmpegLibs')
compile files('libs/commons-codec-1.9.jar')
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:percent:23.1.1'
compile 'com.android.support:palette-v7:23.1.1'
compile 'com.fasterxml.jackson.core:jackson-core:2.7.0-rc1'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.7.0-rc1'
compile 'com.fasterxml.jackson.core:jackson-databind:2.7.0-rc1'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'com.google.code.gson:gson:2.5'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.daimajia.swipelayout:library:1.2.0'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.github.bumptech.glide:glide:3.6.1'
compile 'com.timehop.stickyheadersrecyclerview:library:0.4.3'
compile files('libs/twilioclient-android.jar')
}