android studio添加so库的方法
根据Gradle的版本不同,导入有以下两种方法
方法一
将so文件拷贝到libs文件夹下,然后 在moudle的gradle 配置添加以下代码:
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)
}
完整的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')
- }
方法二: