我在 Android Studio 中开发了一个应用程序。我在我的应用程序中集成了FFMPEG库。这个库包含一个模块和*.so
文件。现在我需要集成另一个具有 jar 文件和本机*.so
文件的库,用于调用的Twilio 。
我面临的问题是,每当我尝试构建应用程序时,库*.so
文件Twilio
都会自动被删除。然后应用程序给出错误,它找不到本机文件。
这是我的 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')
}