【亲测有效】在Android studio中导入.so文件
1、先在工程的libs文件下导入.so文件
2、在build.gradle中(本工程的gradle文件)中的android{}段内填入
/** 导入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)
}
在
dependencies {}内加入
provided fileTree(dir: 'libs', include: ['*.jar'])
3、将生成的Native_Libs.jar文件右键AddAsLibrary
-------------------------完成的gradle-------------------------------------------
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "com.ntu.dc.smarthospital"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
/** 导入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)
}
}
dependencies {
provided fileTree(dir: 'libs', include: ['*.jar'])
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.0'
compile files('libs/nineoldandroids-library-2.4.0.jar')
compile project(':refresh')
compile files('libs/Msc.jar')
compile files('libs/Sunflower.jar')
compile files('libs/Native_Libs2.jar')
}