android studio怎么添加.so文件
2016-01-25 · 做真实的自己 用良心做教育
首先,在Module的根目录中建立libs目录,将jpush集成SDK中的so文件分别拷入,截图如下:
然后就是编写build.gradle文件。
关于so文件引入的配置很简单,代码配置如下:
task nativeLibsToJar(type: Zip, description: "create a jar archive of the native libs") {
destinationDir file("$projectDir/libs")
baseName "Native_Libs2"
extension "jar"
from fileTree(dir: "libs", include: "**/*.so")
into "lib"
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn(nativeLibsToJar)
}
自定义一个任务,在其中指定项目所依赖的so文件的目录,这里用了**/*.so来写,为了省事,指定需要拷入的目录 into "lib",那么动态运行库就被拷入到lib目录中。
完整的build.gradle文件如下:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
applicationId "com.wujay.footerballstar"
minSdkVersion 8
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
task nativeLibsToJar(type: Zip, description: "create a jar archive of the native libs") {
destinationDir file("$projectDir/libs")
baseName "Native_Libs2"
extension "jar"
from fileTree(dir: "libs", include: "**/*.so")
into "lib"
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn(nativeLibsToJar)
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.0'
compile files('libs/jpush-sdk-release1.7.2.jar')
compile files('libs/umeng_sdk.jar')
compile files('libs/libammsdk.jar')
}